spec: uses case conditional

main
Washington Botelho 2022-05-18 11:26:52 -03:00
parent 3e251e00bb
commit 88d15ff408
3 changed files with 9 additions and 6 deletions

View File

@ -13,9 +13,10 @@ 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
if ENV.fetch('DB') == 'mysql' case ENV.fetch('DB')
when 'mysql'
expect(result.count_avg).to eq(BigDecimal('1.333333333333333333')) expect(result.count_avg).to eq(BigDecimal('1.333333333333333333'))
elsif ENV.fetch('DB') == 'postgres' when 'postgres'
expect(result.count_avg).to eq(BigDecimal('1.3333333333333333')) expect(result.count_avg).to eq(BigDecimal('1.3333333333333333'))
else else
raise('DB env missing!') raise('DB env missing!')

View File

@ -21,9 +21,10 @@ RSpec.describe Rating::Rating, ':data' do
end end
it 'returns the estimate for a resource' do it 'returns the estimate for a resource' do
if ENV.fetch('DB') == 'mysql' case ENV.fetch('DB')
when 'mysql'
expect(result[:estimate]).to eq(BigDecimal('42.5000000000000000012000000505')) expect(result[:estimate]).to eq(BigDecimal('42.5000000000000000012000000505'))
elsif ENV.fetch('DB') == 'postgres' when 'postgres'
expect(result[:estimate]).to eq(BigDecimal('42.5000000000000001200000000000000012505')) expect(result[:estimate]).to eq(BigDecimal('42.5000000000000001200000000000000012505'))
else else
raise('DB env missing!') raise('DB env missing!')

View File

@ -9,10 +9,11 @@ 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)
if ENV.fetch('DB') == 'mysql' case ENV.fetch('DB')
when 'mysql'
expect(record.average).to eq(BigDecimal('50.5')) expect(record.average).to eq(BigDecimal('50.5'))
expect(record.estimate).to eq(BigDecimal('42.5')) expect(record.estimate).to eq(BigDecimal('42.5'))
elsif ENV.fetch('DB') == 'postgres' when 'postgres'
expect(record.average).to eq(BigDecimal('50.5')) expect(record.average).to eq(BigDecimal('50.5'))
expect(record.estimate).to eq(BigDecimal('42.5000000000000001')) expect(record.estimate).to eq(BigDecimal('42.5000000000000001'))
else else