G5 / storext

Add type-casting and other features on top of ActiveRecord::Store.store_accessor
MIT License
210 stars 55 forks source link

fixed prediacter methods so that empty string return false #30

Closed stebo closed 8 years ago

stebo commented 8 years ago

I found a small bug in my last pull request which added the predicater methods: if you got an empty string like book.title = "" than book.title? will return TRUE - but should return FALSE!

The mistake was using !!value for all attributes, because in plain ruby

empty_string = ""
=> ""
!!empty_string
=> true

But Rails ActiveRecord does not simply use !!value - it differs between types and if the type is a string than it uses !value.blank? ... which is much better because of course if we check an object attribute with an emtpy string we want

book.title = ""
=> ""
book.title?
=> false
ramontayag commented 8 years ago

Yes, you're right - that's how AR does it. Thanks!

ramontayag commented 8 years ago

2.2.1 released