spc: uses conditional assert
For some reason that I don't know, the MySQL and Postgres has different precision to keep the decimal, so instead to match the exactly number, we're justing checking the Rating logic without worry with that precision.main
parent
06b2caaa4b
commit
9691ba81a0
|
@ -13,7 +13,13 @@ 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.count_avg).to eq(BigDecimal('1.333333333333333333'))
|
if ENV.fetch('DB') == 'mysql'
|
||||||
|
expect(result.count_avg).to eq(BigDecimal('1.333333333333333333'))
|
||||||
|
elsif ENV.fetch('DB') == 'postgres'
|
||||||
|
expect(result.count_avg).to eq(BigDecimal('1.3333333333333333'))
|
||||||
|
else
|
||||||
|
raise('DB env missing!')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,13 @@ 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 eq(BigDecimal('42.5000000000000000012000000505'))
|
if ENV.fetch('DB') == 'mysql'
|
||||||
|
expect(result[:estimate]).to eq(BigDecimal('42.5000000000000000012000000505'))
|
||||||
|
elsif ENV.fetch('DB') == 'postgres'
|
||||||
|
expect(result[:estimate]).to eq(BigDecimal('42.5000000000000001200000000000000012505'))
|
||||||
|
else
|
||||||
|
raise('DB env missing!')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,18 @@ 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(BigDecimal('50.5'))
|
if ENV.fetch('DB') == 'mysql'
|
||||||
expect(record.estimate).to eq(BigDecimal('42.5'))
|
expect(record.average).to eq(BigDecimal('50.5'))
|
||||||
expect(record.sum).to be(101)
|
expect(record.estimate).to eq(BigDecimal('42.5'))
|
||||||
expect(record.total).to be(2)
|
elsif ENV.fetch('DB') == 'postgres'
|
||||||
|
expect(record.average).to eq(BigDecimal('50.5'))
|
||||||
|
expect(record.estimate).to eq(BigDecimal('42.5000000000000001'))
|
||||||
|
else
|
||||||
|
raise('DB env missing!')
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(record.sum).to be(101)
|
||||||
|
expect(record.total).to be(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
ENV['DB'] ||= 'mysql'
|
ENV['DB'] ||= 'postgres'
|
||||||
|
|
||||||
conn_params = { database: :rating_test, host: '127.0.0.1' }
|
conn_params = { database: :rating_test, host: '127.0.0.1' }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue