Skip to content

Commit c49baec

Browse files
committed
Merge pull request #776 from nateberkopec/0-9-1
Revert #665
2 parents f1c3268 + 577db35 commit c49baec

File tree

4 files changed

+2
-22
lines changed

4 files changed

+2
-22
lines changed

lib/action_controller/serialization.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def build_json_serializer(resource, options = {})
8787
if serializer = options.fetch(:serializer, default_serializer(resource))
8888
options[:scope] = serialization_scope unless options.has_key?(:scope)
8989

90-
if resource.respond_to?(:each)
90+
if resource.respond_to?(:to_ary)
9191
options[:resource_name] = controller_name
9292
options[:namespace] = namespace_for_serializer if namespace_for_serializer
9393
end

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def format_keys(format)
5656
attr_reader :key_format
5757

5858
def serializer_for(resource, options = {})
59-
if resource.respond_to?(:each)
59+
if resource.respond_to?(:to_ary)
6060
if Object.constants.include?(:ArraySerializer)
6161
::ArraySerializer
6262
else

test/fixtures/poro.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ def description
100100
attributes :name, :description
101101
end
102102

103-
class DifferentProfileSerializer < ActiveModel::Serializer
104-
attributes :name
105-
end
106-
107103
class CategorySerializer < ActiveModel::Serializer
108104
attributes :name
109105

test/integration/action_controller/serialization_test.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,5 @@ def test_render_array_embeding_in_root
283283
assert_equal("{\"my\":[{\"name\":\"Name 1\",\"email\":\"[email protected]\",\"profile_id\":#{@controller.user.profile.object_id}}],\"profiles\":[{\"name\":\"N1\",\"description\":\"D1\"}]}", @response.body)
284284
end
285285
end
286-
287-
class ExplicitEachSerializerWithEnumarableObjectTest < ActionController::TestCase
288-
class MyController < ActionController::Base
289-
def render_array
290-
render json: [Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })].to_enum, each_serializer: DifferentProfileSerializer
291-
end
292-
end
293-
294-
tests MyController
295-
296-
def test_render_array
297-
get :render_array
298-
assert_equal 'application/json', @response.content_type
299-
assert_equal '{"my":[{"name":"Name 1"}]}', @response.body
300-
end
301-
end
302286
end
303287
end

0 commit comments

Comments
 (0)