spec: using the correct types

main
Washington Botelho 2022-05-18 09:54:53 -03:00
parent cb3538cde6
commit 90dc76e4d9
3 changed files with 17 additions and 17 deletions

View File

@ -13,7 +13,7 @@ RSpec.describe Rating::Rating, ':averager_data' do
end end
it 'returns the average of number of records for the given resource type' do 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
end end

View File

@ -21,7 +21,7 @@ RSpec.describe Rating::Rating, ':data' do
end end
it 'returns the estimate for a resource' do 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
end end

View File

@ -9,10 +9,10 @@ RSpec.describe Rating::Rating, ':update_rating' do
it 'updates the rating data of the given resource' do it 'updates the rating data of the given resource' do
record = described_class.find_by(resource: article_1) record = described_class.find_by(resource: article_1)
expect(record.average).to eq 50.5 expect(record.average).to eq(BigDecimal('50.5'))
expect(record.estimate).to eq 42.5 expect(record.estimate).to eq(BigDecimal('42.5'))
expect(record.sum).to eq 101 expect(record.sum).to be(101)
expect(record.total).to eq 2 expect(record.total).to be(2)
end end
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 it 'updates the rating data of the given resource respecting the scope' do
record = described_class.find_by(resource: article_1, scopeable: category) record = described_class.find_by(resource: article_1, scopeable: category)
expect(record.average).to eq 1.5 expect(record.average).to eq(BigDecimal('1.5'))
expect(record.estimate).to eq 1.5 expect(record.estimate).to eq(BigDecimal('1.5'))
expect(record.sum).to eq 3 expect(record.sum).to be(3)
expect(record.total).to eq 2 expect(record.total).to be(2)
end end
end end
context 'when rate table has no record' do context 'when rate table has no record' do
let!(:resource) { create :article } let!(:resource) { create(:article) }
let!(:scope) { nil } let!(:scope) { nil }
it 'calculates with counts values as zero' do it 'calculates with counts values as zero' do
described_class.update_rating resource, scope described_class.update_rating(resource, scope)
record = described_class.last record = described_class.last
expect(record.average).to eq 0 expect(record.average).to eq(BigDecimal('0.0'))
expect(record.estimate).to eq 0 expect(record.estimate).to eq(BigDecimal('0.0'))
expect(record.sum).to eq 0 expect(record.sum).to be(0)
expect(record.total).to eq 0 expect(record.total).to be(0)
end end
end end
end end