Ruby on Rails tutorial ArgumentError: Unknown validator: 'PresenseValidator'

943 Views Asked by At

I'm a student studying the ruby on rails tutorial. I'm working on the Sample_App and everything was working green until I added some tests for password validity. now i get 1 error and 2 failures. The test generating the error changes every time I run the test, but its always a presence validator. The failures stay the same.

ERROR["test_layout_links", #<Minitest::Reporters::Suite:0x000055584f4fae28 @name="SiteLayoutTest">, 0.00946968999960518] test_layout_links#SiteLayoutTest (0.01s) ArgumentError: ArgumentError: Unknown validator: 'PresenseValidator' app/models/user.rb:10:in <class:User>' app/models/user.rb:1:in '

FAIL["test_password_should_be_present_(nonblank)", #<Minitest::Reporters::Suite:0x00007f2b307e3c60 @name="UserTest">, 0.07021111799986102] test_password_should_be_present_(nonblank)#UserTest (0.07s) Expected true to be nil or false test/models/user_test.rb:67:in `block in class:UserTest'

FAIL["test_password_should_have_minimum_length", #<Minitest::Reporters::Suite:0x00007f2b308e9948 @name="UserTest">, 0.09405937999872549] test_password_should_have_minimum_length#UserTest (0.09s) Expected true to be nil or false test/models/user_test.rb:72:in `block in class:UserTest'

18/18: [===========================================================================================================================================] 100% Time: 00:00:00, Time: 00:00:00

Finished in 0.54466s 18 tests, 31 assertions, 2 failures, 1 errors, 0 skips

class User < ApplicationRecord
  
    before_save { email.downcase! }
    validates :name,  presence: true, length: { maximum: 50 }
    VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
    validates :email, presence: true, length: { maximum: 255 },
                      format: { with: VALID_EMAIL_REGEX },
                      uniqueness: true
    has_secure_password
    validates :password, presense: true, length: { minimum: 6 }
  end

is my user.rb file

require "test_helper"

class UserTest < ActiveSupport::TestCase
  
  def setup
    @user = User.new(name: "Example User", email: "[email protected]",
                     password: "foobar", password_confirmation: "foobar")
  end
  
  test "should be valid" do
    assert @user.valid?
  end
  
  test "name should be present" do
    @user.name = "       "
    assert_not @user.valid?
  end
  
  test "email should be present" do
    @user.email = "       "
    assert_not @user.valid?
  end
  
  test "name should not be too long" do
    @user.name = "a" * 51
    assert_not @user.valid?
  end
  
  test "email should not be too long" do
    @user.email = "a" * 244 + "@example.com"
    assert_not @user.valid?
  end
  
  test "email validation should accept valid addresses" do
    valid_addresses = %w[[email protected] [email protected] [email protected] 
                      [email protected] [email protected]]
    valid_addresses.each do |valid_address|
      @user.email = valid_address
      assert @user.valid?, "#{valid_address.inspect} should be valid"
    end
  end
  
  test "email validation should reject invalid addresses" do
    invalid_addresses = %w[user@example,com user_at_foo.org user.name@example. 
                        foo@bar_baz.com foo@bar+baz.com [email protected]]
    invalid_addresses.each do |invalid_address|
      @user.email = invalid_address
      assert_not @user.valid?, "#{invalid_address.inspect} should be invalid"
    end   
  end
  
  test "email addresses should be unique" do
    duplicate_user = @user.dup
    @user.save
    assert_not duplicate_user.valid?
  end
  
  test "email addresses should be saved as lower-case" do
    mixed_case_email = "[email protected]"
    @user.email = mixed_case_email
    @user.save
    assert_equal mixed_case_email.downcase, @user.reload.email
  end
  
  test "password should be present (nonblank)" do
    @user.password = @user.password_confirmation = " " * 5
    assert_not @user.valid?
  end
  
  test "password should have minimum length" do
    @user.password = @user.password_confirmation = "a" * 5
    assert_not @user.valid?
  end 
end

is my test file. These are the last two files I was working with when the errors popped up. Any help would be appreciated, I can provide more information or other parts of the code if anyone can figure out where else I need to look for what's going on.

0

There are 0 best solutions below