mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
Add Serializer#associations
This commit is contained in:
parent
b1f7a5ccda
commit
fa4ee9d645
@ -103,5 +103,9 @@ module ActiveModel
|
|||||||
hash[name] = send(name)
|
hash[name] = send(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def associations
|
||||||
|
self.class._associations.dup
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -60,6 +60,25 @@ module ActiveModel
|
|||||||
|
|
||||||
assert_equal({post: {type: :belongs_to, options: {}}}, @comment_serializer.class._associations)
|
assert_equal({post: {type: :belongs_to, options: {}}}, @comment_serializer.class._associations)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user