1
validate :cannot_modify_if_locked, on: :update
def cannot_modify_if_locked
if self.locked
errors.add(:locked_at, "#{self.locked_at} and cannot be modified")
false
end
end
RSPECRspec的軌道
consent_form = build(:consent_form, { locked_at: Date.today })
expect(consent_form.).to eq true
這個測試是不好的。 如何寫這個測試?我需要在rspec上檢查這個驗證
重新格式化代碼 –
目前尚不清楚你想要達到的,代碼是無效的。你能在你的問題中用簡單的英語解釋嗎? –
我forogot寫這個答案belove我幫助。問題解決了:) @seba – VladimirR