0
在我的Rails应用程序我有各种Items
的Invoice
:如何使用RSpec单元测试accep_nested_attributes_for?
class Invoice < ActiveRecord::Base
attr_accessible :date, :recipient, :items_attributes
accepts_nested_attributes_for :items, :reject_if => :all_blank, :allow_destroy => true
end
不过,我与该模型一个RSpec的单元测试挣扎。例如,我想测试一个发票如果没有项目就会报错。
这不起作用:
describe Invoice do
it "is invalid without an item" do
expect(build(:invoice, :items_attributes => {}).to have(1).errors_on(:items_attributes)
end
end
有人能帮忙吗?