Rails 3.0、rspec 2.0、および factory_girl を実行しています。私が取り組んでいる単純化されたシナリオは次のとおりです。ユーザーは一度に 1 つのプランにのみサブスクライブできます。
# 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
rspec spec/models/user_spec.rb を実行すると、次のエラーが発生しました。
失敗/エラー: user = Factory(:user) SQLite3::ConstraintException: users.plan_id を 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
私が間違っていることは何ですか?私はこの非常に単純なシナリオで立ち往生しており、非常にイライラしています。その時点で、BDD は地獄のように私を遅くします!