aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/secure_password_test.rb
blob: 7d7c51e6cb20c502dc09de4b56ad52ab6f81b448 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'cases/helper'
require 'models/user'

class SecurePasswordTest < ActiveModel::TestCase
  setup do
    @user = User.new
  end

  test "password must be present" do
    assert !@user.valid?
    assert_equal 1, @user.errors.size
  end
  
  test "password must match confirmation" do
    @user.password = "thiswillberight"
    @user.password_confirmation = "wrong"
    
    assert !@user.valid?
    
    @user.password_confirmation = "thiswillberight"
    
    assert @user.valid?
  end
  
  test "password must pass validation rules" do
    @user.password = "password"
    assert !@user.valid?
    
    @user.password = "short"
    assert !@user.valid?
    
    @user.password = "plentylongenough"
    assert @user.valid?
  end
  
  test "authenticate" do
    @user.password = "secret"
    
    assert !@user.authenticate("wrong")
    assert @user.authenticate("secret")
  end
end