I'm running rails 3.0, rspec 2.0 and factory_girl. Here is the simplified scenario I'm working with: a user can subscribe to only one plan at a time
# user.rb
class User < ActiveRecord::Base
has_one :plan
attr_accessible :login, :plan_id
end
# plan.rb
class Profile < ActiveRecord::Base
attr_accessible :plan
end
# user_factory.rb
Factory.define :user do |u|
u.login "test"
u.association :plan
end
#plan_factory.rb
Factory.define :plan do |p|
p.name "plan1"
end
when I run rspec spec/models/user_spec.rb I got this error:
Failure/Error: user = Factory(:user) SQLite3::ConstraintException: users.plan_id may not be NULL
#spec/models/user_spec.rb
require File.dirname(__FILE__) + '/../spec_helper'
describe User do
it "should be valid" do
user = Factory(:user)
#User.new.should be_valid
user.should be_valid
end
end
what I'm doing wrong? I'm stuck with this very simple scenario, and it is very frustating. at that point BDD slow me down like hell!