Implement Serializer's scope

This commit is contained in:
Santiago Pastorino 2013-07-02 00:13:26 -07:00
parent c3f857d1b6
commit b6f9c5ee43
2 changed files with 37 additions and 1 deletions

View File

@ -31,8 +31,9 @@ module ActiveModel
@object = object
@root = options[:root] || self.class._root
@root = self.class.root_name if @root == true
@scope = options[:scope]
end
attr_accessor :object, :root
attr_accessor :object, :root, :scope
alias read_attribute_for_serialization send

View File

@ -0,0 +1,35 @@
require 'newbase/test_helper'
require 'newbase/active_model/serializer'
module SerializerTest
module Scope
class Model
def initialize(hash={})
@attributes = hash
end
def read_attribute_for_serialization(name)
@attributes[name]
end
end
class ModelSerializer < ActiveModel::Serializer
end
class Test < ActiveModel::TestCase
def setup
@serializer = ModelSerializer.new(nil, scope: current_user)
end
def test_scope
assert_equal('user', @serializer.scope)
end
private
def current_user
'user'
end
end
end
end