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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3478dbe5fac4bb47db0a3b730f0b21d49747912056447d9de55d5ec82f6072ec
4
- data.tar.gz: 3d95a77107c053347876554c1f36121a62b9342dd4b585833cd12b2f32aadd0c
3
+ metadata.gz: 107d28dc3f0be409a1684eebea163b6dcf6cc57d801f7dcd88bca4f0bcf4f662
4
+ data.tar.gz: af591a933ee3bf23720cd054c33968ec9fbba3f21cbd9d117dd1628f0b6cebb5
5
5
  SHA512:
6
- metadata.gz: caabeb2c0336c22a86d95a064688424d242c96f84c8e28bd93883a2472f15a22d937ab726f060f765332bb8277f19ffb2fde571a2e7019b91e02c8aced96867d
7
- data.tar.gz: 5acbf2bb5e2280de7507e9c23785ecc75e31b62a8c434a48972f50e78d09fa38a8e4280d4272c91bb3109994cdab217f5766a01d94c5a384d9990aa080c18e06
6
+ metadata.gz: 3c3dc424ab1155b6a7f6aa309b461015c7d06b2786c172d55b03b29052a3643d098fe78dde4a9c7edf2b564ea324451e5ad1a12373769caa7b6520cb0b5def8d
7
+ data.tar.gz: b92eaadfdaa4cca67eca6e3a5550333080541d93b1a48e01dace83bc858969fc718f60123c40353c15bf3ec6c42166b2359d9d82e05b315454a4ca74b91b32be
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## v0.12.0
2
+
3
+ ### News
4
+
5
+ - Officially Supports Postgres;
6
+
7
+ ### Updates
8
+
9
+ - Migrates the CI to GitHub Actions;
10
+ - This gem does not depends on `git` package anymore;
11
+ - Makes this gem requires MFA for security;
12
+ - Adds coverage test;
13
+ - The method `rated?` now uses a better query;
14
+
1
15
  ## v0.11.0
2
16
 
3
17
  ### Updates
@@ -14,47 +28,47 @@
14
28
 
15
29
  ### News
16
30
 
17
- - Order index keys of template the same way Rails does the query;
31
+ - Order index keys of the template the same way Rails does the query;
18
32
  - Limits the `_type` columns to avoid overflow bytes in DBs like MySQL < 5.7.
19
33
 
20
34
  ### Updates
21
35
 
22
36
  - Update Ruby to 2.6.5;
23
- - Update Activerecord to the last version;
37
+ - Update ActiveRecord to the last version;
24
38
 
25
39
  ## v0.8.0
26
40
 
27
41
  ### News
28
42
 
29
- - Adds `unscoped_rating` option to calculate the rating counting all resource record ignoring the scope.
43
+ - Adds `unscoped_rating` option to calculate the rating by counting all resource records ignoring the scope.
30
44
 
31
45
  ## v0.7.0
32
46
 
33
47
  ### News
34
48
 
35
49
  - Support to configure `uniqueness` validation via YAML into Rating::Rate model;
36
- - Support to multiple scopes via `extra_scopes` option.
50
+ - Support multiple scopes via `extra_scopes` option.
37
51
 
38
52
  ### Updates
39
53
 
40
- - Reverts v0.6.0, since we need this validation because we cannot edit the Rate model by ourself.
54
+ - Reverts v0.6.0, since we need this validation because we cannot edit the Rate model by ourselves.
41
55
 
42
56
  ## v0.6.0
43
57
 
44
58
  ### Updates
45
59
 
46
- - The author unique validations was removed to enable custom validations
60
+ - The author's unique validations were removed to enable custom validations
47
61
 
48
62
  ## v0.5.0
49
63
 
50
64
  ### News
51
65
 
52
- - Adds `rating.yml` config to support to change the tables where Rating will write the data;
53
- - Adds `scoping` option to support to generates zero based rating via scope.
66
+ - Adds `rating.yml` config to support changing the tables where Rating will write the data;
67
+ - Adds `scoping` option to support generating zero-based rating via scope.
54
68
 
55
69
  ### Updates
56
70
 
57
- - The migrate was separated in two to improve in troubleshoot. (iondrimba)
71
+ - The migration was separated in two to improve troubleshooting. [#1](https://github.com/wbotelhos/rating/pull/1) by [iondrimba](https://github.com/iondrimba)
58
72
 
59
73
  ## v0.4.0
60
74
 
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Rating
2
2
 
3
- [![Build Status](https://travis-ci.org/wbotelhos/rating.svg)](https://travis-ci.org/wbotelhos/rating)
3
+ [![CI](https://github.com/wbotelhos/rating/workflows/CI/badge.svg)](https://github.com/wbotelhos/rating/actions)
4
4
  [![Gem Version](https://badge.fury.io/rb/rating.svg)](https://badge.fury.io/rb/rating)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/cc5efe8b06bc1d5e9e8a/maintainability)](https://codeclimate.com/github/wbotelhos/rating/maintainability)
6
- [![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos)
6
+ [![codecov](https://codecov.io/gh/wbotelhos/rating/branch/master/graph/badge.svg?token=QJSHUOULEG)](https://codecov.io/gh/wbotelhos/rating)
7
+ [![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)
7
8
 
8
9
  A true Bayesian rating system with scope and cache enabled.
9
10
 
@@ -51,15 +52,15 @@ Add the following code on your `Gemfile` and run `bundle install`:
51
52
  gem 'rating'
52
53
  ```
53
54
 
54
- Run the following task to create a Rating migration:
55
+ Run the following task to create the Rating migration:
55
56
 
56
- ```bash
57
+ ```sh
57
58
  rails g rating:install
58
59
  ```
59
60
 
60
61
  Then execute the migrations to create the to create tables `rating_rates` and `rating_ratings`:
61
62
 
62
- ```bash
63
+ ```sh
63
64
  rake db:migrate
64
65
  ```
65
66
 
@@ -423,6 +424,16 @@ author.rate resource, 5, extra_scope: { approved: true }
423
424
 
424
425
  As you can see, now, only the rate with value `5` will be included on the final rating.
425
426
 
427
+ ### Specs
428
+
429
+ To run all specs, run the following rakes:
430
+
431
+ ```sh
432
+ bundle exec rake spec
433
+ bundle exec rake spec_config
434
+ bundle exec rake spec_config_with_extra_scopes
435
+ ```
436
+
426
437
  ### References
427
438
 
428
439
  - [Evan Miller](http://www.evanmiller.org/ranking-items-with-star-ratings.html)
@@ -20,9 +20,8 @@ module Rating
20
20
  Rate.rate_for author: self, extra_scopes: extra_scopes, resource: resource, scopeable: scope
21
21
  end
22
22
 
23
- # TODO: use exists for performance
24
23
  def rated?(resource, extra_scopes: {}, scope: nil)
25
- !rate_for(resource, extra_scopes: extra_scopes, scope: scope).nil?
24
+ Rate.exists?(extra_scopes.merge(author: self, resource: resource, scopeable: scope))
26
25
  end
27
26
 
28
27
  def rates(extra_scopes: {}, scope: nil)
@@ -19,7 +19,7 @@ module Rating
19
19
  scope: ::Rating::Config.validations['rate']['scope'].map(&:to_sym),
20
20
  }
21
21
 
22
- def self.create(author:, extra_scopes:, metadata:, resource:, scopeable: nil, value:)
22
+ def self.create(author:, extra_scopes:, metadata:, resource:, value:, scopeable: nil)
23
23
  attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes)
24
24
  record = find_or_initialize_by(attributes)
25
25
 
@@ -31,7 +31,7 @@ module Rating
31
31
  record
32
32
  end
33
33
 
34
- def self.rate_for(author:, extra_scopes: {}, resource:, scopeable: nil)
34
+ def self.rate_for(author:, resource:, extra_scopes: {}, scopeable: nil)
35
35
  find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable)
36
36
  end
37
37
 
@@ -93,8 +93,8 @@ module Rating
93
93
  resource_rating_avg = values.rating_avg
94
94
  resource_rating_count = values.rating_count.to_f
95
95
 
96
- (resource_rating_count / (resource_rating_count + count_avg)) * resource_rating_avg +
97
- (count_avg / (resource_rating_count + count_avg)) * resource_type_rating_avg
96
+ ((resource_rating_count / (resource_rating_count + count_avg)) * resource_rating_avg) +
97
+ ((count_avg / (resource_rating_count + count_avg)) * resource_type_rating_avg)
98
98
  end
99
99
 
100
100
  def execute_sql(sql)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rating
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rating
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2022-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: database_cleaner
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: debug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: factory_bot_rails
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +95,7 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: pry-byebug
98
+ name: pg
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - ">="
@@ -108,6 +136,20 @@ dependencies:
108
136
  - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rails
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
111
153
  - !ruby/object:Gem::Dependency
112
154
  name: rubocop-rspec
113
155
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +182,10 @@ description: A true Bayesian rating system with scope and cache enabled.
140
182
  email: wbotelhos@gmail.com
141
183
  executables: []
142
184
  extensions: []
143
- extra_rdoc_files: []
185
+ extra_rdoc_files:
186
+ - CHANGELOG.md
187
+ - LICENSE
188
+ - README.md
144
189
  files:
145
190
  - CHANGELOG.md
146
191
  - LICENSE
@@ -154,71 +199,12 @@ files:
154
199
  - lib/rating/models/rating/rate.rb
155
200
  - lib/rating/models/rating/rating.rb
156
201
  - lib/rating/version.rb
157
- - spec/config/rate_table_spec.rb
158
- - spec/config/rating_table_spec.rb
159
- - spec/config/validations_spec.rb
160
- - spec/factories/article.rb
161
- - spec/factories/author.rb
162
- - spec/factories/category.rb
163
- - spec/factories/comment.rb
164
- - spec/factories/global.rb
165
- - spec/factories/rating/rate.rb
166
- - spec/factories/rating/rating.rb
167
- - spec/factories/toy.rb
168
- - spec/models/extension/after_create_spec.rb
169
- - spec/models/extension/order_by_rating_spec.rb
170
- - spec/models/extension/rate_for_spec.rb
171
- - spec/models/extension/rate_spec.rb
172
- - spec/models/extension/rated_question_spec.rb
173
- - spec/models/extension/rated_records_spec.rb
174
- - spec/models/extension/rated_spec.rb
175
- - spec/models/extension/rates_records_spec.rb
176
- - spec/models/extension/rates_spec.rb
177
- - spec/models/extension/rating_records_spec.rb
178
- - spec/models/extension/rating_spec.rb
179
- - spec/models/extension/rating_warm_up_spec.rb
180
- - spec/models/extension/unscoped_rating_spec.rb
181
- - spec/models/extension/where_spec.rb
182
- - spec/models/rate/create_spec.rb
183
- - spec/models/rate/rate_for_spec.rb
184
- - spec/models/rate_spec.rb
185
- - spec/models/rating/averager_data_spec.rb
186
- - spec/models/rating/data_spec.rb
187
- - spec/models/rating/update_rating_spec.rb
188
- - spec/models/rating/values_data_spec.rb
189
- - spec/models/rating_spec.rb
190
- - spec/rails_helper.rb
191
- - spec/support/common.rb
192
- - spec/support/database_cleaner.rb
193
- - spec/support/db/migrate/add_comment_on_rating_rates_table.rb
194
- - spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb
195
- - spec/support/db/migrate/create_articles_table.rb
196
- - spec/support/db/migrate/create_authors_table.rb
197
- - spec/support/db/migrate/create_categories_table.rb
198
- - spec/support/db/migrate/create_comments_table.rb
199
- - spec/support/db/migrate/create_globals_table.rb
200
- - spec/support/db/migrate/create_rates_table.rb
201
- - spec/support/db/migrate/create_rating_table.rb
202
- - spec/support/db/migrate/create_review_ratings_table.rb
203
- - spec/support/db/migrate/create_reviews_table.rb
204
- - spec/support/db/migrate/create_toys_table.rb
205
- - spec/support/factory_bot.rb
206
- - spec/support/migrate.rb
207
- - spec/support/models/article.rb
208
- - spec/support/models/author.rb
209
- - spec/support/models/category.rb
210
- - spec/support/models/comment.rb
211
- - spec/support/models/global.rb
212
- - spec/support/models/review.rb
213
- - spec/support/models/review_rating.rb
214
- - spec/support/models/toy.rb
215
- - spec/support/shared_context/with_database_records.rb
216
- - spec/support/shoulda.rb
217
202
  homepage: https://github.com/wbotelhos/rating
218
203
  licenses:
219
204
  - MIT
220
- metadata: {}
221
- post_install_message:
205
+ metadata:
206
+ rubygems_mfa_required: 'true'
207
+ post_install_message:
222
208
  rdoc_options: []
223
209
  require_paths:
224
210
  - lib
@@ -233,68 +219,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
219
  - !ruby/object:Gem::Version
234
220
  version: '0'
235
221
  requirements: []
236
- rubygems_version: 3.1.2
237
- signing_key:
222
+ rubygems_version: 3.3.12
223
+ signing_key:
238
224
  specification_version: 4
239
225
  summary: A true Bayesian rating system with scope and cache enabled.
240
- test_files:
241
- - spec/config/rate_table_spec.rb
242
- - spec/config/validations_spec.rb
243
- - spec/config/rating_table_spec.rb
244
- - spec/models/rate/rate_for_spec.rb
245
- - spec/models/rate/create_spec.rb
246
- - spec/models/rating/averager_data_spec.rb
247
- - spec/models/rating/data_spec.rb
248
- - spec/models/rating/update_rating_spec.rb
249
- - spec/models/rating/values_data_spec.rb
250
- - spec/models/extension/rated_records_spec.rb
251
- - spec/models/extension/rating_spec.rb
252
- - spec/models/extension/rated_question_spec.rb
253
- - spec/models/extension/rating_warm_up_spec.rb
254
- - spec/models/extension/order_by_rating_spec.rb
255
- - spec/models/extension/unscoped_rating_spec.rb
256
- - spec/models/extension/where_spec.rb
257
- - spec/models/extension/rate_spec.rb
258
- - spec/models/extension/rate_for_spec.rb
259
- - spec/models/extension/after_create_spec.rb
260
- - spec/models/extension/rates_spec.rb
261
- - spec/models/extension/rating_records_spec.rb
262
- - spec/models/extension/rated_spec.rb
263
- - spec/models/extension/rates_records_spec.rb
264
- - spec/models/rating_spec.rb
265
- - spec/models/rate_spec.rb
266
- - spec/support/migrate.rb
267
- - spec/support/shoulda.rb
268
- - spec/support/factory_bot.rb
269
- - spec/support/models/article.rb
270
- - spec/support/models/category.rb
271
- - spec/support/models/toy.rb
272
- - spec/support/models/author.rb
273
- - spec/support/models/review.rb
274
- - spec/support/models/comment.rb
275
- - spec/support/models/global.rb
276
- - spec/support/models/review_rating.rb
277
- - spec/support/common.rb
278
- - spec/support/db/migrate/create_categories_table.rb
279
- - spec/support/db/migrate/create_authors_table.rb
280
- - spec/support/db/migrate/create_review_ratings_table.rb
281
- - spec/support/db/migrate/create_articles_table.rb
282
- - spec/support/db/migrate/create_rating_table.rb
283
- - spec/support/db/migrate/create_toys_table.rb
284
- - spec/support/db/migrate/add_comment_on_rating_rates_table.rb
285
- - spec/support/db/migrate/add_extra_fields_on_rating_rates_table.rb
286
- - spec/support/db/migrate/create_reviews_table.rb
287
- - spec/support/db/migrate/create_comments_table.rb
288
- - spec/support/db/migrate/create_globals_table.rb
289
- - spec/support/db/migrate/create_rates_table.rb
290
- - spec/support/database_cleaner.rb
291
- - spec/support/shared_context/with_database_records.rb
292
- - spec/factories/article.rb
293
- - spec/factories/category.rb
294
- - spec/factories/rating/rate.rb
295
- - spec/factories/rating/rating.rb
296
- - spec/factories/toy.rb
297
- - spec/factories/author.rb
298
- - spec/factories/comment.rb
299
- - spec/factories/global.rb
300
- - spec/rails_helper.rb
226
+ test_files: []
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Config, '.rate_table' do
6
- if ENV['CONFIG_ENABLED'] != 'true'
7
- context 'when rating.yml does not exist' do
8
- it { expect(subject.rate_table).to eq 'rating_rates' }
9
- end
10
- end
11
-
12
- if ENV['CONFIG_ENABLED'] == 'true'
13
- context 'when rating.yml exists' do
14
- it { expect(subject.rate_table).to eq 'reviews' }
15
- end
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Config, '.rating_table' do
6
- if ENV['CONFIG_ENABLED'] != 'true'
7
- context 'when rating.yml does not exist' do
8
- it { expect(subject.rating_table).to eq 'rating_ratings' }
9
- end
10
- end
11
-
12
- if ENV['CONFIG_ENABLED'] == 'true'
13
- context 'when rating.yml exists' do
14
- it { expect(subject.rating_table).to eq 'review_ratings' }
15
- end
16
- end
17
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Config, '.validations' do
6
- if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] != 'true'
7
- context 'when rating.yml does not exist' do
8
- it do
9
- expect(subject.validations).to eq({
10
- rate: {
11
- case_sensitive: false,
12
- scope: %w[author_type resource_id resource_type scopeable_id scopeable_type],
13
- },
14
- }.deep_stringify_keys
15
- )
16
- end
17
- end
18
- end
19
-
20
- if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
21
- context 'when rating.yml exists' do
22
- it do
23
- expect(subject.validations).to eq({
24
- rate: {
25
- case_sensitive: false,
26
- scope: %w[author_type resource_id resource_type scopeable_id scopeable_type scope_1 scope_2],
27
- },
28
- }.deep_stringify_keys
29
- )
30
- end
31
- end
32
- end
33
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :article do
5
- sequence(:name) { |i| "Article #{i}" }
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :author do
5
- sequence(:name) { |i| "Author #{i}" }
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :category do
5
- sequence(:name) { |i| "Category #{i}" }
6
- end
7
- end
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :comment
5
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :global do
5
- end
6
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :rating_rate, class: Rating::Rate do
5
- value { 100 }
6
-
7
- author { create :author }
8
- resource { create :article }
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :rating_rating, class: Rating::Rating do
5
- average { 100 }
6
- estimate { 100 }
7
- sum { 100 }
8
- total { 1 }
9
-
10
- association :resource, factory: :article, strategy: :build
11
- end
12
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- FactoryBot.define do
4
- factory :toy do
5
- end
6
- end
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails_helper'
4
-
5
- RSpec.describe Rating::Extension, 'after_create' do
6
- context 'when record is author' do
7
- let!(:record) { build :author }
8
-
9
- it 'does not warm up the cache' do
10
- expect(record).not_to receive(:rating_warm_up)
11
-
12
- record.save
13
- end
14
- end
15
-
16
- context 'when record is not author' do
17
- context 'when record has scoping' do
18
- let!(:record) { build :article }
19
-
20
- it 'warms up the cache' do
21
- expect(record).to receive(:rating_warm_up).with(scoping: :categories)
22
-
23
- record.save
24
- end
25
- end
26
-
27
- context 'when record has no scoping' do
28
- let!(:record) { build :comment }
29
-
30
- it 'warms up the cache' do
31
- expect(record).to receive(:rating_warm_up).with(scoping: nil)
32
-
33
- record.save
34
- end
35
- end
36
-
37
- context 'when update is made' do
38
- let!(:record) { create :comment }
39
-
40
- it 'does not warm up the cache' do
41
- expect(record).not_to receive(:rating_warm_up)
42
-
43
- record.save
44
- end
45
- end
46
- end
47
- end