makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Casting virtual boolean attributes fails in some versions of Rails and MySQL #42

Closed geniousli closed 8 years ago

geniousli commented 9 years ago

class Users::Subscribe < ActiveType::Object attribute :subscribe, :boolean def test if self.subscribe

.....

 end

end end

when i call test method, if statement in test method always passed, even i pass false to subscribe attribute, does it a bug, or designed?

mattbrictson commented 9 years ago

Can you clarify exactly what code you are running? Please also include the versions of Rails and active_type you are running as well as which database adapter you are using

I just tried this example and it works fine:

class Example < ActiveType::Object
  attribute :subscribe, :boolean

  def test
    if self.subscribe
      "Subscribe"
    else
      "Not subscribe"
    end
  end
end

e = Example.new
e.subscribe = false
e.test # => "Not subscribe"
e.subscribe = true
e.test # => "Subscribe"
geniousli commented 9 years ago

i am sorry for the first Issue format, i don't know it support markdown, thank for you patience

mattbrictson commented 9 years ago

OK, I can confirm this is a bug. I am seeing the same failing boolean behavior with:

The bug also exists with active_type master @ 937306d.

@henning-koch this seems to be a duplicate of #34.

geniousli commented 9 years ago

yes, They are looks the same

triskweline commented 8 years ago

I hope this was fixed in 0.4.3.