我正在测试以下内容:
帐户
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'放在任何地方。