Skip to content

Commit

Permalink
Add alias_method ActiveModel::Serializer.root= to be consistency with…
Browse files Browse the repository at this point in the history
… ActiveModel::ArraySerializer
  • Loading branch information
samnang committed Nov 19, 2012
1 parent 6ca430c commit 96ce310
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/active_model/serializer.rb
Expand Up @@ -204,6 +204,7 @@ def embed(type, options={})
def root(name)
self._root = name
end
alias_method :root=, :root

def inherited(klass) #:nodoc:
return if klass.anonymous?
Expand Down
5 changes: 5 additions & 0 deletions test/serializer_test.rb
Expand Up @@ -382,7 +382,12 @@ def test_false_root
root false
end

another_serializer = Class.new(BlogSerializer) do
self.root = false
end

assert_equal({ :author => nil }, serializer.new(blog, :scope => user).as_json)
assert_equal({ :author => nil }, another_serializer.new(blog, :scope => user).as_json)

# test inherited false root
serializer = Class.new(serializer)
Expand Down

0 comments on commit 96ce310

Please sign in to comment.