mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 14:29:31 +00:00
Add Serializer#associations
This commit is contained in:
parent
b1f7a5ccda
commit
fa4ee9d645
@ -103,5 +103,9 @@ module ActiveModel
|
||||
hash[name] = send(name)
|
||||
end
|
||||
end
|
||||
|
||||
def associations
|
||||
self.class._associations.dup
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user