|
4 | 4 | include_context 'movie class'
|
5 | 5 | include_context 'group class'
|
6 | 6 |
|
| 7 | + let(:movies) { build_movies(2) } |
| 8 | + |
7 | 9 | context 'when testing instance methods of object serializer' do
|
8 | 10 | it 'returns correct hash when serializable_hash is called' do
|
9 | 11 | options = {}
|
10 | 12 | options[:meta] = { total: 2 }
|
11 | 13 | options[:links] = { self: 'self' }
|
12 | 14 | options[:include] = [:actors]
|
13 |
| - movies = build_movies(2) |
14 | 15 | serializable_hash = MovieSerializer.new(movies, options).serializable_hash
|
15 | 16 |
|
16 | 17 | expect(serializable_hash[:data].length).to eq 2
|
|
59 | 60 | it 'returns correct number of records when serialized_json is called for an array' do
|
60 | 61 | options = {}
|
61 | 62 | options[:meta] = { total: 2 }
|
62 |
| - movies = build_movies(2) |
63 | 63 | json = MovieSerializer.new(movies, options).serialized_json
|
64 | 64 | serializable_hash = JSON.parse(json)
|
65 | 65 | expect(serializable_hash['data'].length).to eq 2
|
|
126 | 126 | end
|
127 | 127 |
|
128 | 128 | it 'returns multiple records' do
|
129 |
| - movies = build_movies(2) |
130 | 129 | json_hash = MovieSerializer.new(movies).as_json
|
131 | 130 | expect(json_hash['data'].length).to eq 2
|
132 | 131 | end
|
|
142 | 141 | options = {}
|
143 | 142 | options[:meta] = { total: 2 }
|
144 | 143 | options[:include] = [:blah_blah]
|
145 |
| - movies = build_movies(2) |
146 | 144 | expect { MovieSerializer.new(movies, options).serializable_hash }.to raise_error(ArgumentError)
|
147 | 145 | end
|
148 | 146 |
|
|
169 | 167 | options = {}
|
170 | 168 | options[:meta] = { total: 2 }
|
171 | 169 | options[:include] = ['']
|
172 |
| - movies = build_movies(2) |
173 | 170 | expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta]
|
174 | 171 | options[:include] = [nil]
|
175 | 172 | expect(MovieSerializer.new(movies, options).serializable_hash.keys).to eq [:data, :meta]
|
|
0 commit comments