diff --git a/lib/hermod/xml_section_builder.rb b/lib/hermod/xml_section_builder.rb index 02fc0da..5b3e7a9 100755 --- a/lib/hermod/xml_section_builder.rb +++ b/lib/hermod/xml_section_builder.rb @@ -152,6 +152,7 @@ def monetary_node(name, options={}) end create_method(name, [], validators, options) do |value, attributes| + value = value.to_i if options[:optional] && value == 0 [nil, attributes] else diff --git a/spec/hermod/xml_section_builder/monetary_node_spec.rb b/spec/hermod/xml_section_builder/monetary_node_spec.rb index e40b1fe..6bfdf54 100644 --- a/spec/hermod/xml_section_builder/monetary_node_spec.rb +++ b/spec/hermod/xml_section_builder/monetary_node_spec.rb @@ -51,6 +51,14 @@ module Hermod ex = proc { subject.student_loan 0 }.must_raise Hermod::InvalidInputError ex.message.must_equal "student_loan cannot be zero" end + + it "should treat blank nodes as zero nodes" do + subject.ni nil + value_of_node("NI").must_equal "0.00" + + subject.tax nil + nodes("Tax").must_be_empty + end end end end