|
10 | 10 | options[:meta] = { total: 2 }
|
11 | 11 | options[:links] = { self: 'self' }
|
12 | 12 | options[:include] = [:actors]
|
13 |
| - serializable_hash = MovieSerializer.new([movie, movie], options).serializable_hash |
| 13 | + movies = build_movies(2) |
| 14 | + serializable_hash = MovieSerializer.new(movies, options).serializable_hash |
14 | 15 |
|
15 | 16 | expect(serializable_hash[:data].length).to eq 2
|
16 | 17 | expect(serializable_hash[:data][0][:relationships].length).to eq 4
|
|
58 | 59 | it 'returns correct number of records when serialized_json is called for an array' do
|
59 | 60 | options = {}
|
60 | 61 | options[:meta] = { total: 2 }
|
61 |
| - json = MovieSerializer.new([movie, movie], options).serialized_json |
| 62 | + movies = build_movies(2) |
| 63 | + json = MovieSerializer.new(movies, options).serialized_json |
62 | 64 | serializable_hash = JSON.parse(json)
|
63 | 65 | expect(serializable_hash['data'].length).to eq 2
|
64 | 66 | expect(serializable_hash['meta']).to be_instance_of(Hash)
|
|
124 | 126 | end
|
125 | 127 |
|
126 | 128 | it 'returns multiple records' do
|
127 |
| - json_hash = MovieSerializer.new([movie, movie]).as_json |
| 129 | + movies = build_movies(2) |
| 130 | + json_hash = MovieSerializer.new(movies).as_json |
128 | 131 | expect(json_hash['data'].length).to eq 2
|
129 | 132 | end
|
130 | 133 |
|
|
139 | 142 | options = {}
|
140 | 143 | options[:meta] = { total: 2 }
|
141 | 144 | options[:include] = [:blah_blah]
|
142 |
| - expect { MovieSerializer.new([movie, movie], options).serializable_hash }.to raise_error(ArgumentError) |
| 145 | + movies = build_movies(2) |
| 146 | + expect { MovieSerializer.new(movies, options).serializable_hash }.to raise_error(ArgumentError) |
143 | 147 | end
|
144 | 148 |
|
145 | 149 | it 'returns errors when serializing with non-existent and existent includes keys' do
|
|
165 | 169 | options = {}
|
166 | 170 | options[:meta] = { total: 2 }
|
167 | 171 | options[:include] = ['']
|
168 |
| - expect(MovieSerializer.new([movie, movie], options).serializable_hash.keys).to eq [:data, :meta] |
| 172 | + movies = build_movies(2) |
| 173 | + expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta] |
169 | 174 | options[:include] = [nil]
|
170 |
| - expect(MovieSerializer.new([movie, movie], options).serializable_hash.keys).to eq [:data, :meta] |
| 175 | + expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta] |
171 | 176 | end
|
172 | 177 | end
|
173 | 178 |
|
|
0 commit comments