rating 0.3.0 → 0.4.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 +10 -0
- data/lib/generators/rating/templates/db/migrate/create_rating_tables.rb +3 -3
- data/lib/rating/models/rating/rating.rb +2 -2
- data/lib/rating/version.rb +1 -1
- data/spec/models/rating/averager_data_spec.rb +1 -1
- data/spec/models/rating/data_spec.rb +1 -1
- data/spec/models/rating/update_rating_spec.rb +2 -2
- data/spec/rails_helper.rb +7 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba499c445d9291907d676503a5e1a1ad2cb81672
|
4
|
+
data.tar.gz: e3f4479fbb330484091e31cc576bb373b877103f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e21b59e0a17407cb7d11c482d6114a0aa2823dcc7fa5f35ab72173d0dd7e23b1e315a923d4ca8bdc8cca235be77c32e50cabd3aa89753f9faed4fc5298e4043
|
7
|
+
data.tar.gz: 93ac02ecb7f4c1295f6c86e3483bfb80a4c7c8235fcd21e748c5a00c68f3c7db00c2443da7e8a2dc6aac8a578972f52c8641061cb877e7ad6cfe7438fbadd9bd
|
data/CHANGELOG.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
class CreateRatingTables < ActiveRecord::Migration[5.0]
|
4
4
|
def change
|
5
5
|
create_table :rating_rates do |t|
|
6
|
-
t.decimal :value, default: 0, precision:
|
6
|
+
t.decimal :value, default: 0, precision: 25, scale: 16
|
7
7
|
|
8
8
|
t.references :author, index: true, null: false, polymorphic: true
|
9
9
|
t.references :resource, index: true, null: false, polymorphic: true
|
@@ -17,8 +17,8 @@ class CreateRatingTables < ActiveRecord::Migration[5.0]
|
|
17
17
|
unique: true
|
18
18
|
|
19
19
|
create_table :rating_ratings do |t|
|
20
|
-
t.decimal :average, default: 0, mull: false, precision:
|
21
|
-
t.decimal :estimate, default: 0, mull: false, precision:
|
20
|
+
t.decimal :average, default: 0, mull: false, precision: 25, scale: 16
|
21
|
+
t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16
|
22
22
|
t.integer :sum, default: 0, mull: false
|
23
23
|
t.integer :total, default: 0, mull: false
|
24
24
|
|
@@ -25,8 +25,8 @@ module Rating
|
|
25
25
|
|
26
26
|
sql = %(
|
27
27
|
SELECT
|
28
|
-
(#{total_count} /
|
29
|
-
COALESCE(AVG(value), 0)
|
28
|
+
(CAST(#{total_count} AS DECIMAL(17, 14)) / #{distinct_count}) count_avg,
|
29
|
+
COALESCE(AVG(value), 0) rating_avg
|
30
30
|
FROM #{rate_table_name}
|
31
31
|
WHERE resource_type = :resource_type AND #{scope_type_query(scopeable)}
|
32
32
|
).squish
|
data/lib/rating/version.rb
CHANGED
@@ -14,7 +14,7 @@ RSpec.describe Rating::Rating, ':averager_data' do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'returns the average of number of records for the given resource type' do
|
17
|
-
expect(result.as_json['count_avg']).to eq 1.
|
17
|
+
expect(result.as_json['count_avg'].to_s).to eq '1.333333333333333333'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -10,8 +10,8 @@ RSpec.describe Rating::Rating, ':update_rating' do
|
|
10
10
|
it 'updates the rating data of the given resource' do
|
11
11
|
record = described_class.find_by(resource: article_1)
|
12
12
|
|
13
|
-
expect(record.average).to eq 50.
|
14
|
-
expect(record.estimate).to eq 42.
|
13
|
+
expect(record.average).to eq 50.5
|
14
|
+
expect(record.estimate).to eq 42.5
|
15
15
|
expect(record.sum).to eq 101
|
16
16
|
expect(record.total).to eq 2
|
17
17
|
end
|
data/spec/rails_helper.rb
CHANGED
@@ -3,9 +3,15 @@
|
|
3
3
|
ENV['RAILS_ENV'] ||= 'test'
|
4
4
|
|
5
5
|
require 'active_record/railtie'
|
6
|
+
require 'mysql2'
|
6
7
|
require 'pry-byebug'
|
7
8
|
require 'rating'
|
8
9
|
|
9
|
-
|
10
|
+
client = Mysql2::Client.new(host: :localhost, username: :root)
|
11
|
+
|
12
|
+
client.query 'DROP DATABASE IF EXISTS rating_test;'
|
13
|
+
client.query 'CREATE DATABASE IF NOT EXISTS rating_test;'
|
14
|
+
|
15
|
+
ActiveRecord::Base.establish_connection adapter: :mysql2, database: :rating_test, username: :root
|
10
16
|
|
11
17
|
Dir[File.expand_path('support/**/*.rb', __dir__)].each { |file| require file }
|
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.4.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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -59,7 +59,7 @@ dependencies:
|
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
62
|
+
name: mysql2
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - ">="
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: pry-byebug
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: rspec-rails
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
@@ -101,7 +101,7 @@ dependencies:
|
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: rubocop-rspec
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - ">="
|
@@ -115,7 +115,7 @@ dependencies:
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
118
|
+
name: shoulda-matchers
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - ">="
|