rating 0.10.0 → 0.11.0
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/CHANGELOG.md +6 -0
- data/README.md +3 -2
- data/lib/rating/models/rating/rate.rb +1 -5
- data/lib/rating/version.rb +1 -1
- data/spec/models/extension/unscoped_rating_spec.rb +6 -5
- data/spec/models/rate/create_spec.rb +58 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3478dbe5fac4bb47db0a3b730f0b21d49747912056447d9de55d5ec82f6072ec
|
4
|
+
data.tar.gz: 3d95a77107c053347876554c1f36121a62b9342dd4b585833cd12b2f32aadd0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caabeb2c0336c22a86d95a064688424d242c96f84c8e28bd93883a2472f15a22d937ab726f060f765332bb8277f19ffb2fde571a2e7019b91e02c8aced96867d
|
7
|
+
data.tar.gz: 5acbf2bb5e2280de7507e9c23785ecc75e31b62a8c434a48972f50e78d09fa38a8e4280d4272c91bb3109994cdab217f5766a01d94c5a384d9990aa080c18e06
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -390,7 +390,7 @@ rating:
|
|
390
390
|
|
391
391
|
### Unscoped Rating
|
392
392
|
|
393
|
-
All rating values are grouped by
|
393
|
+
All rating values are grouped by its own scope, but you can disable it and group all of them together.
|
394
394
|
|
395
395
|
```ruby
|
396
396
|
rating unscoped_rating: true
|
@@ -404,7 +404,8 @@ author.rate resource, 2, scope: scope
|
|
404
404
|
author.rate resource, 3
|
405
405
|
```
|
406
406
|
|
407
|
-
Now the `sum` will be `6` and the `total` will be `3` because all rating will be calculated into just one rating record ignoring the `scopeable` object.
|
407
|
+
Now the `sum` will be `6` and the `total` will be `3` because all rating will be calculated into just one rating record ignoring the `scopeable` object.
|
408
|
+
The rating record is *always* saved on the record with `scopeable` as `nil`.
|
408
409
|
|
409
410
|
### where
|
410
411
|
|
@@ -23,8 +23,6 @@ module Rating
|
|
23
23
|
attributes = { author: author, resource: resource, scopeable: scopeable }.merge(extra_scopes)
|
24
24
|
record = find_or_initialize_by(attributes)
|
25
25
|
|
26
|
-
return record if record.persisted? && value == record.value
|
27
|
-
|
28
26
|
metadata.each { |k, v| record[k] = v } if metadata.present?
|
29
27
|
|
30
28
|
record.value = value
|
@@ -34,9 +32,7 @@ module Rating
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def self.rate_for(author:, extra_scopes: {}, resource:, scopeable: nil)
|
37
|
-
|
38
|
-
|
39
|
-
find_by attributes
|
35
|
+
find_by extra_scopes.merge(author: author, resource: resource, scopeable: scopeable)
|
40
36
|
end
|
41
37
|
|
42
38
|
private
|
data/lib/rating/version.rb
CHANGED
@@ -5,6 +5,7 @@ require 'rails_helper'
|
|
5
5
|
RSpec.describe Rating::Extension, 'unscoped_rating' do
|
6
6
|
let!(:author_1) { create :author }
|
7
7
|
let!(:author_2) { create :author }
|
8
|
+
let!(:author_3) { create :author }
|
8
9
|
let!(:scope) { create :category }
|
9
10
|
|
10
11
|
context 'when is false' do
|
@@ -13,7 +14,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
|
|
13
14
|
it 'groups in different line record' do
|
14
15
|
author_1.rate resource, 1, scope: scope
|
15
16
|
author_2.rate resource, 2, scope: scope
|
16
|
-
|
17
|
+
author_2.rate resource, 5
|
17
18
|
|
18
19
|
ratings = Rating::Rating.all.order('id')
|
19
20
|
|
@@ -45,7 +46,7 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
|
|
45
46
|
it 'groups in the same line record' do
|
46
47
|
author_1.rate resource, 1, scope: scope
|
47
48
|
author_2.rate resource, 2, scope: scope
|
48
|
-
|
49
|
+
author_2.rate resource, 5
|
49
50
|
|
50
51
|
ratings = Rating::Rating.all.order('id')
|
51
52
|
|
@@ -62,15 +63,15 @@ RSpec.describe Rating::Extension, 'unscoped_rating' do
|
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
context 'when is true and have a non
|
66
|
+
context 'when is true and have a non scoped record first on database' do
|
66
67
|
let!(:resource) { create :global }
|
67
68
|
|
68
69
|
before { ::Rating::Rating.create resource: resource, scopeable: scope }
|
69
70
|
|
70
|
-
it '
|
71
|
+
it 'sets the result on record with no scope' do
|
71
72
|
author_1.rate resource, 1, scope: scope
|
72
73
|
author_2.rate resource, 2, scope: scope
|
73
|
-
|
74
|
+
author_3.rate resource, 5
|
74
75
|
|
75
76
|
ratings = Rating::Rating.all.order('id')
|
76
77
|
|
@@ -192,6 +192,64 @@ RSpec.describe Rating::Rate, ':create' do
|
|
192
192
|
expect(rate.value).to eq 3
|
193
193
|
end
|
194
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
|
195
253
|
end
|
196
254
|
|
197
255
|
if ENV['CONFIG_ENABLED_WITH_EXTRA_SCOPES'] == 'true'
|
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.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Washington Botelho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
233
|
- !ruby/object:Gem::Version
|
234
234
|
version: '0'
|
235
235
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
236
|
+
rubygems_version: 3.1.2
|
237
237
|
signing_key:
|
238
238
|
specification_version: 4
|
239
239
|
summary: A true Bayesian rating system with scope and cache enabled.
|