mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Reference scope by same name as serialization scope
By default, the serialization scope uses current_user, and you can now reference the scope as "current_user" in the serializer. If you override the scope using "serialization_scope" in your controller, it will use that method name instead.
This commit is contained in:
@@ -1338,5 +1338,18 @@ class SerializerTest < ActiveModel::TestCase
|
||||
|
||||
end
|
||||
|
||||
def test_scope_name_method
|
||||
serializer = Class.new(ActiveModel::Serializer) do
|
||||
def has_permission?
|
||||
current_user.super_user?
|
||||
end
|
||||
end
|
||||
|
||||
user = User.new
|
||||
user.superuser = true
|
||||
post = Post.new(:title => 'Foo')
|
||||
|
||||
a_serializer = serializer.new(post, :scope => user, :scope_name => :current_user)
|
||||
assert a_serializer.has_permission?
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user