mdeering / attribute_normalizer

Adds the ability to normalize attributes cleanly with code blocks and predefined normalizers
MIT License
475 stars 53 forks source link

Using `normalize_attribute` on a virtual attribute on rails 4.0.4.rc1 #55

Closed PikachuEXE closed 10 years ago

PikachuEXE commented 10 years ago

Rails 4.0.4.rc1, 4.0.3 was fine

Code:

  attr_accessor :shortlisted_only
  normalize_attribute :shortlisted_only do |value|
    ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
  end

Spec error:

1) ListingSearch attributes #shortlisted_only should normalize shortlisted_only from "1" to "true"
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/activemodel-4.0.4.rc1/lib/active_model/attribute_methods.rb:330

  2) ListingSearch attributes #shortlisted_only should normalize shortlisted_only from "0" to "false"
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/activemodel-4.0.4.rc1/lib/active_model/attribute_methods.rb:330

  3) ListingSearch attributes #listings when shortlisted_only is set true 
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.4.rc1/lib/active_record/attribute_methods.rb:50

  4) ListingSearch attributes #listings when shortlisted_only is set true 
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/PikachuEXE/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.0.4.rc1/lib/active_record/attribute_methods.rb:50

Using the normal way to declare accessor at the moment

  def shortlisted_only
    ActiveRecord::ConnectionAdapters::Column.value_to_boolean(@shortlisted_only)
  end
  def shortlisted_only=(value)
    @shortlisted_only = (ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value))
  end
chezka commented 10 years ago

with rails 4.0.4 use 1.2.0.b

fixed in #36

PikachuEXE commented 10 years ago

b for beta?