Browse Source
* Init * Add some tests * Add failing spec * Move soft validations into a module * Update test * Rubocop * Scope are auto created by enums * Rename folder to validations * No instance variable * Commit both lines * Add error indication * Make partial slightly more generic * Fix back link * Write failing test * All specs currently passing. Can this be real? * Check page should have an override question * Fix back button for check answers pages * Don't really need a wrapper method for the validations * We're really validating a page here not a question * Dup variable * Bit of a nasty hack but maybe better than deriving back link? * Set a no cache header instead of reloading * Move a teeny bit of logic out of the controller * Rubocop * Extract methodpull/75/head
Daniel Baark
3 years ago
committed by
GitHub
12 changed files with 196 additions and 38 deletions
@ -0,0 +1,45 @@ |
|||||||
|
module SoftValidations |
||||||
|
def has_no_unresolved_soft_errors? |
||||||
|
soft_errors.empty? || soft_errors_overridden? |
||||||
|
end |
||||||
|
|
||||||
|
def soft_errors |
||||||
|
{}.merge(net_income_validations) |
||||||
|
end |
||||||
|
|
||||||
|
def soft_errors_overridden? |
||||||
|
public_send(soft_errors.keys.first) if soft_errors.present? |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
def net_income_validations |
||||||
|
net_income_errors = {} |
||||||
|
if net_income_in_soft_min_range? |
||||||
|
net_income_errors["override_net_income_validation"] = OpenStruct.new( |
||||||
|
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}", |
||||||
|
) |
||||||
|
elsif net_income_in_soft_max_range? |
||||||
|
net_income_errors["override_net_income_validation"] = OpenStruct.new( |
||||||
|
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}", |
||||||
|
) |
||||||
|
else |
||||||
|
update_column(:override_net_income_validation, nil) |
||||||
|
end |
||||||
|
net_income_errors |
||||||
|
end |
||||||
|
|
||||||
|
def net_income_in_soft_max_range? |
||||||
|
return unless weekly_net_income && person_1_economic_status |
||||||
|
|
||||||
|
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max) |
||||||
|
end |
||||||
|
|
||||||
|
def net_income_in_soft_min_range? |
||||||
|
return unless weekly_net_income && person_1_economic_status |
||||||
|
|
||||||
|
weekly_net_income.between?(applicable_income_range.soft_min, applicable_income_range.hard_min) |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,11 @@ |
|||||||
|
<div class="govuk-form-group govuk-form-group--error"> |
||||||
|
<%= f.govuk_check_boxes_fieldset @case_log.soft_errors.keys.first, |
||||||
|
legend: { text: @case_log.soft_errors.values.first.message, size: "l" }, |
||||||
|
hint: { text: @case_log.soft_errors.values.first.hint_text } do %> |
||||||
|
|
||||||
|
<%= f.govuk_check_box @case_log.soft_errors.keys.first, @case_log.soft_errors.keys.first, |
||||||
|
label: { text: "Yes" }, |
||||||
|
checked: f.object.send(@case_log.soft_errors.keys.first) |
||||||
|
%> |
||||||
|
<% end %> |
||||||
|
</div> |
@ -0,0 +1,5 @@ |
|||||||
|
class AddNetIncomeOverride < ActiveRecord::Migration[6.1] |
||||||
|
def change |
||||||
|
add_column :case_logs, :override_net_income_validation, :boolean |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue