2010-12-18 16:38:05 -05:00
|
|
|
require 'cases/helper'
|
|
|
|
require 'models/user'
|
|
|
|
|
|
|
|
class SecurePasswordTest < ActiveModel::TestCase
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
setup do
|
|
|
|
@user = User.new
|
|
|
|
end
|
|
|
|
|
|
|
|
test "password must be present" do
|
|
|
|
assert !@user.valid?
|
|
|
|
assert_equal 1, @user.errors.size
|
|
|
|
end
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
test "password must match confirmation" do
|
|
|
|
@user.password = "thiswillberight"
|
|
|
|
@user.password_confirmation = "wrong"
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
assert !@user.valid?
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
@user.password_confirmation = "thiswillberight"
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
assert @user.valid?
|
|
|
|
end
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
test "authenticate" do
|
|
|
|
@user.password = "secret"
|
2010-12-19 04:39:54 -05:00
|
|
|
|
2010-12-18 16:38:05 -05:00
|
|
|
assert !@user.authenticate("wrong")
|
|
|
|
assert @user.authenticate("secret")
|
|
|
|
end
|
2010-12-19 11:58:14 -05:00
|
|
|
end
|