Skip to content

Commit de23501

Browse files
committed
Merge pull request #949 from edwardloveall/el-870-fix
Don't pass serializer option to associated serializers
2 parents 6251b90 + 14439aa commit de23501

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

lib/active_model/serializer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def each_association(&block)
220220
if serializer_class
221221
serializer = serializer_class.new(
222222
association_value,
223-
options.merge(serializer_from_options(association_options))
223+
options.except(:serializer).merge(serializer_from_options(association_options))
224224
)
225225
elsif !association_value.nil? && !association_value.instance_of?(Object)
226226
association_options[:association_options][:virtual_value] = association_value

test/action_controller/adapter_selector_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionController
44
module Serialization
55
class AdapterSelectorTest < ActionController::TestCase
6-
class MyController < ActionController::Base
6+
class AdapterSelectorTestController < ActionController::Base
77
def render_using_default_adapter
88
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
99
render json: @profile
@@ -20,7 +20,7 @@ def render_skipping_adapter
2020
end
2121
end
2222

23-
tests MyController
23+
tests AdapterSelectorTestController
2424

2525
def test_render_using_default_adapter
2626
get :render_using_default_adapter

test/action_controller/explicit_serializer_test.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionController
44
module Serialization
55
class ExplicitSerializerTest < ActionController::TestCase
6-
class MyController < ActionController::Base
6+
class ExplicitSerializerTestController < ActionController::Base
77
def render_using_explicit_serializer
88
@profile = Profile.new(name: 'Name 1',
99
description: 'Description 1',
@@ -55,9 +55,16 @@ def render_array_using_explicit_serializer_and_custom_serializers
5555

5656
render json: [@post], each_serializer: PostPreviewSerializer
5757
end
58+
59+
def render_using_explicit_each_serializer
60+
location = Location.new(id: 42, lat: '-23.550520', lng: '-46.633309')
61+
place = Place.new(id: 1337, name: 'Amazing Place', locations: [location])
62+
63+
render json: place, each_serializer: PlaceSerializer
64+
end
5865
end
5966

60-
tests MyController
67+
tests ExplicitSerializerTestController
6168

6269
def test_render_using_explicit_serializer
6370
get :render_using_explicit_serializer
@@ -105,6 +112,25 @@ def test_render_array_using_explicit_serializer_and_custom_serializers
105112

106113
assert_equal expected.to_json, @response.body
107114
end
115+
116+
def test_render_using_explicit_each_serializer
117+
get :render_using_explicit_each_serializer
118+
119+
expected = {
120+
id: 1337,
121+
name: "Amazing Place",
122+
locations: [
123+
{
124+
id: 42,
125+
lat: "-23.550520",
126+
lng: "-46.633309",
127+
place: "Nowhere" # is a virtual attribute on LocationSerializer
128+
}
129+
]
130+
}
131+
132+
assert_equal expected.to_json, response.body
133+
end
108134
end
109135
end
110136
end

test/action_controller/json_api_linked_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionController
44
module Serialization
55
class JsonApiLinkedTest < ActionController::TestCase
6-
class MyController < ActionController::Base
6+
class JsonApiLinkedTestController < ActionController::Base
77
def setup_post
88
ActionController::Base.cache_store.clear
99
@role1 = Role.new(id: 1, name: 'admin')
@@ -78,7 +78,7 @@ def render_collection_with_include
7878
end
7979
end
8080

81-
tests MyController
81+
tests JsonApiLinkedTestController
8282

8383
def test_render_resource_without_include
8484
get :render_resource_without_include

test/action_controller/rescue_from_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionController
44
module Serialization
55
class RescueFromTest < ActionController::TestCase
6-
class MyController < ActionController::Base
6+
class RescueFromTestController < ActionController::Base
77
rescue_from Exception, with: :handle_error
88

99
def render_using_raise_error_serializer
@@ -16,7 +16,7 @@ def handle_error(exception)
1616
end
1717
end
1818

19-
tests MyController
19+
tests RescueFromTestController
2020

2121
def test_rescue_from
2222
get :render_using_raise_error_serializer

test/action_controller/serialization_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module ActionController
44
module Serialization
55
class ImplicitSerializerTest < ActionController::TestCase
6-
class MyController < ActionController::Base
6+
class ImplicitSerializationTestController < ActionController::Base
77
def render_using_implicit_serializer
88
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
99
render json: @profile
@@ -152,7 +152,7 @@ def with_adapter(adapter)
152152
end
153153
end
154154

155-
tests MyController
155+
tests ImplicitSerializationTestController
156156

157157
# We just have Null for now, this will change
158158
def test_render_using_implicit_serializer

0 commit comments

Comments
 (0)