Test passes

This commit is contained in:
twinturbo 2012-04-23 21:22:07 -05:00
parent 3ca1621011
commit 9f20fe8b36
2 changed files with 13 additions and 7 deletions

View File

@ -225,7 +225,11 @@ module ActiveModel
end end
def plural_key def plural_key
key.to_s.pluralize.to_sym if polymorphic?
associated_object.class.to_s.pluralize.demodulize.underscore.to_sym
else
key.to_s.pluralize.to_sym
end
end end
def serialize def serialize

View File

@ -1038,7 +1038,7 @@ class SerializerTest < ActiveModel::TestCase
def test_polymorphic_associations_are_included_at_root def test_polymorphic_associations_are_included_at_root
email_serializer = Class.new(ActiveModel::Serializer) do email_serializer = Class.new(ActiveModel::Serializer) do
attributes :subject, :body attributes :subject, :body, :id
end end
email_class = Class.new(Model) do email_class = Class.new(Model) do
@ -1052,6 +1052,7 @@ class SerializerTest < ActiveModel::TestCase
end end
attachment_serializer = Class.new(ActiveModel::Serializer) do attachment_serializer = Class.new(ActiveModel::Serializer) do
root :attachment
embed :ids, :include => true embed :ids, :include => true
attributes :name, :url attributes :name, :url
has_one :attachable, :polymorphic => true has_one :attachable, :polymorphic => true
@ -1064,11 +1065,12 @@ class SerializerTest < ActiveModel::TestCase
actual = attachment_serializer.new(attachment, {}).as_json actual = attachment_serializer.new(attachment, {}).as_json
assert_equal({ assert_equal({
:name => 'logo.png', :attachment => {
:url => 'http://example.com/logo.png', :name => 'logo.png',
:attachable => { :url => 'http://example.com/logo.png',
:email => 1 :attachable => {
}, :email => 1
}},
:emails => [{ :emails => [{
:id => 1, :id => 1,
:subject => "Hello", :subject => "Hello",