Skip to content

Commit

Permalink
ap-4503: move ineligible reasons into translations
Browse files Browse the repository at this point in the history
  • Loading branch information
kmahern committed Nov 15, 2023
1 parent 3697e11 commit d132944
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
16 changes: 11 additions & 5 deletions app/helpers/ineligible_reasons_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@ def ineligible_reasons(cfe_result)
return "" unless cfe_result.assessment_result == "ineligible"

reasons = ineligible_reasons_array(cfe_result)
return reasons.first if reasons.length == 1
return ineligible_reason(reasons.first) if reasons.length == 1

ineligible_reasons = ":<ul class='govuk-list govuk-list--bullet'>"
reasons.each { |reason| ineligible_reasons += "<li>#{reason}</li>" }
reasons.each do |reason|
ineligible_reasons += "<li>#{ineligible_reason(reason)}</li>"
end
ineligible_reasons += "</ul>"
end

private

def ineligible_reason(reason)
t("shared.ineligible_reasons.#{reason}")
end

def ineligible_reasons_array(cfe_result)
ineligible_reasons_array = []
ineligible_reasons_array << "gross income" if cfe_result.ineligible_gross_income?
ineligible_reasons_array << "disposable income" if cfe_result.ineligible_disposable_income?(cfe_result)
ineligible_reasons_array << "disposable capital" if cfe_result.ineligible_disposable_capital?(cfe_result)
ineligible_reasons_array << "gross_income" if cfe_result.ineligible_gross_income?
ineligible_reasons_array << "disposable_income" if cfe_result.ineligible_disposable_income?
ineligible_reasons_array << "disposable_capital" if cfe_result.ineligible_disposable_capital?
ineligible_reasons_array
end
end
10 changes: 5 additions & 5 deletions app/models/cfe/v6/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def capital_results
end

def ineligible_gross_income?
gross_income_results.all? { |result| result == 'ineligible' }
gross_income_results.all?("ineligible")
end

def ineligible_disposable_income?
disposable_income_results.all? { |result| result == 'ineligible' }
disposable_income_results.all?("ineligible")
end

def ineligible_disposable_capital?
capital_results.all? { |result| result == 'ineligible' }
capital_results.all?("ineligible")
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -922,3 +922,7 @@ en:
details: |
For example, Child Benefit or tax credits.
Do not include Housing Benefit, government Cost of Living Payments, or any other disregarded benefits.
ineligible_reasons:
gross_income: gross income
disposable_income: disposable income
disposable_capital: disposable capital
2 changes: 1 addition & 1 deletion spec/models/cfe/v6/result_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module V6
end
end

describe "#ineligible_gross_income?" do
describe "#ineligible_disposable_income?" do
context "when overall result is eligible" do
it "returns false" do
expect(cfe_result.ineligible_disposable_income?).to be false
Expand Down

0 comments on commit d132944

Please sign in to comment.