rspec2 - FactoryGirl + RSpec + Rails 3 'undefined method <attribute>=' -


i'm new rails , tdd (as no doubt obvious post) , having hard time wrapping brain around rspec , factorygirl.

i'm using rails 3, rspec , factory girl:

gem 'rails', '3.0.3' # ...    gem 'rspec-rails', '~>2.4.0' gem 'factory_girl_rails' 

i have user model i've been running tests on during development, needed add attribute to, called "source". it's determining user record came (local vs ldap).

in factories.rb file, have several factories defined, following:

# alumnus account tied ldap factory.define :alumnus, :class => user |f|   f.first_name "mickey"   f.last_name  "mouse"   f.username   "mickeymouse"   f.password   "strongpassword"   f.source     "directory" end 

i have macro defined (that's been working until now) looks this:

def login(user)   before(:each)     sign_out :user     sign_in factory.create(user)   end end 

i'm calling in multiple specs (example users_controller_spec.rb):

describe "for non-admins or managers"   login(:alumnus)    "should deny access"     :index     response.should redirect_to(destroy_user_session_path)   end  end 

if don't specify "source" attribute, works ok, do, error when running test

  12) userscontroller non-admins or managers should deny access  failure/error: unable find matching line backtrace  nomethoderror:    undefined method `source=' #<user:0x00000100e256c0> 

i can access attribute no problem rails console , app itself, , it's listed in attr_accessible in user model. it's though rspec seeing old version of model , not recognizing i've added attribute it. if put following line user model, error disappears

attr_accessor :source 

... indicates me looking @ correct model.

help!

how running this?

rake db:test:load 

[if added new attribute you'd need migrate test database.]


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -