Browse Source

Rubocop

pull/72/head
baarkerlounger 4 years ago
parent
commit
0aca7ad716
  1. 4
      app/models/income_range.rb
  2. 8
      app/modules/soft_validations.rb
  3. 5
      spec/features/case_log_spec.rb

4
app/models/income_range.rb

@ -10,6 +10,6 @@ class IncomeRange
"Unable to work because of long term sick or disability": OpenStruct.new(soft_min: 54, soft_max: 460, hard_min: 10, hard_max: 820), "Unable to work because of long term sick or disability": OpenStruct.new(soft_min: 54, soft_max: 460, hard_min: 10, hard_max: 820),
"Child under 16": OpenStruct.new(soft_min: 50, soft_max: 450, hard_min: 10, hard_max: 750), "Child under 16": OpenStruct.new(soft_min: 50, soft_max: 450, hard_min: 10, hard_max: 750),
"Other": OpenStruct.new(soft_min: 50, soft_max: 580, hard_min: 10, hard_max: 1040), "Other": OpenStruct.new(soft_min: 50, soft_max: 580, hard_min: 10, hard_max: 1040),
"Prefer not to say": OpenStruct.new(soft_min: 47, soft_max: 730, hard_min: 10, hard_max: 1300) "Prefer not to say": OpenStruct.new(soft_min: 47, soft_max: 730, hard_min: 10, hard_max: 1300),
} }.freeze
end end

8
app/modules/soft_validations.rb

@ -3,7 +3,7 @@ module SoftValidations
@soft_errors = {}.merge(net_income_validations) @soft_errors = {}.merge(net_income_validations)
end end
private private
def net_income_validations def net_income_validations
net_income_errors = {} net_income_errors = {}
@ -11,17 +11,17 @@ module SoftValidations
if weekly_net_income < applicable_income_range.soft_min && weekly_net_income > applicable_income_range.hard_min if weekly_net_income < applicable_income_range.soft_min && weekly_net_income > applicable_income_range.hard_min
net_income_errors["weekly_net_income"] = OpenStruct.new( net_income_errors["weekly_net_income"] = OpenStruct.new(
message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?", message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}" hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
) )
elsif weekly_net_income > applicable_income_range.soft_max && weekly_net_income < applicable_income_range.hard_max elsif weekly_net_income > applicable_income_range.soft_max && weekly_net_income < applicable_income_range.hard_max
net_income_errors["weekly_net_income"] = OpenStruct.new( net_income_errors["weekly_net_income"] = OpenStruct.new(
message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?", message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?",
hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}" hint_text: "This is based on the tenant's work situation: #{person_1_economic_status}",
) )
end end
elsif weekly_net_income && person_1_economic_status && override_net_income_validation.present? elsif weekly_net_income && person_1_economic_status && override_net_income_validation.present?
if weekly_net_income > applicable_income_range.soft_min && weekly_net_income < applicable_income_range.soft_max if weekly_net_income > applicable_income_range.soft_min && weekly_net_income < applicable_income_range.soft_max
self.update(override_net_income_validation: nil) update!(override_net_income_validation: nil)
end end
end end
net_income_errors net_income_errors

5
spec/features/case_log_spec.rb

@ -379,13 +379,12 @@ RSpec.describe "Test Features" do
describe "Soft Validation" do describe "Soft Validation" do
context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do context "given a weekly net income that is above the expected amount for the given economic status but below the hard max" do
let!(:case_log){ FactoryBot.create(:case_log, :in_progress, person_1_economic_status: "Full-time - 30 hours or more") } let!(:case_log) { FactoryBot.create(:case_log, :in_progress, person_1_economic_status: "Full-time - 30 hours or more") }
let(:income_over_soft_limit) { 750 } let(:income_over_soft_limit) { 750 }
let(:income_under_soft_limit) { 700 } let(:income_under_soft_limit) { 700 }
it "prompts the user to confirm the value is correct" do it "prompts the user to confirm the value is correct" do
visit("/case_logs/#{case_log.id}/net_income") visit("/case_logs/#{case_log.id}/net_income")
choose("case-log-net-income-known-yes-field", allow_label_click: true)
fill_in("case-log-net-income-field", with: income_over_soft_limit) fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true) choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
@ -397,7 +396,6 @@ RSpec.describe "Test Features" do
it "does not require confirming the value if the value is amended" do it "does not require confirming the value if the value is amended" do
visit("/case_logs/#{case_log.id}/net_income") visit("/case_logs/#{case_log.id}/net_income")
choose("case-log-net-income-known-yes-field", allow_label_click: true)
fill_in("case-log-net-income-field", with: income_over_soft_limit) fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true) choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")
@ -410,7 +408,6 @@ RSpec.describe "Test Features" do
xit "clears the confirmation question if the page is returned to using the back button" do xit "clears the confirmation question if the page is returned to using the back button" do
visit("/case_logs/#{case_log.id}/net_income") visit("/case_logs/#{case_log.id}/net_income")
choose("case-log-net-income-known-yes-field", allow_label_click: true)
fill_in("case-log-net-income-field", with: income_over_soft_limit) fill_in("case-log-net-income-field", with: income_over_soft_limit)
choose("case-log-net-income-frequency-weekly-field", allow_label_click: true) choose("case-log-net-income-frequency-weekly-field", allow_label_click: true)
click_button("Save and continue") click_button("Save and continue")

Loading…
Cancel
Save