riak-ripple / ripple

A rich Ruby modeling layer for Riak, Basho's distributed database
Other
619 stars 152 forks source link

Boolean properties do not set correctly #279

Closed IdahoEv closed 12 years ago

IdahoEv commented 12 years ago

Web form checkboxes submit "0" for unchecked and "1" for checked. Ripple Boolean properties typecast "0" as 'true'. This means, if you're using a normal update_attributes() in Rails, it is impossible to unset a boolean by unchecking the box.

I can submit a pull request that fixes this, but I wanted to check if this was on purpose or not, first. Code example and console transcript below


class MyModel include Ripple::Document

property :awesome, Boolean end

$ rails console ruby-1.9.2-p290 :009 > prop = MyModel.properties[:awesome] => #<Ripple::Property:0x007fd0a4fc61c0 @options={}, @key=:awesome, @type=Boolean> ruby-1.9.2-p290 :010 > prop.type_cast("0") => true ruby-1.9.2-p290 :011 > prop.type_cast("1") => true ruby-1.9.2-p290 :012 > mm = MyModel.new => <MyModel:[new] awesome=nil> ruby-1.9.2-p290 :013 > mm.update_attributes("awesome" => '0') => true ruby-1.9.2-p290 :014 > mm =>

IdahoEv commented 12 years ago

version tested was current head: f28a4b940708