Skip to content

Commit 83e7fb6

Browse files
sdsd08013shishirmk
authored andcommitted
update document/use let statement
1 parent 4077a23 commit 83e7fb6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ movie.actor_ids = [1, 2, 3]
104104
movie.owner_id = 3
105105
movie.movie_type_id = 1
106106
movie
107+
108+
movies =
109+
2.times.map do |i|
110+
m = Movie.new
111+
m.id = i + 1
112+
m.name = "test movie #{i}"
113+
m.actor_ids = [1, 2, 3]
114+
m.owner_id = 3
115+
m.movie_type_id = 1
116+
m
117+
end
107118
```
108119

109120
### Object Serialization
@@ -315,7 +326,7 @@ options[:links] = {
315326
prev: '...'
316327
}
317328
hash = MovieSerializer.new(movies, options).serializable_hash
318-
json_string = MovieSerializer.new([movie, movie], options).serialized_json
329+
json_string = MovieSerializer.new(movies, options).serialized_json
319330
```
320331

321332
#### Control Over Collection Serialization

spec/lib/object_serializer_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
include_context 'movie class'
55
include_context 'group class'
66

7+
let(:movies) { build_movies(2) }
8+
79
context 'when testing instance methods of object serializer' do
810
it 'returns correct hash when serializable_hash is called' do
911
options = {}
1012
options[:meta] = { total: 2 }
1113
options[:links] = { self: 'self' }
1214
options[:include] = [:actors]
13-
movies = build_movies(2)
1415
serializable_hash = MovieSerializer.new(movies, options).serializable_hash
1516

1617
expect(serializable_hash[:data].length).to eq 2
@@ -59,7 +60,6 @@
5960
it 'returns correct number of records when serialized_json is called for an array' do
6061
options = {}
6162
options[:meta] = { total: 2 }
62-
movies = build_movies(2)
6363
json = MovieSerializer.new(movies, options).serialized_json
6464
serializable_hash = JSON.parse(json)
6565
expect(serializable_hash['data'].length).to eq 2
@@ -126,7 +126,6 @@
126126
end
127127

128128
it 'returns multiple records' do
129-
movies = build_movies(2)
130129
json_hash = MovieSerializer.new(movies).as_json
131130
expect(json_hash['data'].length).to eq 2
132131
end
@@ -142,7 +141,6 @@
142141
options = {}
143142
options[:meta] = { total: 2 }
144143
options[:include] = [:blah_blah]
145-
movies = build_movies(2)
146144
expect { MovieSerializer.new(movies, options).serializable_hash }.to raise_error(ArgumentError)
147145
end
148146

@@ -169,7 +167,6 @@
169167
options = {}
170168
options[:meta] = { total: 2 }
171169
options[:include] = ['']
172-
movies = build_movies(2)
173170
expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta]
174171
options[:include] = [nil]
175172
expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta]

0 commit comments

Comments
 (0)