restpack_serializer 0.6.7 → 0.6.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/restpack_serializer/version.rb +1 -1
- data/restpack_serializer.gemspec +10 -9
- data/spec/factory/factory_spec.rb +21 -14
- data/spec/fixtures/db.rb +1 -1
- data/spec/restpack_serializer_spec.rb +4 -4
- data/spec/result_spec.rb +16 -15
- data/spec/serializable/filterable_spec.rb +1 -1
- data/spec/serializable/options_spec.rb +40 -35
- data/spec/serializable/paging_spec.rb +88 -81
- data/spec/serializable/resource_spec.rb +11 -10
- data/spec/serializable/serializer_spec.rb +44 -41
- data/spec/serializable/side_loading/belongs_to_spec.rb +16 -13
- data/spec/serializable/side_loading/has_and_belongs_many_spec.rb +7 -7
- data/spec/serializable/side_loading/has_many_spec.rb +19 -20
- data/spec/serializable/side_loading/side_loading_spec.rb +21 -19
- data/spec/serializable/single_spec.rb +4 -4
- data/spec/serializable/sortable_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/factory.rb +20 -26
- metadata +35 -22
@@ -9,18 +9,18 @@ describe RestPack::Serializer::Resource do
|
|
9
9
|
let(:resource) { MyApp::SongSerializer.resource(params, scope, context) }
|
10
10
|
let(:params) { { id: @song.id } }
|
11
11
|
let(:scope) { nil }
|
12
|
-
let(:context) { {
|
12
|
+
let(:context) { {} }
|
13
13
|
|
14
14
|
it "returns a resource by id" do
|
15
|
-
resource[:songs].count.
|
16
|
-
resource[:songs][0][:id].
|
15
|
+
expect(resource[:songs].count).to eq(1)
|
16
|
+
expect(resource[:songs][0][:id]).to eq(@song.id.to_s)
|
17
17
|
end
|
18
18
|
|
19
19
|
context "with context" do
|
20
20
|
let(:context) { { reverse_title?: true } }
|
21
21
|
|
22
22
|
it "returns reversed titles" do
|
23
|
-
resource[:songs][0][:title].
|
23
|
+
expect(resource[:songs][0][:title]).to eq(@song.title.reverse)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -28,19 +28,20 @@ describe RestPack::Serializer::Resource do
|
|
28
28
|
let(:params) { { id: @song.id, include: 'albums' } }
|
29
29
|
|
30
30
|
it "includes side-loaded models" do
|
31
|
-
resource[:linked][:albums].count.
|
32
|
-
resource[:linked][:albums].first[:id].
|
31
|
+
expect(resource[:linked][:albums].count).to eq(1)
|
32
|
+
expect(resource[:linked][:albums].first[:id]).to eq(@song.album.id.to_s)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "includes the side-loads in the main meta data" do
|
36
|
-
resource[:meta][:songs][:include].
|
36
|
+
expect(resource[:meta][:songs][:include]).to eq(%w(albums))
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "missing resource" do
|
41
41
|
let(:params) { { id: "-99" } }
|
42
|
+
|
42
43
|
it "returns no resource" do
|
43
|
-
resource[:songs].length.
|
44
|
+
expect(resource[:songs].length).to eq(0)
|
44
45
|
end
|
45
46
|
|
46
47
|
#TODO: add specs for jsonapi error format when it has been standardised
|
@@ -49,11 +50,11 @@ describe RestPack::Serializer::Resource do
|
|
49
50
|
end
|
50
51
|
|
51
52
|
describe "song with no artist" do
|
52
|
-
let(:song) { FactoryGirl.create(:song, :
|
53
|
+
let(:song) { FactoryGirl.create(:song, artist: nil) }
|
53
54
|
let(:resource) { MyApp::SongSerializer.resource(id: song.id.to_s) }
|
54
55
|
|
55
56
|
it "should not have an artist link" do
|
56
|
-
resource[:songs][0][:links].keys.
|
57
|
+
expect(resource[:songs][0][:links].keys).not_to include(:artist)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -27,7 +27,7 @@ describe RestPack::Serializer do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it ".as_json serializes to an empty hash" do
|
30
|
-
EmptySerializer.as_json(person).
|
30
|
+
expect(EmptySerializer.as_json(person)).to eq({})
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -71,11 +71,11 @@ describe RestPack::Serializer do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it ".as_json serializes" do
|
74
|
-
serialized = DerivedSerializer.as_json({},
|
75
|
-
serialized.
|
74
|
+
serialized = DerivedSerializer.as_json({}, include_food?: false, name: 'Ben', age: 1)
|
75
|
+
expect(serialized).to eq({ #NOTE: I think this should include colour as DerivedSerializer defines it, but this would be a big breaking change
|
76
76
|
name: "Ben",
|
77
77
|
age: 1
|
78
|
-
}
|
78
|
+
})
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -116,34 +116,35 @@ describe RestPack::Serializer do
|
|
116
116
|
|
117
117
|
def custom_attributes
|
118
118
|
{
|
119
|
-
:
|
119
|
+
custom_key: "custom value for model id #{@model.id}"
|
120
120
|
}
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
describe ".serialize" do
|
125
125
|
it "serializes to an array" do
|
126
|
-
serializer.class.serialize(person).
|
126
|
+
expect(serializer.class.serialize(person)).to eq(
|
127
127
|
people: [{
|
128
128
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
129
129
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
130
130
|
}]
|
131
|
-
|
131
|
+
)
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
135
|
describe ".as_json" do
|
136
136
|
it "serializes specified attributes" do
|
137
|
-
serializer.as_json(person).
|
137
|
+
expect(serializer.as_json(person)).to eq(
|
138
138
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
139
139
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
140
|
-
|
140
|
+
)
|
141
141
|
end
|
142
142
|
|
143
143
|
context "an array" do
|
144
144
|
let(:people) { [person, person] }
|
145
|
+
|
145
146
|
it "results in a serialized array" do
|
146
|
-
serializer.as_json(people).
|
147
|
+
expect(serializer.as_json(people)).to eq([
|
147
148
|
{
|
148
149
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
149
150
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
@@ -152,11 +153,12 @@ describe RestPack::Serializer do
|
|
152
153
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
153
154
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
154
155
|
}
|
155
|
-
]
|
156
|
+
])
|
156
157
|
end
|
158
|
+
|
157
159
|
context "#array_as_json" do
|
158
160
|
it "results in a serialized array" do
|
159
|
-
serializer.class.array_as_json(people).
|
161
|
+
expect(serializer.class.array_as_json(people)).to eq([
|
160
162
|
{
|
161
163
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
162
164
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
@@ -165,75 +167,75 @@ describe RestPack::Serializer do
|
|
165
167
|
id: '123', name: 'Gavin', description: 'This is person #123',
|
166
168
|
href: '/people/123', custom_key: 'custom value for model id 123'
|
167
169
|
}
|
168
|
-
]
|
170
|
+
])
|
169
171
|
end
|
170
172
|
end
|
171
173
|
end
|
172
174
|
|
173
175
|
context "nil" do
|
174
176
|
it "results in nil" do
|
175
|
-
serializer.as_json(nil).
|
177
|
+
expect(serializer.as_json(nil)).to eq(nil)
|
176
178
|
end
|
177
179
|
end
|
178
180
|
|
179
181
|
context "with options" do
|
180
182
|
it "excludes specified attributes" do
|
181
|
-
serializer.as_json(person,
|
183
|
+
expect(serializer.as_json(person, include_description?: false)).to eq(
|
182
184
|
id: '123', name: 'Gavin', href: '/people/123',
|
183
185
|
custom_key: 'custom value for model id 123'
|
184
|
-
|
186
|
+
)
|
185
187
|
end
|
186
188
|
|
187
189
|
it "excludes custom attributes if specified" do
|
188
|
-
hash = serializer.as_json(person,
|
189
|
-
hash[:admin_info].
|
190
|
+
hash = serializer.as_json(person, is_admin?: false)
|
191
|
+
expect(hash[:admin_info]).to eq(nil)
|
190
192
|
end
|
191
193
|
|
192
194
|
it "includes custom attributes if specified" do
|
193
|
-
hash = serializer.as_json(person,
|
194
|
-
hash[:admin_info].
|
195
|
+
hash = serializer.as_json(person, is_admin?: true)
|
196
|
+
expect(hash[:admin_info]).to eq(
|
195
197
|
key: "super_secret_sauce",
|
196
198
|
array: [
|
197
199
|
name: 'Alex'
|
198
200
|
]
|
199
|
-
|
201
|
+
)
|
200
202
|
end
|
201
203
|
|
202
204
|
it "excludes a blacklist of attributes if specified as an array" do
|
203
|
-
serializer.as_json(person,
|
205
|
+
expect(serializer.as_json(person, attribute_blacklist: [:name, :description])).to eq(
|
204
206
|
id: '123',
|
205
207
|
href: '/people/123',
|
206
208
|
custom_key: 'custom value for model id 123'
|
207
|
-
|
209
|
+
)
|
208
210
|
end
|
209
211
|
|
210
212
|
it "excludes a blacklist of attributes if specified as a string" do
|
211
|
-
serializer.as_json(person,
|
213
|
+
expect(serializer.as_json(person, attribute_blacklist: 'name, description')).to eq(
|
212
214
|
id: '123',
|
213
215
|
href: '/people/123',
|
214
216
|
custom_key: 'custom value for model id 123'
|
215
|
-
|
217
|
+
)
|
216
218
|
end
|
217
219
|
|
218
220
|
it "includes a whitelist of attributes if specified as an array" do
|
219
|
-
serializer.as_json(person,
|
221
|
+
expect(serializer.as_json(person, attribute_whitelist: [:name, :description])).to eq(
|
220
222
|
name: 'Gavin',
|
221
223
|
description: 'This is person #123',
|
222
224
|
custom_key: 'custom value for model id 123'
|
223
|
-
|
225
|
+
)
|
224
226
|
end
|
225
227
|
|
226
228
|
it "includes a whitelist of attributes if specified as a string" do
|
227
|
-
serializer.as_json(person,
|
229
|
+
expect(serializer.as_json(person, attribute_whitelist: 'name, description')).to eq(
|
228
230
|
name: 'Gavin',
|
229
231
|
description: 'This is person #123',
|
230
232
|
custom_key: 'custom value for model id 123'
|
231
|
-
|
233
|
+
)
|
232
234
|
end
|
233
235
|
|
234
236
|
it "raises an exception if both the whitelist and blacklist are provided" do
|
235
237
|
expect do
|
236
|
-
serializer.as_json(person,
|
238
|
+
serializer.as_json(person, attribute_whitelist: [:name], attribute_blacklist: [:id])
|
237
239
|
end.to raise_error(ArgumentError, "the context can't define both an `attribute_whitelist` and an `attribute_blacklist`")
|
238
240
|
end
|
239
241
|
end
|
@@ -245,10 +247,10 @@ describe RestPack::Serializer do
|
|
245
247
|
it "includes 'links' data for :belongs_to associations" do
|
246
248
|
@album1 = FactoryGirl.create(:album_with_songs, song_count: 11)
|
247
249
|
json = serializer.as_json(@album1.songs.first)
|
248
|
-
json[:links].
|
250
|
+
expect(json[:links]).to eq(
|
249
251
|
artist: @album1.artist_id.to_s,
|
250
252
|
album: @album1.id.to_s
|
251
|
-
|
253
|
+
)
|
252
254
|
end
|
253
255
|
end
|
254
256
|
|
@@ -256,12 +258,13 @@ describe RestPack::Serializer do
|
|
256
258
|
let(:artist_factory) { FactoryGirl.create :artist_with_fans }
|
257
259
|
let(:artist_serializer) { MyApp::ArtistSerializer.new }
|
258
260
|
let(:json) { artist_serializer.as_json(artist_factory) }
|
259
|
-
let(:side_load_ids) { artist_has_association.map {|obj| obj.id.to_s } }
|
261
|
+
let(:side_load_ids) { artist_has_association.map { |obj| obj.id.to_s } }
|
260
262
|
|
261
263
|
context "when the association has been eager loaded" do
|
262
264
|
before do
|
263
|
-
artist_factory.fans.
|
265
|
+
allow(artist_factory.fans).to receive(:loaded?).and_return(true)
|
264
266
|
end
|
267
|
+
|
265
268
|
it "does not make a query to retrieve id values" do
|
266
269
|
expect(artist_factory.fans).not_to receive(:pluck)
|
267
270
|
json
|
@@ -291,7 +294,7 @@ describe RestPack::Serializer do
|
|
291
294
|
|
292
295
|
describe "#model_class" do
|
293
296
|
it "extracts the Model name from the Serializer name" do
|
294
|
-
PersonSerializer.model_class.
|
297
|
+
expect(PersonSerializer.model_class).to eq(Person)
|
295
298
|
end
|
296
299
|
|
297
300
|
context "with namespaced model class" do
|
@@ -306,7 +309,7 @@ describe RestPack::Serializer do
|
|
306
309
|
end
|
307
310
|
|
308
311
|
it "returns the correct class" do
|
309
|
-
NamespacedSerializer.model_class.
|
312
|
+
expect(NamespacedSerializer.model_class).to eq(SomeNamespace::Model)
|
310
313
|
end
|
311
314
|
end
|
312
315
|
end
|
@@ -314,15 +317,15 @@ describe RestPack::Serializer do
|
|
314
317
|
describe "#key" do
|
315
318
|
context "with default key" do
|
316
319
|
it "returns the correct key" do
|
317
|
-
PersonSerializer.key.
|
320
|
+
expect(PersonSerializer.key).to eq(:people)
|
318
321
|
end
|
319
322
|
|
320
323
|
it "has correct #singular_key" do
|
321
|
-
PersonSerializer.singular_key.
|
324
|
+
expect(PersonSerializer.singular_key).to eq(:person)
|
322
325
|
end
|
323
326
|
|
324
327
|
it "has correct #plural_key" do
|
325
|
-
PersonSerializer.plural_key.
|
328
|
+
expect(PersonSerializer.plural_key).to eq(:people)
|
326
329
|
end
|
327
330
|
end
|
328
331
|
|
@@ -333,11 +336,11 @@ describe RestPack::Serializer do
|
|
333
336
|
end
|
334
337
|
|
335
338
|
it "returns the correct key" do
|
336
|
-
SerializerWithCustomKey.key.
|
339
|
+
expect(SerializerWithCustomKey.key).to eq(:customers)
|
337
340
|
end
|
338
341
|
|
339
342
|
it "has correct #singular_key" do
|
340
|
-
SerializerWithCustomKey.singular_key.
|
343
|
+
expect(SerializerWithCustomKey.singular_key).to eq(:customer)
|
341
344
|
end
|
342
345
|
end
|
343
346
|
end
|
@@ -17,15 +17,15 @@ describe RestPack::Serializer::SideLoading do
|
|
17
17
|
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer) }
|
18
18
|
|
19
19
|
it "returns a hash with no data" do
|
20
|
-
side_loads.
|
20
|
+
expect(side_loads).to eq(meta: {})
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
context "when including :albums" do
|
25
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer,
|
25
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, "include" => "albums") }
|
26
26
|
|
27
27
|
it "returns a hash with no data" do
|
28
|
-
side_loads.
|
28
|
+
expect(side_loads).to eq(meta: {})
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -34,13 +34,13 @@ describe RestPack::Serializer::SideLoading do
|
|
34
34
|
let(:models) { [MyApp::Song.first] }
|
35
35
|
|
36
36
|
context "when including :albums" do
|
37
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer,
|
37
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, "include" => "albums") }
|
38
38
|
|
39
39
|
it "returns side-loaded albums" do
|
40
|
-
side_loads.
|
40
|
+
expect(side_loads).to eq(
|
41
41
|
albums: [MyApp::AlbumSerializer.as_json(MyApp::Song.first.album)],
|
42
|
-
meta: {
|
43
|
-
|
42
|
+
meta: {}
|
43
|
+
)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -53,16 +53,16 @@ describe RestPack::Serializer::SideLoading do
|
|
53
53
|
let(:models) { [song1, song2] }
|
54
54
|
|
55
55
|
context "when including :albums" do
|
56
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer,
|
56
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, "include" => "albums") }
|
57
57
|
|
58
58
|
it "returns side-loaded albums" do
|
59
|
-
side_loads.
|
59
|
+
expect(side_loads).to eq(
|
60
60
|
albums: [
|
61
61
|
MyApp::AlbumSerializer.as_json(song1.album),
|
62
62
|
MyApp::AlbumSerializer.as_json(song2.album)
|
63
63
|
],
|
64
|
-
:
|
65
|
-
|
64
|
+
meta: {}
|
65
|
+
)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -72,10 +72,13 @@ describe RestPack::Serializer::SideLoading do
|
|
72
72
|
let(:models) { [b_side] }
|
73
73
|
|
74
74
|
context 'when including :albums' do
|
75
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer,
|
75
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::SongSerializer, "include" => "albums") }
|
76
76
|
|
77
77
|
it 'return a hash with no data' do
|
78
|
-
side_loads.
|
78
|
+
expect(side_loads).to eq(
|
79
|
+
albums: [],
|
80
|
+
meta: {}
|
81
|
+
)
|
79
82
|
end
|
80
83
|
end
|
81
84
|
end
|
@@ -15,13 +15,13 @@ describe RestPack::Serializer::SideLoading do
|
|
15
15
|
let(:models) { [@artist1] }
|
16
16
|
|
17
17
|
context "when including :albums" do
|
18
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer,
|
18
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "stalkers") }
|
19
19
|
let(:stalker_count) { @artist1.stalkers.count }
|
20
20
|
|
21
21
|
it "returns side-loaded albums" do
|
22
|
-
side_loads[:stalkers].count.
|
23
|
-
side_loads[:meta][:stalkers][:page].
|
24
|
-
side_loads[:meta][:stalkers][:count].
|
22
|
+
expect(side_loads[:stalkers].count).to eq(stalker_count)
|
23
|
+
expect(side_loads[:meta][:stalkers][:page]).to eq(1)
|
24
|
+
expect(side_loads[:meta][:stalkers][:count]).to eq(stalker_count)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -30,12 +30,12 @@ describe RestPack::Serializer::SideLoading do
|
|
30
30
|
let(:models) { [@artist1, @artist2] }
|
31
31
|
|
32
32
|
context "when including :albums" do
|
33
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer,
|
33
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "stalkers") }
|
34
34
|
let(:stalker_count) { @artist1.stalkers.count + @artist2.stalkers.count }
|
35
35
|
|
36
36
|
it "returns side-loaded albums" do
|
37
|
-
side_loads[:stalkers].count.
|
38
|
-
side_loads[:meta][:stalkers][:count].
|
37
|
+
expect(side_loads[:stalkers].count).to eq(stalker_count)
|
38
|
+
expect(side_loads[:meta][:stalkers][:count]).to eq(stalker_count)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -15,12 +15,12 @@ describe RestPack::Serializer::SideLoading do
|
|
15
15
|
let(:models) { [@artist1] }
|
16
16
|
|
17
17
|
context "when including :albums" do
|
18
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer,
|
18
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "albums") }
|
19
19
|
|
20
20
|
it "returns side-loaded albums" do
|
21
|
-
side_loads[:albums].count.
|
22
|
-
side_loads[:meta][:albums][:page].
|
23
|
-
side_loads[:meta][:albums][:count].
|
21
|
+
expect(side_loads[:albums].count).to eq(@artist1.albums.count)
|
22
|
+
expect(side_loads[:meta][:albums][:page]).to eq(1)
|
23
|
+
expect(side_loads[:meta][:albums][:count]).to eq(@artist1.albums.count)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -29,12 +29,12 @@ describe RestPack::Serializer::SideLoading do
|
|
29
29
|
let(:models) { [@artist1, @artist2] }
|
30
30
|
|
31
31
|
context "when including :albums" do
|
32
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer,
|
32
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "albums") }
|
33
33
|
|
34
34
|
it "returns side-loaded albums" do
|
35
35
|
expected_count = @artist1.albums.count + @artist2.albums.count
|
36
|
-
side_loads[:albums].count.
|
37
|
-
side_loads[:meta][:albums][:count].
|
36
|
+
expect(side_loads[:albums].count).to eq(expected_count)
|
37
|
+
expect(side_loads[:meta][:albums][:count]).to eq(expected_count)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -42,28 +42,27 @@ describe RestPack::Serializer::SideLoading do
|
|
42
42
|
|
43
43
|
describe '.has_many through' do
|
44
44
|
context 'when including :fans' do
|
45
|
-
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer,
|
46
|
-
let(:artist_1) {FactoryGirl.create :artist_with_fans}
|
47
|
-
let(:artist_2) {FactoryGirl.create :artist_with_fans}
|
45
|
+
let(:options) { RestPack::Serializer::Options.new(MyApp::ArtistSerializer, "include" => "fans") }
|
46
|
+
let(:artist_1) { FactoryGirl.create :artist_with_fans }
|
47
|
+
let(:artist_2) { FactoryGirl.create :artist_with_fans }
|
48
48
|
|
49
49
|
context "with a single model" do
|
50
|
-
let(:models) {[artist_1]}
|
50
|
+
let(:models) { [artist_1] }
|
51
51
|
|
52
52
|
it 'returns side-loaded fans' do
|
53
|
-
side_loads[:fans].count.
|
54
|
-
side_loads[:meta][:fans][:page].
|
55
|
-
side_loads[:meta][:fans][:count].
|
53
|
+
expect(side_loads[:fans].count).to eq(artist_1.fans.count)
|
54
|
+
expect(side_loads[:meta][:fans][:page]).to eq(1)
|
55
|
+
expect(side_loads[:meta][:fans][:count]).to eq(artist_1.fans.count)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
context "with a multiple models" do
|
59
|
-
let(:models) {[artist_1, artist_2]}
|
59
|
+
let(:models) { [artist_1, artist_2] }
|
60
60
|
|
61
61
|
it 'returns side-loaded fans' do
|
62
|
-
expected_count = artist_1.fans.count
|
63
|
-
|
64
|
-
side_loads[:fans].
|
65
|
-
side_loads[:meta][:fans][:
|
66
|
-
side_loads[:meta][:fans][:count].should == expected_count
|
62
|
+
expected_count = artist_1.fans.count + artist_2.fans.count
|
63
|
+
expect(side_loads[:fans].count).to eq(expected_count)
|
64
|
+
expect(side_loads[:meta][:fans][:page]).to eq(1)
|
65
|
+
expect(side_loads[:meta][:fans][:count]).to eq(expected_count)
|
67
66
|
end
|
68
67
|
|
69
68
|
context "when there are shared fans" do
|