In my holder test file:
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
And my holder model looks like:
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
But, when I run my tests the last two validations are still red. What do I need to do to test them so they turn green?
You forgot
sin yourvalidate. It has to be:validateandvalidatesare completely different methods.See there: http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html.