Skip to content

Commit e05193f

Browse files
Erolshishirmk
authored andcommitted
Add spec for proc methods with optional arguments
1 parent 449c1bf commit e05193f

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

spec/lib/object_serializer_class_methods_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,15 @@
235235
before do
236236
movie.release_year = 2008
237237
MovieSerializer.attribute :released_in_year, &:release_year
238+
MovieSerializer.attribute :name, &:local_name
238239
end
239240

240241
after do
241242
MovieSerializer.attributes_to_serialize.delete(:released_in_year)
242243
end
243244

244245
it 'returns correct hash when serializable_hash is called' do
245-
expect(serializable_hash[:data][:attributes][:name]).to eq movie.name
246+
expect(serializable_hash[:data][:attributes][:name]).to eq "english #{movie.name}"
246247
expect(serializable_hash[:data][:attributes][:released_in_year]).to eq movie.release_year
247248
end
248249
end

spec/shared/contexts/movie_context.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ def cache_key
5454
"#{id}"
5555
end
5656

57+
def local_name(locale = :english)
58+
"#{locale} #{name}"
59+
end
60+
5761
def url
5862
"http://movies.com/#{id}"
5963
end

0 commit comments

Comments
 (0)