madeintandem / hstore_accessor

Adds typed hstore-backed field support to ActiveRecord models.
MIT License
242 stars 47 forks source link

Correctly interpret booleans set directly in hstore hash #16

Closed drock closed 10 years ago

drock commented 10 years ago

When using the generated accessor methods to set a boolean values, everything is fine because the accessor sets it using a string. However, if you set a boolean using true by directly accessing the hstore hash, a subsequent call to the generated accessor will be incorrect.

Example(Using Product class from specs):

p = Product.new
p.options['popular'] = true
p.popular?

The last line will return false. This is due to the deserializer directly comparing the boolean value against the string "true".

This patch changes the code to use ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES to accept any true value or string representation of it.

thegrubbsian commented 10 years ago

Just pushed a fix for this...closing it.