4
我测试如下:RSpec的测试关系逻辑
帐户
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
我真的不明白 - 父母是什么?使用'create'方法时不应该创建和保存所有模型吗?我已经尝试过把'account.save'放在任何地方。
我认为在某处存在验证错误。所以#save或#create返回false。我自己面临这个问题。在我的情况下,我是通过使用构建ie嘲笑返回类型即。不保存对象 – deepak 2012-09-25 12:55:12