私はRspecコントローラテストでアソシエーションをテストしようとしています。問題は、Factoryがattributes_forコマンドの関連付けを生成しないことです。だから、this postでの提案を以下の私の検証がそうのような私のコントローラの仕様に属性を定義した:FactoryGirl attributes_forとアソシエーション
EntitlementsController PUT update with valid params assigns the requested entitlement as @entitlement
Failure/Error: entitlement = Entitlement.create! valid_attributes
ActiveRecord::RecordInvalid:
Validation failed: User can't be blank, Country can't be blank, Client & expert are both FALSE. Please specify either a client or expert relationship, not both
しかし:しかし
def valid_attributes
user = FactoryGirl.create(:user)
country = FactoryGirl.create(:country)
valid_attributes = FactoryGirl.build(:entitlement, user_id: user.id, country_id: country.id, client: true).attributes.symbolize_keys
puts valid_attributes
end
、コントローラのテストランは、私はまだ、次のエラーを取得するとき
{:id=>nil, :user_id=>2, :country_id=>1, :client=>true, :expert=>false, :created_at=>nil, :updated_at=>nil}
ああ、ありがとうございます。 –