[rspec-users] Missing model attribute in cucumber test

aslak hellesoy aslak.hellesoy at gmail.com
Wed Jan 14 14:19:20 EST 2009


On Wed, Jan 14, 2009 at 7:46 PM, James Byrne <lists at ruby-forum.com> wrote:

> Rails 2.2.2
> Cucumber 0.1.15
> SQLite3
>
> 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" (
>  "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
> ...
>  "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)
>  my_user.user_administrator
> end
>
> Then I see this error:
>
>    And the user named "newuser" is an administrator     #
> features/app/models/users/step_definitions/user_steps.rb:24
>      undefined method `user_administrator' for #<User:0x2ac26fa83e80>
> (NoMethodError)
>
>  /usr/lib64/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in
> `method_missing'
>      ./features/app/models/users/step_definitions/user_steps.rb:26:in
> `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?


Did you migrate your test db? rake features does that for you, but plain
cucumber doesn't

Aslak


>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090114/d71d8d79/attachment.html>


More information about the rspec-users mailing list