我正在使用一些 Shoulda rspec 匹配器来测试我的模型,其中之一是:
describe Issue do
it { should_not allow_value("test").for(:priority) }
end
我的问题是我在模型中的验证如下所示:
validates_format_of :priority, :with => /^(Low|Normal|High|Urgent)$/, :on => :update
因此,在运行此测试时,我得到:
1) 'Issue should not allow priority to be set to "test"' FAILED
Expected errors when priority is set to "test", got errors: category is invalid (nil)title can't be blank (nil)profile_id can't be blank (nil)
验证没有被触发,因为它只在更新时运行,我如何在更新和创建时使用这些应该匹配器?