Merge pull request #106 from raycohen/scope_option_precedence

Scope option precedence
This commit is contained in:
José Valim 2012-07-29 03:06:47 -07:00
commit dd5cdb6ddb
2 changed files with 12 additions and 1 deletions

View File

@ -52,7 +52,7 @@ module ActionController
end
if serializer
options[:scope] = serialization_scope
options[:scope] = serialization_scope unless options.has_key?(:scope)
options[:url_options] = url_options
json = serializer.new(json, options.merge(default_serializer_options || {}))
end

View File

@ -131,6 +131,12 @@ class RenderJsonTest < ActionController::TestCase
render :json => JsonSerializable.new, :options => true
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)
render :json => JsonSerializable.new, :scope => scope
end
def render_json_with_serializer_api_but_without_serializer
@current_user = Struct.new(:as_json).new(:current_user => true)
render :json => JsonSerializable.new(true)
@ -259,6 +265,11 @@ class RenderJsonTest < ActionController::TestCase
assert_match '"options":true', @response.body
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
end
def test_render_json_with_serializer_api_but_without_serializer
get :render_json_with_serializer_api_but_without_serializer
assert_match '{"serializable_object":true}', @response.body