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 before do
movie.release_year = 2008 movie.release_year = 2008
MovieSerializer.attribute :released_in_year, &:release_year MovieSerializer.attribute :released_in_year, &:release_year
MovieSerializer.attribute :name, &:local_name
end end
after do after do
@ -242,7 +243,7 @@ describe FastJsonapi::ObjectSerializer do
end end
it 'returns correct hash when serializable_hash is called' do 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 expect(serializable_hash[:data][:attributes][:released_in_year]).to eq movie.release_year
end end
end end

View File

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