在我的持有人测试文件中:
test "name must be present" do
holder = Holder.new(name: "name")
assert holder.valid?
end
test "name must not be blank" do
h = Holder.new(name: " ")
assert !h.valid?
end
test "name must not be nil" do
h = Holder.new(name: nil)
assert !h.valid?
end
我的持有人模型看起来像:
class Holder < ActiveRecord::Base
attr_accessible :description, :name, :user_id
validates_length_of :name, maximum: 75
validates_length_of :description, maximum: 250
validate :name, presence: true
end
但是,当我运行测试时,最后两个验证仍然是红色的。我需要做些什么来测试它们以使它们变绿?