devmynd/hstore_accessor — pull request #8 by pallymore (2013-11-01 20:57:40+00:00)
Title: when a string 'true' is passed to a boolean field it should be saved as 'true'

Hello DevMynd,

First of all, thank you for this awesome gem. I'm using it in multiple projects.

Earlier today I was working on a simple form that creates a new object in the database when submitted, then I discovered that a few boolean fields in the hstore are always saved as false. I double checked the spelling of the fieldnames and the values and then found out the root cause is that when the form values are passed as strings to the controller, and for those boolean fields the gem is comparing the value directly to true to decide if it is true.

I think it's probably a good idea to assume "true" string means true, so I made this little change here.

But furthermore, I'm not sure if you guys want to think about more use cases: like by default if you don't assign a value to a checkbox, when it's checked, the value is actually "on" which should be true as well. Or, for a more generic use, should it be

:boolean => -> value { (value && true).to_s }

so all Ruby true value will be casted to true correctly?