I am trying to write a validation test for the name attribute in order to check if its present. My user_test.rb file:
require 'test_helper'
class UserTest < ActiveSupport::TestCase
  def setup
    @user = User.new(name: "Example User", email: "user@example.com")
  end
  test "should be valid" do
    assert @user.valid?
  end
  test "name should be present" do
    @user.name = " "
    assert_not @user.valid?
  end
end
My user.rb file:
class User < ActiveRecord::Base
  validates(:name, presence: true)
end
My I/O in the console when testing:
2.2.1 :007 > user = User.new(name: "", email: "ex@example.com")
 => #<User id: nil, name: "", email: "ex@example.com", created_at: nil, updated_at: nil> 
2.2.1 :008 > user.valid?
 => true 
 
     
     
    