rating 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -9
  3. data/README.md +16 -5
  4. data/lib/rating/models/rating/extension.rb +1 -2
  5. data/lib/rating/models/rating/rate.rb +2 -2
  6. data/lib/rating/models/rating/rating.rb +2 -2
  7. data/lib/rating/version.rb +1 -1
  8. metadata +56 -130
  9. data/spec/config/rate_table_spec.rb +0 -17
  10. data/spec/config/rating_table_spec.rb +0 -17
  11. data/spec/config/validations_spec.rb +0 -33
  12. data/spec/factories/article.rb +0 -7
  13. data/spec/factories/author.rb +0 -7
  14. data/spec/factories/category.rb +0 -7
  15. data/spec/factories/comment.rb +0 -5
  16. data/spec/factories/global.rb +0 -6
  17. data/spec/factories/rating/rate.rb +0 -10
  18. data/spec/factories/rating/rating.rb +0 -12
  19. data/spec/factories/toy.rb +0 -6
  20. data/spec/models/extension/after_create_spec.rb +0 -47
  21. data/spec/models/extension/order_by_rating_spec.rb +0 -180
  22. data/spec/models/extension/rate_for_spec.rb +0 -41
  23. data/spec/models/extension/rate_spec.rb +0 -60
  24. data/spec/models/extension/rated_question_spec.rb +0 -48
  25. data/spec/models/extension/rated_records_spec.rb +0 -12
  26. data/spec/models/extension/rated_spec.rb +0 -50
  27. data/spec/models/extension/rates_records_spec.rb +0 -12
  28. data/spec/models/extension/rates_spec.rb +0 -50
  29. data/spec/models/extension/rating_records_spec.rb +0 -12
  30. data/spec/models/extension/rating_spec.rb +0 -40
  31. data/spec/models/extension/rating_warm_up_spec.rb +0 -115
  32. data/spec/models/extension/unscoped_rating_spec.rb +0 -99
  33. data/spec/models/extension/where_spec.rb +0 -33
  34. data/spec/models/rate/create_spec.rb +0 -422
  35. data/spec/models/rate/rate_for_spec.rb +0 -107
  36. data/spec/models/rate_spec.rb +0 -28
  37. data/spec/models/rating/averager_data_spec.rb +0 -32
  38. data/spec/models/rating/data_spec.rb +0 -48
  39. data/spec/models/rating/update_rating_spec.rb +0 -48
  40. data/spec/models/rating/values_data_spec.rb +0 -40
  41. data/spec/models/rating_spec.rb +0 -24
  42. data/spec/rails_helper.rb +0 -17
  43. data/spec/support/common.rb +0 -22
  44. data/spec/support/database_cleaner.rb +0 -19
  45. data/spec/support/db/migrate/add_comment_on_rating_rates_table.rb +0 -8
  46. data/spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb +0 -8
  47. data/spec/support/db/migrate/create_articles_table.rb +0 -9
  48. data/spec/support/db/migrate/create_authors_table.rb +0 -9
  49. data/spec/support/db/migrate/create_categories_table.rb +0 -12
  50. data/spec/support/db/migrate/create_comments_table.rb +0 -7
  51. data/spec/support/db/migrate/create_globals_table.rb +0 -8
  52. data/spec/support/db/migrate/create_rates_table.rb +0 -19
  53. data/spec/support/db/migrate/create_rating_table.rb +0 -20
  54. data/spec/support/db/migrate/create_review_ratings_table.rb +0 -17
  55. data/spec/support/db/migrate/create_reviews_table.rb +0 -15
  56. data/spec/support/db/migrate/create_toys_table.rb +0 -8
  57. data/spec/support/factory_bot.rb +0 -9
  58. data/spec/support/migrate.rb +0 -21
  59. data/spec/support/models/article.rb +0 -7
  60. data/spec/support/models/author.rb +0 -5
  61. data/spec/support/models/category.rb +0 -6
  62. data/spec/support/models/comment.rb +0 -5
  63. data/spec/support/models/global.rb +0 -7
  64. data/spec/support/models/review.rb +0 -5
  65. data/spec/support/models/review_rating.rb +0 -4
  66. data/spec/support/models/toy.rb +0 -5
  67. data/spec/support/shared_context/with_database_records.rb +0 -20
  68. data/spec/support/shoulda.rb +0 -10
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Extension, 'unscoped_rating' do
6
- let!(:author_1) { create :author }
7
- let!(:author_2) { create :author }
8
- let!(:author_3) { create :author }
9
- let!(:scope) { create :category }
10
-
11
- context 'when is false' do
12
- let!(:resource) { create :article }
13
-
14
- it 'groups in different line record' do
15
- author_1.rate resource, 1, scope: scope
16
- author_2.rate resource, 2, scope: scope
17
- author_2.rate resource, 5
18
-
19
- ratings = Rating::Rating.all.order('id')
20
-
21
- expect(ratings.size).to eq 2
22
-
23
- rating = ratings[0]
24
-
25
- expect(rating.average.to_s).to eq '1.5'
26
- expect(rating.estimate.to_s).to eq '1.5'
27
- expect(rating.resource).to eq resource
28
- expect(rating.scopeable).to eq scope
29
- expect(rating.sum).to eq 3
30
- expect(rating.total).to eq 2
31
-
32
- rating = ratings[1]
33
-
34
- expect(rating.average.to_s).to eq '5.0'
35
- expect(rating.estimate.to_s).to eq '5.0'
36
- expect(rating.resource).to eq resource
37
- expect(rating.scopeable).to eq nil
38
- expect(rating.sum).to eq 5
39
- expect(rating.total).to eq 1
40
- end
41
- end
42
-
43
- context 'when is true' do
44
- let!(:resource) { create :global }
45
-
46
- it 'groups in the same line record' do
47
- author_1.rate resource, 1, scope: scope
48
- author_2.rate resource, 2, scope: scope
49
- author_2.rate resource, 5
50
-
51
- ratings = Rating::Rating.all.order('id')
52
-
53
- expect(ratings.size).to eq 1
54
-
55
- rating = ratings[0]
56
-
57
- expect(rating.average.to_s).to eq '2.6666666666666667'
58
- expect(rating.estimate.to_s).to eq '2.6666666666666667'
59
- expect(rating.resource).to eq resource
60
- expect(rating.scopeable).to eq nil
61
- expect(rating.sum).to eq 8
62
- expect(rating.total).to eq 3
63
- end
64
- end
65
-
66
- context 'when is true and have a non scoped record first on database' do
67
- let!(:resource) { create :global }
68
-
69
- before { ::Rating::Rating.create resource: resource, scopeable: scope }
70
-
71
- it 'sets the result on record with no scope' do
72
- author_1.rate resource, 1, scope: scope
73
- author_2.rate resource, 2, scope: scope
74
- author_3.rate resource, 5
75
-
76
- ratings = Rating::Rating.all.order('id')
77
-
78
- expect(ratings.size).to eq 2
79
-
80
- rating = ratings[0]
81
-
82
- expect(rating.average.to_s).to eq '0.0'
83
- expect(rating.estimate.to_s).to eq '0.0'
84
- expect(rating.resource).to eq resource
85
- expect(rating.scopeable).to eq scope
86
- expect(rating.sum).to eq 0
87
- expect(rating.total).to eq 0
88
-
89
- rating = ratings[1]
90
-
91
- expect(rating.average.to_s).to eq '2.6666666666666667'
92
- expect(rating.estimate.to_s).to eq '2.6666666666666667'
93
- expect(rating.resource).to eq resource
94
- expect(rating.scopeable).to eq nil
95
- expect(rating.sum).to eq 8
96
- expect(rating.total).to eq 3
97
- end
98
- end
99
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Extension, 'unscoped_rating' do
6
- let!(:author_1) { create :author }
7
- let!(:author_2) { create :author }
8
- let!(:author_3) { create :author }
9
- let!(:author_4) { create :author }
10
- let!(:author_5) { create :author }
11
- let!(:resource) { create :toy }
12
-
13
- it 'uses rate with where condition' do
14
- author_1.rate resource, 1
15
- author_2.rate resource, 2
16
- author_3.rate resource, 3
17
- author_4.rate resource, 4
18
- author_5.rate resource, 5
19
-
20
- ratings = Rating::Rating.all.order('id')
21
-
22
- expect(ratings.size).to eq 1
23
-
24
- rating = ratings[0]
25
-
26
- expect(rating.average.to_s).to eq '3.0'
27
- expect(rating.estimate.to_s).to eq '3.0'
28
- expect(rating.resource).to eq resource
29
- expect(rating.scopeable).to eq nil
30
- expect(rating.sum).to eq 9
31
- expect(rating.total).to eq 3
32
- end
33
- end
@@ -1,422 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Rate, ':create' do
6
- let!(:author) { create :author }
7
- let!(:article) { create :article }
8
-
9
- context 'with no scopeable' do
10
- before { described_class.create author: author, extra_scopes: {}, metadata: {}, resource: article, value: 3 }
11
-
12
- context 'when rate does not exist yet' do
13
- it 'creates a rate entry' do
14
- rate = described_class.last
15
-
16
- expect(rate.author).to eq author
17
- expect(rate.resource).to eq article
18
- expect(rate.value).to eq 3
19
- end
20
-
21
- it 'creates a rating entry' do
22
- rating = Rating::Rating.last
23
-
24
- expect(rating.average).to eq 3
25
- expect(rating.estimate).to eq 3
26
- expect(rating.resource).to eq article
27
- expect(rating.sum).to eq 3
28
- expect(rating.total).to eq 1
29
- end
30
- end
31
-
32
- context 'when rate already exists' do
33
- let!(:author_2) { create :author }
34
-
35
- before { described_class.create author: author_2, extra_scopes: {}, metadata: {}, resource: article, value: 4 }
36
-
37
- it 'creates one more rate entry' do
38
- rates = described_class.where(author: [author, author_2]).order('created_at asc')
39
-
40
- expect(rates.size).to eq 2
41
-
42
- rate = rates[0]
43
-
44
- expect(rate.author).to eq author
45
- expect(rate.resource).to eq article
46
- expect(rate.value).to eq 3
47
-
48
- rate = rates[1]
49
-
50
- expect(rate.author).to eq author_2
51
- expect(rate.resource).to eq article
52
- expect(rate.value).to eq 4
53
- end
54
-
55
- it 'updates the unique rating entry' do
56
- rating = Rating::Rating.find_by(resource: article)
57
-
58
- expect(rating.average).to eq 3.5
59
- expect(rating.estimate).to eq 3.5
60
- expect(rating.resource).to eq article
61
- expect(rating.sum).to eq 7
62
- expect(rating.total).to eq 2
63
- end
64
- end
65
- end
66
-
67
- context 'with scopeable' do
68
- let!(:category) { create :category }
69
-
70
- before do
71
- described_class.create(
72
- author: author,
73
- extra_scopes: {},
74
- metadata: {},
75
- resource: article,
76
- scopeable: category,
77
- value: 3
78
- )
79
- end
80
-
81
- context 'when rate does not exist yet' do
82
- it 'creates a rate entry' do
83
- rate = described_class.last
84
-
85
- expect(rate.author).to eq author
86
- expect(rate.resource).to eq article
87
- expect(rate.scopeable).to eq category
88
- expect(rate.value).to eq 3
89
- end
90
-
91
- it 'creates a rating entry' do
92
- rating = Rating::Rating.last
93
-
94
- expect(rating.average).to eq 3
95
- expect(rating.estimate).to eq 3
96
- expect(rating.resource).to eq article
97
- expect(rating.scopeable).to eq category
98
- expect(rating.sum).to eq 3
99
- expect(rating.total).to eq 1
100
- end
101
- end
102
-
103
- context 'when rate already exists' do
104
- let!(:author_2) { create :author }
105
-
106
- before do
107
- described_class.create(
108
- author: author_2,
109
- extra_scopes: {},
110
- metadata: {},
111
- resource: article,
112
- scopeable: category,
113
- value: 4
114
- )
115
- end
116
-
117
- it 'creates one more rate entry' do
118
- rates = described_class.where(author: [author, author_2]).order('created_at asc')
119
-
120
- expect(rates.size).to eq 2
121
-
122
- rate = rates[0]
123
-
124
- expect(rate.author).to eq author
125
- expect(rate.resource).to eq article
126
- expect(rate.scopeable).to eq category
127
- expect(rate.value).to eq 3
128
-
129
- rate = rates[1]
130
-
131
- expect(rate.author).to eq author_2
132
- expect(rate.resource).to eq article
133
- expect(rate.scopeable).to eq category
134
- expect(rate.value).to eq 4
135
- end
136
-
137
- it 'updates the unique rating entry' do
138
- rating = Rating::Rating.find_by(resource: article, scopeable: category)
139
-
140
- expect(rating.average).to eq 3.5
141
- expect(rating.estimate).to eq 3.5
142
- expect(rating.resource).to eq article
143
- expect(rating.scopeable).to eq category
144
- expect(rating.sum).to eq 7
145
- expect(rating.total).to eq 2
146
- end
147
- end
148
- end
149
-
150
- context 'with metadata' do
151
- context 'with nil value' do
152
- it 'creates a rate entry ignoring metadata' do
153
- described_class.create author: author, extra_scopes: {}, metadata: nil, resource: article, value: 3
154
-
155
- rate = described_class.last
156
-
157
- expect(rate.author).to eq author
158
- expect(rate.comment).to eq nil
159
- expect(rate.resource).to eq article
160
- expect(rate.value).to eq 3
161
- end
162
- end
163
-
164
- context 'with empty value' do
165
- it 'creates a rate entry ignoring metadata' do
166
- described_class.create author: author, extra_scopes: {}, metadata: '', resource: article, value: 3
167
-
168
- rate = described_class.last
169
-
170
- expect(rate.author).to eq author
171
- expect(rate.comment).to eq nil
172
- expect(rate.resource).to eq article
173
- expect(rate.value).to eq 3
174
- end
175
- end
176
-
177
- context 'with hash value' do
178
- it 'creates a rate entry with metadata included' do
179
- described_class.create(
180
- author: author,
181
- extra_scopes: {},
182
- metadata: { comment: 'comment' },
183
- resource: article,
184
- value: 3
185
- )
186
-
187
- rate = described_class.last
188
-
189
- expect(rate.author).to eq author
190
- expect(rate.comment).to eq 'comment'
191
- expect(rate.resource).to eq article
192
- expect(rate.value).to eq 3
193
- end
194
- end
195
-
196
- context 'when already has an entry' do
197
- before do
198
- described_class.create(
199
- author: author,
200
- extra_scopes: {},
201
- metadata: { comment: 'comment' },
202
- resource: article,
203
- value: 1
204
- )
205
- end
206
-
207
- context 'when value is the same' do
208
- it 'still updates metadata' do
209
- described_class.create(
210
- author: author,
211
- extra_scopes: {},
212
- metadata: { comment: 'comment.updated' },
213
- resource: article,
214
- value: 1
215
- )
216
-
217
- rates = described_class.all
218
-
219
- expect(rates.size).to eq 1
220
-
221
- rate = rates[0]
222
-
223
- expect(rate.author).to eq author
224
- expect(rate.comment).to eq 'comment.updated'
225
- expect(rate.resource).to eq article
226
- expect(rate.value).to eq 1
227
- end
228
- end
229
-
230
- context 'when value is different same' do
231
- it 'still updates metadata' do
232
- described_class.create(
233
- author: author,
234
- extra_scopes: {},
235
- metadata: { comment: 'comment.updated' },
236
- resource: article,
237
- value: 2
238
- )
239
-
240
- rates = described_class.all
241
-
242
- expect(rates.size).to eq 1
243
-
244
- rate = rates[0]
245
-
246
- expect(rate.author).to eq author
247
- expect(rate.comment).to eq 'comment.updated'
248
- expect(rate.resource).to eq article
249
- expect(rate.value).to eq 2
250
- end
251
- end
252
- end
253
- end
254
-
255
- if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
256
- context 'with extra scopes' do
257
- let!(:category) { create :category }
258
-
259
- it 'creates a rate entry' do
260
- described_class.create(
261
- author: author,
262
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
263
- metadata: {},
264
- resource: article,
265
- scopeable: category,
266
- value: 1
267
- )
268
-
269
- rate = described_class.last
270
-
271
- expect(rate.author).to eq author
272
- expect(rate.resource).to eq article
273
- expect(rate.scope_1).to eq 'scope_1'
274
- expect(rate.scope_2).to eq 'scope_2'
275
- expect(rate.scopeable).to eq category
276
- expect(rate.value).to eq 1
277
- end
278
-
279
- it 'creates a rating entry' do
280
- described_class.create(
281
- author: author,
282
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
283
- metadata: {},
284
- resource: article,
285
- scopeable: category,
286
- value: 1
287
- )
288
-
289
- rating = Rating::Rating.last
290
-
291
- expect(rating.average).to eq 1
292
- expect(rating.estimate).to eq 1
293
- expect(rating.resource).to eq article
294
- expect(rating.scopeable).to eq category
295
- expect(rating.sum).to eq 1
296
- expect(rating.total).to eq 1
297
- end
298
-
299
- context 'when rate already exists' do
300
- before do
301
- described_class.create(
302
- author: author,
303
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
304
- metadata: {},
305
- resource: article,
306
- scopeable: category,
307
- value: 1
308
- )
309
- end
310
-
311
- it 'updates the rate entry' do
312
- described_class.create(
313
- author: author,
314
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
315
- metadata: {},
316
- resource: article,
317
- scopeable: category,
318
- value: 2
319
- )
320
-
321
- rates = described_class.all
322
-
323
- expect(rates.size).to eq 1
324
-
325
- rate = rates[0]
326
-
327
- expect(rate.author).to eq author
328
- expect(rate.resource).to eq article
329
- expect(rate.scope_1).to eq 'scope_1'
330
- expect(rate.scope_2).to eq 'scope_2'
331
- expect(rate.scopeable).to eq category
332
- expect(rate.value).to eq 2
333
- end
334
-
335
- it 'updates the unique rating entry' do
336
- described_class.create(
337
- author: author,
338
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
339
- metadata: {},
340
- resource: article,
341
- scopeable: category,
342
- value: 2
343
- )
344
-
345
- ratings = Rating::Rating.all
346
-
347
- expect(ratings.size).to eq 1
348
-
349
- rating = ratings[0]
350
-
351
- expect(rating.average).to eq 2
352
- expect(rating.estimate).to eq 2
353
- expect(rating.resource).to eq article
354
- expect(rating.scopeable).to eq category
355
- expect(rating.sum).to eq 2
356
- expect(rating.total).to eq 1
357
- end
358
- end
359
-
360
- context 'when rate already exists but with at least one extra scope different' do
361
- before do
362
- described_class.create(
363
- author: author,
364
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
365
- metadata: {},
366
- resource: article,
367
- scopeable: category,
368
- value: 1
369
- )
370
-
371
- described_class.create(
372
- author: author,
373
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_missing' },
374
- metadata: {},
375
- resource: article,
376
- scopeable: category,
377
- value: 2
378
- )
379
- end
380
-
381
- it 'creates a new rate entry' do
382
- rates = described_class.all
383
-
384
- expect(rates.size).to eq 2
385
-
386
- rate = rates[0]
387
-
388
- expect(rate.author).to eq author
389
- expect(rate.resource).to eq article
390
- expect(rate.scope_1).to eq 'scope_1'
391
- expect(rate.scope_2).to eq 'scope_2'
392
- expect(rate.scopeable).to eq category
393
- expect(rate.value).to eq 1
394
-
395
- rate = rates[1]
396
-
397
- expect(rate.author).to eq author
398
- expect(rate.resource).to eq article
399
- expect(rate.scope_1).to eq 'scope_1'
400
- expect(rate.scope_2).to eq 'scope_missing'
401
- expect(rate.scopeable).to eq category
402
- expect(rate.value).to eq 2
403
- end
404
-
405
- it 'updates the unique rating entry' do
406
- ratings = Rating::Rating.all
407
-
408
- expect(ratings.size).to eq 1
409
-
410
- rating = ratings[0]
411
-
412
- expect(rating.average).to eq 1.5
413
- expect(rating.estimate).to eq 1.5
414
- expect(rating.resource).to eq article
415
- expect(rating.scopeable).to eq category
416
- expect(rating.sum).to eq 3
417
- expect(rating.total).to eq 2
418
- end
419
- end
420
- end
421
- end
422
- end
@@ -1,107 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Rate, ':rate_for' do
6
- let!(:author) { create :author }
7
- let!(:article) { create :article }
8
-
9
- context 'with no scopeable' do
10
- context 'when rate does not exist' do
11
- it { expect(described_class.rate_for(author: author, resource: article)).to eq nil }
12
- end
13
-
14
- context 'when rate exists' do
15
- let!(:record) do
16
- described_class.create author: author, extra_scopes: {}, metadata: {}, resource: article, value: 3
17
- end
18
-
19
- it 'returns the record' do
20
- expect(described_class.rate_for(author: author, resource: article)).to eq record
21
- end
22
- end
23
- end
24
-
25
- context 'with scopeable' do
26
- let!(:category) { create :category }
27
-
28
- context 'when rate does not exist' do
29
- it do
30
- expect(described_class.rate_for(author: author, resource: article, scopeable: category)).to eq nil
31
- end
32
- end
33
-
34
- context 'when rate exists' do
35
- let!(:record) do
36
- described_class.create(
37
- author: author,
38
- extra_scopes: {},
39
- metadata: {},
40
- resource: article,
41
- scopeable: category,
42
- value: 3
43
- )
44
- end
45
-
46
- it 'returns the record' do
47
- query = described_class.rate_for(author: author, resource: article, scopeable: category)
48
-
49
- expect(query).to eq record
50
- end
51
- end
52
- end
53
-
54
- if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
55
- context 'with extra scopes' do
56
- let!(:category) { create :category }
57
-
58
- context 'when matches all attributes including the extra scopes' do
59
- let!(:record) do
60
- described_class.create(
61
- author: author,
62
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
63
- metadata: {},
64
- resource: article,
65
- scopeable: category,
66
- value: 1
67
- )
68
- end
69
-
70
- it 'returns the record' do
71
- result = described_class.rate_for(
72
- author: author,
73
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
74
- resource: article,
75
- scopeable: category
76
- )
77
-
78
- expect(result).to eq record
79
- end
80
- end
81
-
82
- context 'when matches all attributes but at least one extra scopes' do
83
- before do
84
- described_class.create(
85
- author: author,
86
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_2' },
87
- metadata: {},
88
- resource: article,
89
- scopeable: category,
90
- value: 1
91
- )
92
- end
93
-
94
- it 'does not return the record' do
95
- result = described_class.rate_for(
96
- author: author,
97
- extra_scopes: { scope_1: 'scope_1', scope_2: 'scope_missing' },
98
- resource: article,
99
- scopeable: category
100
- )
101
-
102
- expect(result).to eq nil
103
- end
104
- end
105
- end
106
- end
107
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Rate do
6
- let!(:object) { build :rating_rate }
7
-
8
- it { expect(object).to be_valid }
9
-
10
- it { is_expected.to belong_to :author }
11
- it { is_expected.to belong_to :resource }
12
- it { is_expected.to belong_to :scopeable }
13
-
14
- it { is_expected.to validate_presence_of :author }
15
- it { is_expected.to validate_presence_of :resource }
16
- it { is_expected.to validate_presence_of :value }
17
-
18
- it do
19
- expect(subject).to validate_numericality_of(:value).is_less_than_or_equal_to(100).is_less_than_or_equal_to 100
20
- end
21
-
22
- it do
23
- scopes = %i[author_type resource_id resource_type scopeable_id scopeable_type]
24
- scopes += %i[scope_1 scope_2] if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
25
-
26
- expect(object).to validate_uniqueness_of(:author_id).scoped_to(scopes).case_insensitive
27
- end
28
- end