Add Serializer#associations

This commit is contained in:
Tema Bolshakov 2014-08-27 11:21:01 +04:00
parent b1f7a5ccda
commit fa4ee9d645
2 changed files with 23 additions and 0 deletions

View File

@ -103,5 +103,9 @@ module ActiveModel
hash[name] = send(name)
end
end
def associations
self.class._associations.dup
end
end
end

View File

@ -60,6 +60,25 @@ module ActiveModel
assert_equal({post: {type: :belongs_to, options: {}}}, @comment_serializer.class._associations)
end
def test_associations
@comment_serializer_class.class_eval do
belongs_to :post
has_many :comments
end
expected_associations = {
post: {
type: :belongs_to,
options: {}
},
comments: {
type: :has_many,
options: {}
},
}
assert_equal(expected_associations, @comment_serializer.associations)
end
end
end
end