Skip to content

Commit

Permalink
Cast monetary node values to integers first
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Mills committed Nov 4, 2014
1 parent 5320351 commit 978d78b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/hermod/xml_section_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def monetary_node(name, options={})
end

create_method(name, [], validators, options) do |value, attributes|
if (options[:optional] && value == 0) || value.blank?
value = value.to_i
if options[:optional] && value == 0
[nil, attributes]
else
[sprintf(format_for(:money), value), attributes]
Expand Down
7 changes: 5 additions & 2 deletions spec/hermod/xml_section_builder/monetary_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ module Hermod
ex.message.must_equal "student_loan cannot be zero"
end

it "should ignore blank nodes" do
it "should treat blank nodes as zero nodes" do
subject.ni nil
nodes("NI").must_be_empty
value_of_node("NI").must_equal "0.00"

subject.tax nil
nodes("Tax").must_be_empty
end
end
end
Expand Down

0 comments on commit 978d78b

Please sign in to comment.