Allows serialization_scope to be disabled with serialization_scope nil

This commit is contained in:
Andy Lindeman 2012-06-05 12:37:09 -04:00
parent 7afac9cd5c
commit 47850677e9
2 changed files with 35 additions and 1 deletions

View File

@ -33,7 +33,7 @@ module ActionController
end
def serialization_scope
send(_serialization_scope) if respond_to?(_serialization_scope)
send(_serialization_scope) if _serialization_scope && respond_to?(_serialization_scope)
end
def default_serializer_options

View File

@ -0,0 +1,34 @@
require "test_helper"
class NoSerializationScopeTest < ActionController::TestCase
class ScopeSerializer
def initialize(object, options)
@object, @options = object, options
end
def as_json(*)
{ :scope => @options[:scope].as_json }
end
end
class ScopeSerializable
def active_model_serializer
ScopeSerializer
end
end
class NoSerializationScopeController < ActionController::Base
serialization_scope nil
def index
render :json => ScopeSerializable.new
end
end
tests NoSerializationScopeController
def test_disabled_serialization_scope
get :index
assert_equal '{"scope":null}', @response.body
end
end