这是我的模型验证
validate :validate_mark_cheat
def validate_mark_cheat
if (self.student_from_id == self.student_to_id)
errors.add(:student_from_id, "a mark can't be self-asign")
errors.add(:student_to_id, "a mark can't be self-asign")
end
end
这是我的单元测试
test "Mark can't be self-given" do
mark = Mark.new(:student_from_id => 1, :student_to_id =>1)
assert mark.invalid?
assert mark.errors[:sudent_from_id].any?
assert mark.errors[:student_to_id].any?
end
我不知道为什么我的测试失败了
谢谢