From 978d78b81f65884df1321ec5e8ef73ae95b71005 Mon Sep 17 00:00:00 2001 From: Harry Mills Date: Tue, 4 Nov 2014 16:35:37 +0000 Subject: [PATCH] Cast monetary node values to integers first --- lib/hermod/xml_section_builder.rb | 3 ++- spec/hermod/xml_section_builder/monetary_node_spec.rb | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/hermod/xml_section_builder.rb b/lib/hermod/xml_section_builder.rb index 90b0e48..5b3e7a9 100755 --- a/lib/hermod/xml_section_builder.rb +++ b/lib/hermod/xml_section_builder.rb @@ -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] diff --git a/spec/hermod/xml_section_builder/monetary_node_spec.rb b/spec/hermod/xml_section_builder/monetary_node_spec.rb index f947f91..6bfdf54 100644 --- a/spec/hermod/xml_section_builder/monetary_node_spec.rb +++ b/spec/hermod/xml_section_builder/monetary_node_spec.rb @@ -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