rating 0.3.0 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7828759c72eb95c9dc6562c8c56b2b42c2b266e6
4
- data.tar.gz: ad5a258d49d2bbf05f0d2fbc54800e590850d5a9
3
+ metadata.gz: ba499c445d9291907d676503a5e1a1ad2cb81672
4
+ data.tar.gz: e3f4479fbb330484091e31cc576bb373b877103f
5
5
  SHA512:
6
- metadata.gz: 880d5a7fe68b86e91d9b7eaf1c3f3ab3b7ef40eac8db2942daa8a7beca89e5887abbf92fbdc05b5bc751dd9ea292362bb5513c6adb43f74391a832027e5e15e4
7
- data.tar.gz: 94e6666f1174c77da6cd9db33fd2415aa4af621813689da0ff7c1f082c55b39015d2538add63cff10b4972a4a5797859f1b3c42d061d4611b1b14106d6b703fb
6
+ metadata.gz: 1e21b59e0a17407cb7d11c482d6114a0aa2823dcc7fa5f35ab72173d0dd7e23b1e315a923d4ca8bdc8cca235be77c32e50cabd3aa89753f9faed4fc5298e4043
7
+ data.tar.gz: 93ac02ecb7f4c1295f6c86e3483bfb80a4c7c8235fcd21e748c5a00c68f3c7db00c2443da7e8a2dc6aac8a578972f52c8641061cb877e7ad6cfe7438fbadd9bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v0.4.0
2
+
3
+ ### News
4
+
5
+ - Adds support to MySQL using decimal over float cast on calculations.
6
+
7
+ ### Updates
8
+
9
+ - Grows up the decimal precision to enable billion of records count.
10
+
1
11
  ## v0.3.0
2
12
 
3
13
  ### News
@@ -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: 17, scale: 14
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: 17, scale: 14
21
- t.decimal :estimate, default: 0, mull: false, precision: 17, scale: 14
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} / CAST(#{distinct_count} AS float)) count_avg,
29
- COALESCE(AVG(value), 0) rating_avg
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rating
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
@@ -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.3333333333333333
17
+ expect(result.as_json['count_avg'].to_s).to eq '1.333333333333333333'
18
18
  end
19
19
  end
20
20
 
@@ -22,7 +22,7 @@ RSpec.describe Rating::Rating, ':data' do
22
22
  end
23
23
 
24
24
  it 'returns the estimate for a resource' do
25
- expect(result[:estimate]).to eq 42.50000000000001
25
+ expect(result[:estimate].to_s).to eq '42.5000000000000000012000000505'
26
26
  end
27
27
  end
28
28
 
@@ -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.50000000000001
14
- expect(record.estimate).to eq 42.50000000000001
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
- ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
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.3.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-01 00:00:00.000000000 Z
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: pry-byebug
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: rspec-rails
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: rubocop-rspec
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: shoulda-matchers
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: sqlite3
118
+ name: shoulda-matchers
119
119
  requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ">="