From d3c6596990ea88a6372f26a969b68c151303fdb6 Mon Sep 17 00:00:00 2001 From: Tony Pitale Date: Fri, 15 Mar 2013 03:54:35 -0400 Subject: [PATCH] make sure to merge the original responder options into the given options to preserve location --- lib/active_model/serializer/responder.rb | 2 +- test/responder_test.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/active_model/serializer/responder.rb b/lib/active_model/serializer/responder.rb index caa7dfda..2b3c282e 100644 --- a/lib/active_model/serializer/responder.rb +++ b/lib/active_model/serializer/responder.rb @@ -32,7 +32,7 @@ module ActiveModel serialization_scope = controller.send(:serialization_scope) options[:scope] = serialization_scope unless options.has_key?(:scope) 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 super end diff --git a/test/responder_test.rb b/test/responder_test.rb index 0a28e9af..d00a93c3 100644 --- a/test/responder_test.rb +++ b/test/responder_test.rb @@ -143,6 +143,10 @@ class ResponderTest < ActionController::TestCase respond_with JsonSerializable.new, :options => true end + def render_json_with_serializer_but_without_location + respond_with JsonSerializable.new, :location => nil + end + def render_json_with_serializer_and_scope_option @current_user = Struct.new(:as_json).new(:current_user => true) scope = Struct.new(:as_json).new(:current_user => false) @@ -301,6 +305,11 @@ class ResponderTest < ActionController::TestCase assert_match '"options":true', @response.body 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 get :render_json_with_serializer_and_scope_option assert_match '"scope":{"current_user":false}', @response.body