37 lines
1.0 KiB
Ruby
37 lines
1.0 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe FastJsonapi::ObjectSerializer do
|
|
include_context 'movie class'
|
|
|
|
let(:fields) do
|
|
{
|
|
movie: %i[name actors],
|
|
actor: %i[name agency]
|
|
}
|
|
end
|
|
|
|
it 'only returns specified fields' do
|
|
hash = MovieSerializer.new(movie, fields: fields).serializable_hash
|
|
|
|
expect(hash[:data][:attributes].keys.sort).to eq %i[name]
|
|
end
|
|
|
|
it 'only returns specified relationships' do
|
|
hash = MovieSerializer.new(movie, fields: fields).serializable_hash
|
|
|
|
expect(hash[:data][:relationships].keys.sort).to eq %i[actors]
|
|
end
|
|
|
|
it 'only returns specified fields for included relationships' do
|
|
hash = MovieSerializer.new(movie, fields: fields, include: %i[actors]).serializable_hash
|
|
|
|
expect(hash[:included].first[:attributes].keys.sort).to eq %i[name]
|
|
end
|
|
|
|
it 'only returns specified relationships for included relationships' do
|
|
hash = MovieSerializer.new(movie, fields: fields, include: %i[actors]).serializable_hash
|
|
|
|
expect(hash[:included].first[:relationships].keys.sort).to eq %i[agency]
|
|
end
|
|
end
|