Add spec for proc methods with optional arguments

This commit is contained in:
Erol 2018-07-14 17:11:24 +08:00 committed by Shishir Kakaraddi
parent 449c1bf05f
commit e05193fb5e
2 changed files with 6 additions and 1 deletions

View File

@ -235,6 +235,7 @@ describe FastJsonapi::ObjectSerializer do
before do
movie.release_year = 2008
MovieSerializer.attribute :released_in_year, &:release_year
MovieSerializer.attribute :name, &:local_name
end
after do
@ -242,7 +243,7 @@ describe FastJsonapi::ObjectSerializer do
end
it 'returns correct hash when serializable_hash is called' do
expect(serializable_hash[:data][:attributes][:name]).to eq movie.name
expect(serializable_hash[:data][:attributes][:name]).to eq "english #{movie.name}"
expect(serializable_hash[:data][:attributes][:released_in_year]).to eq movie.release_year
end
end

View File

@ -54,6 +54,10 @@ RSpec.shared_context 'movie class' do
"#{id}"
end
def local_name(locale = :english)
"#{locale} #{name}"
end
def url
"http://movies.com/#{id}"
end