mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
make sure to merge the original responder options into the given options to preserve location
This commit is contained in:
parent
6408b73e3c
commit
d3c6596990
@ -32,7 +32,7 @@ module ActiveModel
|
|||||||
serialization_scope = controller.send(:serialization_scope)
|
serialization_scope = controller.send(:serialization_scope)
|
||||||
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
options[:scope] = serialization_scope unless options.has_key?(:scope)
|
||||||
options[:url_options] = controller.send(:url_options)
|
options[:url_options] = controller.send(:url_options)
|
||||||
render(given_options.merge(:json => serializer.new(resource, options)))
|
render(given_options.merge(self.options).merge(:json => serializer.new(resource, options)))
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|||||||
@ -143,6 +143,10 @@ class ResponderTest < ActionController::TestCase
|
|||||||
respond_with JsonSerializable.new, :options => true
|
respond_with JsonSerializable.new, :options => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_json_with_serializer_but_without_location
|
||||||
|
respond_with JsonSerializable.new, :location => nil
|
||||||
|
end
|
||||||
|
|
||||||
def render_json_with_serializer_and_scope_option
|
def render_json_with_serializer_and_scope_option
|
||||||
@current_user = Struct.new(:as_json).new(:current_user => true)
|
@current_user = Struct.new(:as_json).new(:current_user => true)
|
||||||
scope = Struct.new(:as_json).new(:current_user => false)
|
scope = Struct.new(:as_json).new(:current_user => false)
|
||||||
@ -301,6 +305,11 @@ class ResponderTest < ActionController::TestCase
|
|||||||
assert_match '"options":true', @response.body
|
assert_match '"options":true', @response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_render_json_with_serializer_but_without_location
|
||||||
|
post :render_json_with_serializer_but_without_location
|
||||||
|
assert_equal nil, @response.location
|
||||||
|
end
|
||||||
|
|
||||||
def test_render_json_with_serializer_and_scope_option
|
def test_render_json_with_serializer_and_scope_option
|
||||||
get :render_json_with_serializer_and_scope_option
|
get :render_json_with_serializer_and_scope_option
|
||||||
assert_match '"scope":{"current_user":false}', @response.body
|
assert_match '"scope":{"current_user":false}', @response.body
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user