mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Merge pull request #949 from edwardloveall/el-870-fix
Don't pass serializer option to associated serializers
This commit is contained in:
commit
de23501995
@ -220,7 +220,7 @@ module ActiveModel
|
||||
if serializer_class
|
||||
serializer = serializer_class.new(
|
||||
association_value,
|
||||
options.merge(serializer_from_options(association_options))
|
||||
options.except(:serializer).merge(serializer_from_options(association_options))
|
||||
)
|
||||
elsif !association_value.nil? && !association_value.instance_of?(Object)
|
||||
association_options[:association_options][:virtual_value] = association_value
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class AdapterSelectorTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
class AdapterSelectorTestController < ActionController::Base
|
||||
def render_using_default_adapter
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile
|
||||
@ -20,7 +20,7 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
tests AdapterSelectorTestController
|
||||
|
||||
def test_render_using_default_adapter
|
||||
get :render_using_default_adapter
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class ExplicitSerializerTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
class ExplicitSerializerTestController < ActionController::Base
|
||||
def render_using_explicit_serializer
|
||||
@profile = Profile.new(name: 'Name 1',
|
||||
description: 'Description 1',
|
||||
@ -55,9 +55,16 @@ module ActionController
|
||||
|
||||
render json: [@post], each_serializer: PostPreviewSerializer
|
||||
end
|
||||
|
||||
def render_using_explicit_each_serializer
|
||||
location = Location.new(id: 42, lat: '-23.550520', lng: '-46.633309')
|
||||
place = Place.new(id: 1337, name: 'Amazing Place', locations: [location])
|
||||
|
||||
render json: place, each_serializer: PlaceSerializer
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
tests ExplicitSerializerTestController
|
||||
|
||||
def test_render_using_explicit_serializer
|
||||
get :render_using_explicit_serializer
|
||||
@ -105,6 +112,25 @@ module ActionController
|
||||
|
||||
assert_equal expected.to_json, @response.body
|
||||
end
|
||||
|
||||
def test_render_using_explicit_each_serializer
|
||||
get :render_using_explicit_each_serializer
|
||||
|
||||
expected = {
|
||||
id: 1337,
|
||||
name: "Amazing Place",
|
||||
locations: [
|
||||
{
|
||||
id: 42,
|
||||
lat: "-23.550520",
|
||||
lng: "-46.633309",
|
||||
place: "Nowhere" # is a virtual attribute on LocationSerializer
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
assert_equal expected.to_json, response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class JsonApiLinkedTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
class JsonApiLinkedTestController < ActionController::Base
|
||||
def setup_post
|
||||
ActionController::Base.cache_store.clear
|
||||
@role1 = Role.new(id: 1, name: 'admin')
|
||||
@ -78,7 +78,7 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
tests JsonApiLinkedTestController
|
||||
|
||||
def test_render_resource_without_include
|
||||
get :render_resource_without_include
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class RescueFromTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
class RescueFromTestController < ActionController::Base
|
||||
rescue_from Exception, with: :handle_error
|
||||
|
||||
def render_using_raise_error_serializer
|
||||
@ -16,7 +16,7 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
tests RescueFromTestController
|
||||
|
||||
def test_rescue_from
|
||||
get :render_using_raise_error_serializer
|
||||
|
||||
@ -3,7 +3,7 @@ require 'test_helper'
|
||||
module ActionController
|
||||
module Serialization
|
||||
class ImplicitSerializerTest < ActionController::TestCase
|
||||
class MyController < ActionController::Base
|
||||
class ImplicitSerializationTestController < ActionController::Base
|
||||
def render_using_implicit_serializer
|
||||
@profile = Profile.new({ name: 'Name 1', description: 'Description 1', comments: 'Comments 1' })
|
||||
render json: @profile
|
||||
@ -152,7 +152,7 @@ module ActionController
|
||||
end
|
||||
end
|
||||
|
||||
tests MyController
|
||||
tests ImplicitSerializationTestController
|
||||
|
||||
# We just have Null for now, this will change
|
||||
def test_render_using_implicit_serializer
|
||||
|
||||
Loading…
Reference in New Issue
Block a user