mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Merge pull request #77 from alindeman/disable_serialization_scope
Allows serialization_scope to be disabled with serialization_scope nil
This commit is contained in:
commit
d956507482
@ -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
|
||||
|
||||
34
test/no_serialization_scope_test.rb
Normal file
34
test/no_serialization_scope_test.rb
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user