From 90dc76e4d9f1827b205097f582f90a8de0eeb972 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Wed, 18 May 2022 09:54:53 -0300 Subject: [PATCH] spec: using the correct types --- spec/models/rating/averager_data_spec.rb | 2 +- spec/models/rating/data_spec.rb | 2 +- spec/models/rating/update_rating_spec.rb | 30 ++++++++++++------------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/models/rating/averager_data_spec.rb b/spec/models/rating/averager_data_spec.rb index a6a95e5..a962769 100644 --- a/spec/models/rating/averager_data_spec.rb +++ b/spec/models/rating/averager_data_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Rating::Rating, ':averager_data' do end it 'returns the average of number of records for the given resource type' do - expect(result.as_json['count_avg'].to_s).to eq '1.333333333333333333' + expect(result.count_avg).to eq(BigDecimal('1.333333333333333333')) end end diff --git a/spec/models/rating/data_spec.rb b/spec/models/rating/data_spec.rb index f3726c8..d870424 100644 --- a/spec/models/rating/data_spec.rb +++ b/spec/models/rating/data_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Rating::Rating, ':data' do end it 'returns the estimate for a resource' do - expect(result[:estimate].to_s).to eq '42.5000000000000000012000000505' + expect(result[:estimate]).to eq(BigDecimal('42.5000000000000000012000000505')) end end diff --git a/spec/models/rating/update_rating_spec.rb b/spec/models/rating/update_rating_spec.rb index 8c3bb25..319f3f1 100644 --- a/spec/models/rating/update_rating_spec.rb +++ b/spec/models/rating/update_rating_spec.rb @@ -9,10 +9,10 @@ RSpec.describe Rating::Rating, ':update_rating' do it 'updates the rating data of the given resource' do record = described_class.find_by(resource: article_1) - expect(record.average).to eq 50.5 - expect(record.estimate).to eq 42.5 - expect(record.sum).to eq 101 - expect(record.total).to eq 2 + expect(record.average).to eq(BigDecimal('50.5')) + expect(record.estimate).to eq(BigDecimal('42.5')) + expect(record.sum).to be(101) + expect(record.total).to be(2) end end @@ -22,26 +22,26 @@ RSpec.describe Rating::Rating, ':update_rating' do it 'updates the rating data of the given resource respecting the scope' do record = described_class.find_by(resource: article_1, scopeable: category) - expect(record.average).to eq 1.5 - expect(record.estimate).to eq 1.5 - expect(record.sum).to eq 3 - expect(record.total).to eq 2 + expect(record.average).to eq(BigDecimal('1.5')) + expect(record.estimate).to eq(BigDecimal('1.5')) + expect(record.sum).to be(3) + expect(record.total).to be(2) end end context 'when rate table has no record' do - let!(:resource) { create :article } - let!(:scope) { nil } + let!(:resource) { create(:article) } + let!(:scope) { nil } it 'calculates with counts values as zero' do - described_class.update_rating resource, scope + described_class.update_rating(resource, scope) record = described_class.last - expect(record.average).to eq 0 - expect(record.estimate).to eq 0 - expect(record.sum).to eq 0 - expect(record.total).to eq 0 + expect(record.average).to eq(BigDecimal('0.0')) + expect(record.estimate).to eq(BigDecimal('0.0')) + expect(record.sum).to be(0) + expect(record.total).to be(0) end end end