Skip to content

v2.14.0: Jbuilder.encode keyword arguments are broken. #602

@flavorjones

Description

@flavorjones

The changes to the Jbuilder initializer (from an options hash to keyword arguments) means that the Jbuilder.encode method no longer works when options are passed to it.

For example:

  test "encode forwards options to new" do
    Jbuilder.encode(key_formatter: 1, ignore_nil: 2) do |json|
      assert_equal 1, json.instance_eval{ @key_formatter }
      assert_equal 2, json.instance_eval{ @ignore_nil }
    end
  end

Fails with:

Error:
JbuilderTest#test_encode_forwards_options_to_new:
ArgumentError: wrong number of arguments (given 1, expected 0)
    lib/jbuilder.rb:16:in 'initialize'
    lib/jbuilder.rb:32:in 'Class#new'
    lib/jbuilder.rb:32:in 'Jbuilder.encode'
    test/jbuilder_test.rb:941:in 'block in <class:JbuilderTest>'

where it previously worked fine in 2.13.0 and earlier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions