私は以下をテストしています:
アカウント
class Account < ActiveRecord::Base
has_many :ownerships
has_many :brands, :through => :ownerships
end
所有権参加モデル
class Ownership < ActiveRecord::Base
belongs_to :brand
belongs_to :account
end
テスト
it "should be able to apply for brand ownership" do
account = Account.create(valid_account_attributes)
account.ownerships.create(:brand => Brand.create(:name => 'Superuser'))
account.ownerships.first.state == 'pending'
end
そして、私はこのエラーを受け取り続けます
You cannot call create unless the parent is saved
よくわかりません - どこの親ですか?「作成」メソッドを使用する場合、すべてのモデルを作成して保存するべきではありませんか? 「account.save」をどこにでも置いてみました。