On 11 June 2011 09:45, ddoherty03 <[email protected]> wrote:
> All,
> Can anyone see what's happening here?
> ================== migration =======================
> class CreateGreetings < ActiveRecord::Migration
>   def self.up
>     create_table :greetings do |t|
>       t.string :greet
>       t.string :language
>       t.integer :count
>       t.timestamps
>     end
>   end
>   def self.down
>     drop_table :greetings
>   end
> end
> ================== greeting.rb =============================
> class Greeting < ActiveRecord::Base
>   after_initialize :check_greet
>   validates_uniqueness_of :count
>   def check_greet
>     self.language = lanugage.capitalize
>   end
> end
> =================== greeting.yml ==========================
> hello:
>   greet: howdy
>   language: english
>   count: 44
> hola:
>   greet: hola, que tal
>   language: spanish
>   count: 55
> =================== greeting_test.rb ========================
> require 'test_helper'
> class GreetingTest < ActiveSupport::TestCase
>   # Replace this with your real tests.
>   test "uniqueness of count" do
>     gg = Greeting.new(:language => 'esperanto', :count =>
> greetings(:hello).count)
>     assert !gg.valid?
>   end
> end
> =========================================================
> When I run 'rake test:units' on this it blows up when getting to the
> after_initialize
> procedure, claiming there is no method 'language' for the Greeting class.
> I'm having this issue in a larger app, but I've tried to pare this down to
> the minimum
> that reproduces the problem.
> Is this a bug in rails, or am I missing something?

This shows how important it is to always copy/paste error messages and
code.  I think if you look carefully at the error message you may see
that it says that there is no method lanugage rather than language.
Check the code in check_greet

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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to