Skip to content

Instantly share code, notes, and snippets.

@samflores
Forked from dannluciano/user.rb
Last active August 29, 2015 14:06
Show Gist options
  • Save samflores/028720af6c30c03b0bd2 to your computer and use it in GitHub Desktop.
Save samflores/028720af6c30c03b0bd2 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
validates :username, presence: :true
validates :password_digest, presence: :true
has_secure_password
end
test "username is required" do
@user = User.new(password: 's3kr3t')
assert [email protected]? && @user.errors[:username].include?("can't be blank")
end
test "password is required" do
@user = User.new(username: 'johndoe')
assert [email protected]? && @user.errors[:password].include?("can't be blank")
end
# de acordo com a documentação has_secure_password não adiciona validação de tamanho do campo password
# http://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment