我有这个模型代码:
validates_presence_of :setting_id
validates_presence_of :user_id
validates_presence_of :topic_id, if: :direct?
我有这些 rspec 测试:
it { should validate_presence_of :setting_id }
it { should validate_presence_of :user_id }
it { should validate_presence_of(:topic_id).if(:direct?) }
前 2 个测试工作正常。最后一个给出了一个错误:
undefined method 'if' for #<Shoulda::Matchers::ActiveModel::ValidatePresenceOfMatcher:0x007fda6a5c6268>
如何为代码片段添加类似的测试以验证最后一次存在(:topic_id).if(:direct?)