diff --git a/lib/jbuilder.rb b/lib/jbuilder.rb index a378d66..6aa2af6 100644 --- a/lib/jbuilder.rb +++ b/lib/jbuilder.rb @@ -220,9 +220,7 @@ def child! # # [1,2,3] def array!(collection = [], *attributes, &block) - @attributes = if block && block.arity == 2 - _two_arguments_map_collection(collection, &block) - elsif block + @attributes = if block _map_collection(collection, &block) elsif attributes.any? _map_collection(collection) { |element| extract! element, *attributes } @@ -278,7 +276,7 @@ def attributes! # Encodes the current builder as JSON. def target! - ::MultiJson.dump @attributes + ::MultiJson.dump(@attributes) end private @@ -332,22 +330,6 @@ def _merge(hash_or_array) end end - def _two_arguments_map_collection(collection, &block) - message = "Passing jbuilder object to block is " \ - "deprecated and will be removed soon." - - if block.respond_to?(:parameters) - arguments = block.parameters.map(&:last) - actual = "|#{arguments.drop(1) * ', '}|" - deprecated = "|#{arguments * ', '}|" - message += "\nUse #{actual} instead of #{deprecated} as block arguments" - end - - ::ActiveSupport::Deprecation.warn message, ::Kernel.caller(5) - - _map_collection(collection){ |element| block[self, element] } - end - def _mapable_arguments?(value, *args) value.respond_to?(:map) end diff --git a/test/jbuilder_test.rb b/test/jbuilder_test.rb index 8542268..37e7c08 100644 --- a/test/jbuilder_test.rb +++ b/test/jbuilder_test.rb @@ -241,23 +241,6 @@ def initialize(name, age) assert_equal 'world', parsed['comments'].second['content'] end - test 'nesting multiple children from array with inline loop with old api' do - comments = [ Comment.new('hello', 1), Comment.new('world', 2) ] - - json = Jbuilder.encode do |json| - ::ActiveSupport::Deprecation.silence do - json.comments comments do |json, comment| - json.content comment.content - end - end - end - - parsed = MultiJson.load(json) - assert_equal ['content'], parsed['comments'].first.keys - assert_equal 'hello', parsed['comments'].first['content'] - assert_equal 'world', parsed['comments'].second['content'] - end - test 'nesting multiple children from array with inline loop on root' do comments = [ Comment.new('hello', 1), Comment.new('world', 2) ] @@ -272,22 +255,6 @@ def initialize(name, age) assert_equal 'world', parsed.second['content'] end - test 'nesting multiple children from array with inline loop on root with old api' do - comments = [ Comment.new('hello', 1), Comment.new('world', 2) ] - - json = Jbuilder.encode do |json| - ::ActiveSupport::Deprecation.silence do - json.call(comments) do |json, comment| - json.content comment.content - end - end - end - - parsed = MultiJson.load(json) - assert_equal 'hello', parsed.first['content'] - assert_equal 'world', parsed.second['content'] - end - test 'array nested inside nested hash' do json = Jbuilder.encode do |json| json.author do @@ -337,24 +304,6 @@ def initialize(name, age) assert_not_equal 'hello', MultiJson.load(json)[0]['not_in_json'] end - test 'directly set an array nested in another array with old api' do - data = [ { :department => 'QA', :not_in_json => 'hello', :names => ['John', 'David'] } ] - json = Jbuilder.encode do |json| - ::ActiveSupport::Deprecation.silence do - json.array! data do |json, object| - json.department object[:department] - json.names do - json.array! object[:names] - end - end - end - end - - parsed = MultiJson.load(json) - assert_equal 'David', parsed.first['names'].last - assert_not_equal 'hello', parsed.first['not_in_json'] - end - test 'nested jbuilder objects' do to_nest = Jbuilder.new to_nest.nested_value 'Nested Test'