newtoy/toystore — Issue #23: Boolean objects don't work as excepted
Author: gtaglang
Created: 2011-10-19 08:51:16+00:00
State: open

Say I have this model :

```ruby
# test_bool.rb
require 'toystore'
require 'adapter/memory'

class TestBool
include Toy::Store
store :memory, {}
attribute :bool, Boolean
end
```

Test in the console :

```
ruby > require '/path/to/test_bool.rb'
=> true
ruby > t = TestBool.create(:bool => '0')
=> #
```

According to [extensions/boolean.rb](https://github.com/newtoy/toystore/blob/master/lib/toy/extensions/boolean.rb) when I receive a value from a webpage, for exemple :

```ruby
params = {'bool' => '0'}
t = TestBool.create(params)
puts t.bool #=> we get true
```

We should have a `TestBool` object with `bool` attribute set to `false`. Here it's not the case.
When I try to set the `bool` attribute with the `false` object I get the correct result as excepted. Same with `nil` object.

I checked [spec/toy/extensions/boolean_spec.rb](https://github.com/newtoy/toystore/blob/master/spec/toy/extensions/boolean_spec.rb) in the IRB console `Boolean.to_store` and `Boolean.from_store` methods and they parse the attribute as excepted.

So I think that the attribute we want to save as a `Boolean` object is already `true` when it comes to the `Boolean.to_store` method.