rating 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +28 -2
- data/lib/generators/rating/install_generator.rb +9 -4
- data/lib/generators/rating/templates/db/migrate/create_rate_table.rb +19 -0
- data/lib/generators/rating/templates/db/migrate/{create_rating_tables.rb → create_rating_table.rb} +1 -15
- data/lib/rating.rb +1 -0
- data/lib/rating/config.rb +25 -0
- data/lib/rating/models/rating/extension.rb +14 -2
- data/lib/rating/models/rating/rate.rb +2 -1
- data/lib/rating/models/rating/rating.rb +3 -2
- data/lib/rating/version.rb +1 -1
- data/spec/config/rate_table_spec.rb +13 -0
- data/spec/config/rating_table_spec.rb +13 -0
- data/spec/factories/comment.rb +5 -0
- data/spec/models/extension/after_create_spec.rb +36 -17
- data/spec/models/extension/rating_warm_up_spec.rb +115 -0
- data/spec/models/rating/update_rating_spec.rb +20 -2
- data/spec/support/db/migrate/add_comment_on_rating_rates_table.rb +1 -0
- data/spec/support/db/migrate/create_categories_table.rb +2 -0
- data/spec/support/db/migrate/create_comments_table.rb +7 -0
- data/spec/support/db/migrate/create_review_ratings_table.rb +17 -0
- data/spec/support/db/migrate/create_reviews_table.rb +15 -0
- data/spec/support/migrate.rb +7 -2
- data/spec/support/models/article.rb +3 -1
- data/spec/support/models/category.rb +1 -0
- data/spec/support/models/comment.rb +5 -0
- data/spec/support/models/review.rb +5 -0
- data/spec/support/models/review_rating.rb +4 -0
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 870497d9efe65b495fb63f0205c701da2ec6a754
|
4
|
+
data.tar.gz: e9d022d3c26ee5876c5bad1bf93ca0f80a98d5c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fba27be52abc6695936928d7ecdb076e0d733cfd9757c8f8f35a1d4853c00606f6878944f5cee6d3f6eab918888f5b2c9cf7a7a033cfce73246ef9b83c599513
|
7
|
+
data.tar.gz: f46c512cac625b12fc7f66c4d00993ece9f91427901af861843fc96a0656b12f979c2e5f95f0b42fecf01877144622f98e2050addd472162096dc565294422a5
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## v0.5.0
|
2
|
+
|
3
|
+
### News
|
4
|
+
|
5
|
+
- Adds `rating.yml` config to support to change the tables where Rating will write the data;
|
6
|
+
- Adds `scoping` option to support to generates zero based rating via scope.
|
7
|
+
|
8
|
+
### Updates
|
9
|
+
|
10
|
+
- The migrate was separated in two to improve in troubleshoot. (iondrimba)
|
11
|
+
|
1
12
|
## v0.4.0
|
2
13
|
|
3
14
|
### News
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/wbotelhos/rating.svg)](https://travis-ci.org/wbotelhos/rating)
|
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
|
-
[![
|
6
|
+
[![Patreon](https://img.shields.io/badge/donate-%3C3-brightgreen.svg)](https://www.patreon.com/wbotelhos)
|
7
7
|
|
8
8
|
A true Bayesian rating system with scope and cache enabled.
|
9
9
|
|
@@ -321,6 +321,32 @@ rate.fingerprint # <Fingerprint id:...>
|
|
321
321
|
rate.value # 3
|
322
322
|
```
|
323
323
|
|
324
|
+
### Scoping
|
325
|
+
|
326
|
+
If you need to warm up a record with scope, you need to setup the `scoping` relation.
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
class Resource < ApplicationRecord
|
330
|
+
voting scoping: :categories
|
331
|
+
end
|
332
|
+
```
|
333
|
+
|
334
|
+
Now, when a resource is created, the cache will be generated for each related `category` as `scopeable`.
|
335
|
+
|
336
|
+
### Table Name
|
337
|
+
|
338
|
+
You can choose the table where Rating will write the data via YAML config.
|
339
|
+
You should just to provide a `config/rating.yml` file with the following content:
|
340
|
+
|
341
|
+
```yml
|
342
|
+
rating:
|
343
|
+
rate_table: 'reviews'
|
344
|
+
rating_table: 'review_ratings'
|
345
|
+
```
|
346
|
+
|
347
|
+
Now the rates will be written on `reviews` table over `rating_rates` and calculation will be on `review_ratings` over `rating_ratings`.
|
348
|
+
You can change one table o both of them.
|
349
|
+
|
324
350
|
## Love it!
|
325
351
|
|
326
|
-
Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=rating) or [
|
352
|
+
Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=rating) or [Patreon](https://www.patreon.com/wbotelhos). Thanks! (:
|
@@ -4,16 +4,21 @@ module Rating
|
|
4
4
|
class InstallGenerator < Rails::Generators::Base
|
5
5
|
source_root File.expand_path('../templates', __FILE__)
|
6
6
|
|
7
|
-
desc '
|
7
|
+
desc 'Creates Rating migration'
|
8
8
|
|
9
9
|
def create_migration
|
10
|
-
template 'db/migrate/
|
10
|
+
template 'db/migrate/create_rating_table.rb', "db/migrate/#{timestamp(0)}_create_rating_table.rb"
|
11
|
+
template 'db/migrate/create_rate_table.rb', "db/migrate/#{timestamp(1)}_create_rate_table.rb"
|
11
12
|
end
|
12
13
|
|
13
14
|
private
|
14
15
|
|
15
|
-
def
|
16
|
-
Time.current
|
16
|
+
def time
|
17
|
+
@time ||= Time.current
|
18
|
+
end
|
19
|
+
|
20
|
+
def timestamp(seconds)
|
21
|
+
(time + seconds.seconds).strftime '%Y%m%d%H%M%S'
|
17
22
|
end
|
18
23
|
end
|
19
24
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateRateTable < ActiveRecord::Migration[5.0]
|
4
|
+
def change
|
5
|
+
create_table :rating_rates do |t|
|
6
|
+
t.decimal :value, default: 0, precision: 25, scale: 16
|
7
|
+
|
8
|
+
t.references :author, index: true, null: false, polymorphic: true
|
9
|
+
t.references :resource, index: true, null: false, polymorphic: true
|
10
|
+
t.references :scopeable, index: true, null: true, polymorphic: true
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
|
15
|
+
add_index :rating_rates, %i[author_id author_type resource_id resource_type scopeable_id scopeable_type],
|
16
|
+
name: :index_rating_rates_on_author_and_resource_and_scopeable,
|
17
|
+
unique: true
|
18
|
+
end
|
19
|
+
end
|
data/lib/generators/rating/templates/db/migrate/{create_rating_tables.rb → create_rating_table.rb}
RENAMED
@@ -1,21 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class CreateRatingTable < ActiveRecord::Migration[5.0]
|
4
4
|
def change
|
5
|
-
create_table :rating_rates do |t|
|
6
|
-
t.decimal :value, default: 0, precision: 25, scale: 16
|
7
|
-
|
8
|
-
t.references :author, index: true, null: false, polymorphic: true
|
9
|
-
t.references :resource, index: true, null: false, polymorphic: true
|
10
|
-
t.references :scopeable, index: true, null: true, polymorphic: true
|
11
|
-
|
12
|
-
t.timestamps null: false
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :rating_rates, %i[author_id author_type resource_id resource_type scopeable_id scopeable_type],
|
16
|
-
name: :index_rating_rates_on_author_and_resource_and_scopeable,
|
17
|
-
unique: true
|
18
|
-
|
19
5
|
create_table :rating_ratings do |t|
|
20
6
|
t.decimal :average, default: 0, mull: false, precision: 25, scale: 16
|
21
7
|
t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16
|
data/lib/rating.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rating
|
4
|
+
module Config
|
5
|
+
module_function
|
6
|
+
|
7
|
+
def config
|
8
|
+
@config ||= begin
|
9
|
+
file_path = File.expand_path('config/rating.yml')
|
10
|
+
|
11
|
+
return {} unless File.exist?(file_path)
|
12
|
+
|
13
|
+
YAML.safe_load(File.read(file_path))['rating']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def rate_table
|
18
|
+
@rate_table ||= config[__method__.to_s] || 'rating_rates'
|
19
|
+
end
|
20
|
+
|
21
|
+
def rating_table
|
22
|
+
@rating_table ||= config[__method__.to_s] || 'rating_ratings'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -28,11 +28,23 @@ module Rating
|
|
28
28
|
def rating(scope: nil)
|
29
29
|
rating_records.find_by scopeable: scope
|
30
30
|
end
|
31
|
+
|
32
|
+
def rating_warm_up(scoping: nil)
|
33
|
+
return Rating.find_or_create_by(resource: self) if scoping.blank?
|
34
|
+
|
35
|
+
[scoping].flatten.compact.map do |attribute|
|
36
|
+
next unless respond_to?(attribute)
|
37
|
+
|
38
|
+
[public_send(attribute)].flatten.compact.map do |object|
|
39
|
+
Rating.find_or_create_by! resource: self, scopeable: object
|
40
|
+
end
|
41
|
+
end.flatten.compact
|
42
|
+
end
|
31
43
|
end
|
32
44
|
|
33
45
|
module ClassMethods
|
34
|
-
def rating(as: nil)
|
35
|
-
after_create -> {
|
46
|
+
def rating(as: nil, scoping: nil)
|
47
|
+
after_create -> { rating_warm_up scoping: scoping }, unless: -> { as == :author }
|
36
48
|
|
37
49
|
has_many :rating_records,
|
38
50
|
as: :resource,
|
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
module Rating
|
4
4
|
class Rating < ActiveRecord::Base
|
5
|
-
self.
|
5
|
+
self.table_name_prefix = 'rating_'
|
6
|
+
self.table_name = ::Rating::Config.rating_table
|
6
7
|
|
7
8
|
belongs_to :resource, polymorphic: true
|
8
9
|
belongs_to :scopeable, polymorphic: true
|
@@ -100,7 +101,7 @@ module Rating
|
|
100
101
|
count = distinct ? 'COUNT(DISTINCT resource_id)' : 'COUNT(1)'
|
101
102
|
|
102
103
|
%((
|
103
|
-
SELECT #{count}
|
104
|
+
SELECT GREATEST(#{count}, 1)
|
104
105
|
FROM #{rate_table_name}
|
105
106
|
WHERE resource_type = :resource_type AND #{scope_type_query(scopeable)}
|
106
107
|
))
|
data/lib/rating/version.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe Rating::Config, '.rate_table' do
|
6
|
+
context 'when rating.yml does not exist' do
|
7
|
+
it { expect(subject.rate_table).to eq 'rating_rates' }
|
8
|
+
end if ENV['CONFIG_ENABLED'] != 'true'
|
9
|
+
|
10
|
+
context 'when rating.yml exists' do
|
11
|
+
it { expect(subject.rate_table).to eq 'reviews' }
|
12
|
+
end if ENV['CONFIG_ENABLED'] == 'true'
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe Rating::Config, '.rating_table' do
|
6
|
+
context 'when rating.yml does not exist' do
|
7
|
+
it { expect(subject.rating_table).to eq 'rating_ratings' }
|
8
|
+
end if ENV['CONFIG_ENABLED'] != 'true'
|
9
|
+
|
10
|
+
context 'when rating.yml exists' do
|
11
|
+
it { expect(subject.rating_table).to eq 'review_ratings' }
|
12
|
+
end if ENV['CONFIG_ENABLED'] == 'true'
|
13
|
+
end
|
@@ -2,27 +2,46 @@
|
|
2
2
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
|
-
RSpec.describe Rating::Extension, '
|
6
|
-
context 'when
|
7
|
-
let!(:
|
8
|
-
|
9
|
-
it '
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
expect(rating.estimate).to eq 0
|
14
|
-
expect(rating.resource).to eq article
|
15
|
-
expect(rating.scopeable).to eq nil
|
16
|
-
expect(rating.sum).to eq 0
|
17
|
-
expect(rating.total).to eq 0
|
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
|
18
13
|
end
|
19
14
|
end
|
20
15
|
|
21
|
-
context 'when
|
22
|
-
|
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)
|
23
42
|
|
24
|
-
|
25
|
-
|
43
|
+
record.save
|
44
|
+
end
|
26
45
|
end
|
27
46
|
end
|
28
47
|
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
RSpec.describe Rating::Extension, '.rating_warm_up' do
|
6
|
+
context 'when scoping is nil' do
|
7
|
+
context 'when update is made' do
|
8
|
+
let!(:record) { create :comment }
|
9
|
+
let!(:rating) { ::Rating::Rating.find_by resource: record }
|
10
|
+
|
11
|
+
it 'creates the cache' do
|
12
|
+
record.rating_warm_up scoping: nil
|
13
|
+
|
14
|
+
expect(::Rating::Rating.all).to eq [rating]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns the cached object' do
|
18
|
+
expect(record.rating_warm_up).to eq rating
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when record does not exist' do
|
23
|
+
let!(:record) { create :comment }
|
24
|
+
|
25
|
+
before { ::Rating::Rating.destroy_all }
|
26
|
+
|
27
|
+
it 'creates the cache' do
|
28
|
+
record.rating_warm_up scoping: nil
|
29
|
+
|
30
|
+
expect(::Rating::Rating.all.map(&:resource)).to eq [record]
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the cached object' do
|
34
|
+
expect(record.rating_warm_up).to eq ::Rating::Rating.last
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when scoping is not nil' do
|
40
|
+
context 'when update is made' do
|
41
|
+
let!(:category_1) { create :category }
|
42
|
+
let!(:category_2) { create :category }
|
43
|
+
let!(:record) { create :article, categories: [category_1, category_2] }
|
44
|
+
|
45
|
+
it 'creates the cache' do
|
46
|
+
record.rating_warm_up scoping: :categories
|
47
|
+
|
48
|
+
ratings = ::Rating::Rating.all
|
49
|
+
|
50
|
+
expect(ratings.map(&:scopeable)).to match_array [category_1, category_2]
|
51
|
+
expect(ratings.map(&:resource)).to match_array [record, record]
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns the cached objects' do
|
55
|
+
expect(record.rating_warm_up(scoping: :categories)).to eq ::Rating::Rating.all
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when record does not exist' do
|
60
|
+
let!(:category_1) { create :category }
|
61
|
+
let!(:category_2) { create :category }
|
62
|
+
let!(:record) { create :article, categories: [category_1, category_2] }
|
63
|
+
|
64
|
+
before { ::Rating::Rating.destroy_all }
|
65
|
+
|
66
|
+
it 'creates the cache' do
|
67
|
+
record.rating_warm_up scoping: :categories
|
68
|
+
|
69
|
+
ratings = ::Rating::Rating.all
|
70
|
+
|
71
|
+
expect(ratings.map(&:scopeable)).to match_array [category_1, category_2]
|
72
|
+
expect(ratings.map(&:resource)).to match_array [record, record]
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns the cached objects' do
|
76
|
+
expect(record.rating_warm_up(scoping: :categories)).to eq ::Rating::Rating.all
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'when a non existent scoping is given' do
|
81
|
+
let!(:record) { create :article }
|
82
|
+
|
83
|
+
it 'returns an empty array' do
|
84
|
+
expect(record.rating_warm_up(scoping: :missing)).to eq []
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when scoping is given inside array' do
|
89
|
+
let!(:category) { create :category }
|
90
|
+
let!(:record) { create :article, categories: [category] }
|
91
|
+
|
92
|
+
it 'returns the cache' do
|
93
|
+
expect(record.rating_warm_up(scoping: [:categories])).to eq ::Rating::Rating.all
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when scoping is given inside multiple arrays' do
|
98
|
+
let!(:category) { create :category }
|
99
|
+
let!(:record) { create :article, categories: [category] }
|
100
|
+
|
101
|
+
it 'returns the cache' do
|
102
|
+
expect(record.rating_warm_up(scoping: [[:categories]])).to eq ::Rating::Rating.all
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when scoping is given with nil value together' do
|
107
|
+
let!(:category) { create :category }
|
108
|
+
let!(:record) { create :article, categories: [category] }
|
109
|
+
|
110
|
+
it 'returns the cache' do
|
111
|
+
expect(record.rating_warm_up(scoping: [[:categories, nil], nil])).to eq ::Rating::Rating.all
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -4,9 +4,9 @@ require 'rails_helper'
|
|
4
4
|
require 'support/shared_context/with_database_records'
|
5
5
|
|
6
6
|
RSpec.describe Rating::Rating, ':update_rating' do
|
7
|
-
include_context 'with_database_records'
|
8
|
-
|
9
7
|
context 'with no scopeable' do
|
8
|
+
include_context 'with_database_records'
|
9
|
+
|
10
10
|
it 'updates the rating data of the given resource' do
|
11
11
|
record = described_class.find_by(resource: article_1)
|
12
12
|
|
@@ -18,6 +18,8 @@ RSpec.describe Rating::Rating, ':update_rating' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
context 'with scopeable' do
|
21
|
+
include_context 'with_database_records'
|
22
|
+
|
21
23
|
it 'updates the rating data of the given resource respecting the scope' do
|
22
24
|
record = described_class.find_by(resource: article_1, scopeable: category)
|
23
25
|
|
@@ -27,4 +29,20 @@ RSpec.describe Rating::Rating, ':update_rating' do
|
|
27
29
|
expect(record.total).to eq 2
|
28
30
|
end
|
29
31
|
end
|
32
|
+
|
33
|
+
context 'when rate table has no record' do
|
34
|
+
let!(:resource) { create :article }
|
35
|
+
let!(:scope) { nil }
|
36
|
+
|
37
|
+
it 'calculates with counts values as zero' do
|
38
|
+
described_class.update_rating resource, scope
|
39
|
+
|
40
|
+
record = described_class.last
|
41
|
+
|
42
|
+
expect(record.average).to eq 0
|
43
|
+
expect(record.estimate).to eq 0
|
44
|
+
expect(record.sum).to eq 0
|
45
|
+
expect(record.total).to eq 0
|
46
|
+
end
|
47
|
+
end
|
30
48
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateReviewRatingsTable < ActiveRecord::Migration[5.0]
|
4
|
+
def change
|
5
|
+
create_table :review_ratings do |t|
|
6
|
+
t.decimal :average, default: 0, mull: false, precision: 25, scale: 16
|
7
|
+
t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16
|
8
|
+
t.integer :sum, default: 0, mull: false
|
9
|
+
t.integer :total, default: 0, mull: false
|
10
|
+
|
11
|
+
t.references :resource, index: true, null: false, polymorphic: true
|
12
|
+
t.references :scopeable, index: true, null: true, polymorphic: true
|
13
|
+
|
14
|
+
t.timestamps null: false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CreateReviewsTable < ActiveRecord::Migration[5.0]
|
4
|
+
def change
|
5
|
+
create_table :reviews do |t|
|
6
|
+
t.decimal :value, default: 0, precision: 25, scale: 16
|
7
|
+
|
8
|
+
t.references :author, index: true, null: false, polymorphic: true
|
9
|
+
t.references :resource, index: true, null: false, polymorphic: true
|
10
|
+
t.references :scopeable, index: true, null: true, polymorphic: true
|
11
|
+
|
12
|
+
t.timestamps null: false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/support/migrate.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path('../../lib/generators/rating/templates/db/migrate/
|
3
|
+
require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rating_table.rb', __dir__)
|
4
|
+
require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rate_table.rb', __dir__)
|
4
5
|
|
5
6
|
Dir[File.expand_path('db/migrate/*.rb', __dir__)].each { |file| require file }
|
6
7
|
|
7
8
|
CreateArticlesTable.new.change
|
8
9
|
CreateAuthorsTable.new.change
|
9
10
|
CreateCategoriesTable.new.change
|
10
|
-
|
11
|
+
CreateCommentsTable.new.change
|
12
|
+
CreateRateTable.new.change
|
13
|
+
CreateRatingTable.new.change
|
14
|
+
CreateReviewRatingsTable.new.change
|
15
|
+
CreateReviewsTable.new.change
|
11
16
|
AddCommentOnRatingRatesTable.new.change
|
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.5.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: 2018-02-
|
11
|
+
date: 2018-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -138,15 +138,20 @@ files:
|
|
138
138
|
- LICENSE
|
139
139
|
- README.md
|
140
140
|
- lib/generators/rating/install_generator.rb
|
141
|
-
- lib/generators/rating/templates/db/migrate/
|
141
|
+
- lib/generators/rating/templates/db/migrate/create_rate_table.rb
|
142
|
+
- lib/generators/rating/templates/db/migrate/create_rating_table.rb
|
142
143
|
- lib/rating.rb
|
144
|
+
- lib/rating/config.rb
|
143
145
|
- lib/rating/models/rating/extension.rb
|
144
146
|
- lib/rating/models/rating/rate.rb
|
145
147
|
- lib/rating/models/rating/rating.rb
|
146
148
|
- lib/rating/version.rb
|
149
|
+
- spec/config/rate_table_spec.rb
|
150
|
+
- spec/config/rating_table_spec.rb
|
147
151
|
- spec/factories/article.rb
|
148
152
|
- spec/factories/author.rb
|
149
153
|
- spec/factories/category.rb
|
154
|
+
- spec/factories/comment.rb
|
150
155
|
- spec/factories/rating/rate.rb
|
151
156
|
- spec/factories/rating/rating.rb
|
152
157
|
- spec/models/extension/after_create_spec.rb
|
@@ -160,6 +165,7 @@ files:
|
|
160
165
|
- spec/models/extension/rates_spec.rb
|
161
166
|
- spec/models/extension/rating_records_spec.rb
|
162
167
|
- spec/models/extension/rating_spec.rb
|
168
|
+
- spec/models/extension/rating_warm_up_spec.rb
|
163
169
|
- spec/models/rate/create_spec.rb
|
164
170
|
- spec/models/rate/rate_for_spec.rb
|
165
171
|
- spec/models/rate_spec.rb
|
@@ -175,11 +181,17 @@ files:
|
|
175
181
|
- spec/support/db/migrate/create_articles_table.rb
|
176
182
|
- spec/support/db/migrate/create_authors_table.rb
|
177
183
|
- spec/support/db/migrate/create_categories_table.rb
|
184
|
+
- spec/support/db/migrate/create_comments_table.rb
|
185
|
+
- spec/support/db/migrate/create_review_ratings_table.rb
|
186
|
+
- spec/support/db/migrate/create_reviews_table.rb
|
178
187
|
- spec/support/factory_bot.rb
|
179
188
|
- spec/support/migrate.rb
|
180
189
|
- spec/support/models/article.rb
|
181
190
|
- spec/support/models/author.rb
|
182
191
|
- spec/support/models/category.rb
|
192
|
+
- spec/support/models/comment.rb
|
193
|
+
- spec/support/models/review.rb
|
194
|
+
- spec/support/models/review_rating.rb
|
183
195
|
- spec/support/shared_context/with_database_records.rb
|
184
196
|
- spec/support/shoulda.rb
|
185
197
|
homepage: https://github.com/wbotelhos/rating
|
@@ -207,6 +219,8 @@ signing_key:
|
|
207
219
|
specification_version: 4
|
208
220
|
summary: A true Bayesian rating system with scope and cache enabled.
|
209
221
|
test_files:
|
222
|
+
- spec/config/rate_table_spec.rb
|
223
|
+
- spec/config/rating_table_spec.rb
|
210
224
|
- spec/models/rate/rate_for_spec.rb
|
211
225
|
- spec/models/rate/create_spec.rb
|
212
226
|
- spec/models/rating/averager_data_spec.rb
|
@@ -216,6 +230,7 @@ test_files:
|
|
216
230
|
- spec/models/extension/rated_records_spec.rb
|
217
231
|
- spec/models/extension/rating_spec.rb
|
218
232
|
- spec/models/extension/rated_question_spec.rb
|
233
|
+
- spec/models/extension/rating_warm_up_spec.rb
|
219
234
|
- spec/models/extension/order_by_rating_spec.rb
|
220
235
|
- spec/models/extension/rate_spec.rb
|
221
236
|
- spec/models/extension/rate_for_spec.rb
|
@@ -232,11 +247,17 @@ test_files:
|
|
232
247
|
- spec/support/models/article.rb
|
233
248
|
- spec/support/models/category.rb
|
234
249
|
- spec/support/models/author.rb
|
250
|
+
- spec/support/models/review.rb
|
251
|
+
- spec/support/models/comment.rb
|
252
|
+
- spec/support/models/review_rating.rb
|
235
253
|
- spec/support/common.rb
|
236
254
|
- spec/support/db/migrate/create_categories_table.rb
|
237
255
|
- spec/support/db/migrate/create_authors_table.rb
|
256
|
+
- spec/support/db/migrate/create_review_ratings_table.rb
|
238
257
|
- spec/support/db/migrate/create_articles_table.rb
|
239
258
|
- spec/support/db/migrate/add_comment_on_rating_rates_table.rb
|
259
|
+
- spec/support/db/migrate/create_reviews_table.rb
|
260
|
+
- spec/support/db/migrate/create_comments_table.rb
|
240
261
|
- spec/support/database_cleaner.rb
|
241
262
|
- spec/support/shared_context/with_database_records.rb
|
242
263
|
- spec/factories/article.rb
|
@@ -244,4 +265,5 @@ test_files:
|
|
244
265
|
- spec/factories/rating/rate.rb
|
245
266
|
- spec/factories/rating/rating.rb
|
246
267
|
- spec/factories/author.rb
|
268
|
+
- spec/factories/comment.rb
|
247
269
|
- spec/rails_helper.rb
|