Allow optional attributes with types other than String #31

Merged
merged 2 commits into from Feb 20, 2014

Projects

None yet

2 participants

@nerab
nerab commented Feb 20, 2014

This PR adds support for optional attributes with a type other than String.

Before, if an attribute was defined with a type other than String and was nil, to_xml failed with an error similar to:

TypeError in '#to_xml Address before(:all)'
wrong argument type Float (expected String)

The fix is pretty simple - always calling to_s on the value is the right thing to do for an attribute, because attributes are always text in XML.

There is an additional change that sets the Gemfile source to https://rubygems.org.

nerab added some commits Feb 20, 2014
@nerab nerab Change source to the recommended https://rubygems.org value d2351e5
@nerab nerab Allow optional attributes with types other than String
This commit adds support for optional attributes (nil is an allowed
value). Without it, HappyMapper will fail with an error similar to:

  TypeError in '#to_xml Address before(:all)'
  wrong argument type Float (expected String)

if an attribute is defined with a type other than String, but
is actually nil, when to_xml is called.

The fix is pretty simple - always calling to_s on the value is the
right thing to do for an attribute, because attributes are always
text in XML.
e6c2c6b
@jnunemaker jnunemaker merged commit ab86093 into jnunemaker:master Feb 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment