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:
parent
9d08d2abed
commit
2de80d4889
9
spec/fixtures/movie.rb
vendored
9
spec/fixtures/movie.rb
vendored
@ -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: {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user