[rspec-users] Missing model attribute in cucumber test

James Byrne lists at ruby-forum.com
Wed Jan 14 13:46:23 EST 2009

Rails 2.2.2
Cucumber 0.1.15

I have this migration for the User model:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string    :sms_address
      t.boolean   :user_administrator,    :default => false,
                                          :null => false
      t.string    :username,              :null => false

I see this in the DB schema:

CREATE TABLE "users" (
  "sms_address" varchar(255),
  "user_administrator" boolean DEFAULT 'f' NOT NULL,
  "username" varchar(255) NOT NULL,

And in the console I see this:

>> myuser=User.new
=> #<User id: nil, crypted_password: nil, current_login_at: nil,
current_login_ip: nil, email: nil, last_login_at: nil, last_login_ip:
nil, last_request_at: nil, login_count: nil, name_last: nil, name_first:
nil, name_middle: nil, openid_identifier: nil, password_salt: nil,
perishable_token: nil, persistence_token: nil, single_access_token: nil,
sms_address: nil, user_administrator: false, username: nil, created_at:
nil, updated_at: nil>
>> y myuser.attributes.sort
- - sms_address
- - updated_at
- - user_administrator
  - false
- - username
=> nil

So, as far as I can see user_administrator is an attribute of users.

However, when I have this step defintion:

When /user named "(.*)" is an administrator/ do |name|
  my_user = User.find_by_username!(name)

Then I see this error:

    And the user named "newuser" is an administrator     #
      undefined method `user_administrator' for #<User:0x2ac26fa83e80>
`And /user named "(.*)" is an administrator/'
      features/app/models/users/user.feature:29:in `And the user named
"newuser" is an administrator'

Have I misspelled something somewhere and just cannot see it?  what is
causing this?
Posted via http://www.ruby-forum.com/.

More information about the rspec-users mailing list