Skip to content

Commit b560322

Browse files
authoredNov 12, 2019
Fix money formatting and feedback in Maternity/Paternity/Adopti… (#4212)
Fix money formatting and feedback in Maternity/Paternity/Adoption calculator
2 parents 45eea26 + 967221d commit b560322

7 files changed

+19
-5
lines changed
 

‎app/presenters/money_question_presenter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def response_label(value)
66
end
77

88
def hint_text
9-
text = [body, "in £", suffix_label].reject(&:blank?).compact.join(", ")
9+
text = [body, suffix_label].reject(&:blank?).compact.join(", ")
1010
ActionView::Base.full_sanitizer.sanitize(text)
1111
end
1212
end

‎lib/smart_answer/money.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def <=>(other)
2727
end
2828

2929
def self.parse(raw_input)
30-
raw_input.is_a?(Numeric) ? raw_input : raw_input.to_s.delete(",").gsub(/\s/, "")
30+
if raw_input.is_a?(Numeric)
31+
raw_input
32+
else
33+
raw_input.to_s.delete(",").gsub(/\s/, "").gsub(/£/, "")
34+
end
3135
end
3236

3337
def self.validate!(input)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% content_for :error_message do %>
2+
Use numbers like 12.34
3+
<% end %>

‎lib/smart_answer_flows/maternity-paternity-calculator/questions/earnings_for_pay_period.govspeak.erb

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
<% content_for :hint do %>
66
This is their earnings before deductions like PAYE, pension or National Insurance contributions.
77
<% end %>
8+
9+
<%= render partial: 'earnings_question_error_message.govspeak.erb' %>

‎lib/smart_answer_flows/maternity-paternity-calculator/questions/earnings_for_pay_period_adoption.govspeak.erb

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@
66
This is their earnings before deductions like PAYE, pension or National Insurance contributions.
77
<% end %>
88

9-
<% content_for :error_message do %>
10-
Please enter a number greater than 0
11-
<% end %>
9+
<%= render partial: 'earnings_question_error_message.govspeak.erb' %>

‎lib/smart_answer_flows/maternity-paternity-calculator/questions/earnings_for_pay_period_paternity.govspeak.erb

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
<% content_for :hint do %>
66
This is the earnings before deductions like PAYE, pension or National Insurance contributions.
77
<% end %>
8+
9+
<%= render partial: 'earnings_question_error_message.govspeak.erb' %>

‎test/unit/money_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class MoneyTest < ActiveSupport::TestCase
2424
assert two == 2000
2525
end
2626

27+
test "Values with £ sign are stripped out and parsed correctly" do
28+
salary = SmartAnswer::Money.new("£15000")
29+
assert salary == 15000
30+
end
31+
2732
test "should be possible to initialize with a BigDecimal" do
2833
v = BigDecimal("1234.5678")
2934
money = SmartAnswer::Money.new(v)

0 commit comments

Comments
 (0)
Please sign in to comment.