On 11 June 2011 14:25, ddoherty03 <ddohert...@gmail.com> wrote: > Here is the method that is blowing up: > ===================== greeting.rb ============================== > class Greeting < ActiveRecord::Base > after_initialize :check_greet > validates_uniqueness_of :count > def check_greet > self.language = language.capitalize > end > end > ============================================================ > And here is the backtrace I get when I run the unit test posted earlier: > ============================================================ > Loaded suite > /home/ded/.rvm/gems/ruby-1.9.2-p180@global/gems/rake-0.9.1/lib/rake/rake_test_loader > Started > E > Finished in 0.280612 seconds. > 1) Error: > test_uniqueness_of_count(GreetingTest): > ActiveModel::MissingAttributeError: missing attribute: language > /home/ded/Rails/demo/app/models/greeting.rb:6:in `check_greet' > > /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:415:in > `_run_initialize_callbacks' > > /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activerecord-3.0.3/lib/active_record/base.rb:1453:in > `init_with' > > .... > > /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activemodel-3.0.3/lib/active_model/validations.rb:179:in > `valid?' > > /home/ded/.rvm/gems/ruby-1.9.2-p180@rails303/gems/activerecord-3.0.3/lib/active_record/validations.rb:55:in > `valid?' > /home/ded/Rails/demo/test/unit/greeting_test.rb:7:in `block in > <class:GreetingTest>' > 1 tests, 0 assertions, 0 failures, 1 errors, 0 skips > Test run options: --seed 44283 > rake aborted! > Command failed with status (1): > [/home/ded/.rvm/rubies/ruby-1.9.2-p180/bin/...]
I think this may be helpful http://stackoverflow.com/questions/1778374/validates-presence-of-causes-after-initialize-to-be-called-with-a-weird-self Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.