Topic: more errors [SOLVED]

1) User when First Name is too long
     Failure/Error: before { User.first_name = "a" * 210 }
     NoMethodError:
       undefined method `first_name=' for #<Class:0x007ffbc68f9ca0>
     # ./spec/models/user_spec.rb:28:in `block (3 levels) in <top (required)>

  describe "when First Name is too long" do
    before { User.first_name = "a" * 21 }
   it { should_not be_valid }
  end

now when i go to rails c
Loading development environment (Rails 3.2.3)

User
=> User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, created_at: datetime, updated_at: datetime, username: string, account_id: integer, first_name: string, last_name: string)

i can see that first_name is there

Last edited by moiseszaragoza (2012-05-22 21:43:57)

Re: more errors [SOLVED]

You are calling first_name on the class and not an instance of the class.

Try:

 describe "when First Name is too long" do
  subject { User.new }
  before { subject.first_name = "a" * 21 }
  it { should_not be_valid }
end

Re: more errors [SOLVED]

you are a life saver
Thank you so much