Added tests for polymorphic belongs_to

* chore(tests): add missing test for relationships belongs_to polymorphic type definitions

* chore(tests): add missing test for relationships belongs_to polymorphic type definitions

* linting
This commit is contained in:
Kevin Pheasey 2020-05-19 05:18:57 -04:00 committed by GitHub
parent 9d08d2abed
commit 2de80d4889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -3,6 +3,7 @@ class Movie
:id,
:name,
:year,
:actor_or_user,
:actors,
:actor_ids,
:polymorphics,
@ -55,6 +56,14 @@ class MovieSerializer
link :self, :url
belongs_to :owner, serializer: UserSerializer
belongs_to :actor_or_user,
id_method_name: :uid,
polymorphic: {
Actor => :actor,
User => :user
}
has_many(
:actors,
links: {

View File

@ -8,6 +8,7 @@ RSpec.describe FastJsonapi::ObjectSerializer do
poly_act = Actor.fake
poly_act.movies = [Movie.fake]
mov.polymorphics = [User.fake, poly_act]
mov.actor_or_user = Actor.fake
mov
end
let(:params) { {} }
@ -93,7 +94,7 @@ RSpec.describe FastJsonapi::ObjectSerializer do
end
end
context 'with polymorphic' do
context 'with has_many polymorphic' do
let(:params) do
{ include: ['actors_and_users.played_movies'] }
end
@ -121,6 +122,18 @@ RSpec.describe FastJsonapi::ObjectSerializer do
)
end
end
context 'with belongs_to polymorphic' do
let(:params) do
{ include: ['actor_or_user'] }
end
it do
expect(serialized['included']).to include(
have_type('actor').and(have_id(movie.actor_or_user.uid))
)
end
end
end
end
end