Sha256: 3b52589c5f4a338eda45a663b685b15dba1f69c56854363543b12a32b45cdb27

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'test_helper'

class ResetPasswordTest < ActiveSupport::TestCase
  setup do
    @user = users(:julien)
  end

  test "generate reset password token" do
    assert @user.generate_reset_password_token!
    assert @user.persisted?
    refute_nil @user.reset_password_token
    refute_nil @user.reset_password_sent_at
  end

  test "reset password" do
    assert @user.generate_reset_password_token!
    assert @user.reset_password!('password' => "azerty", 'password_confirmation' => "azerty")
    assert @user.persisted?
    assert_nil @user.reset_password_token
    assert_nil @user.reset_password_sent_at
    assert @user.valid_password?("azerty")
  end

  test "should find user with token" do
    @user.generate_reset_password_token!
    user = User.find_for_password_reset(@user.reset_password_token)
    assert_equal @user, user
    refute_nil user.reset_password_token
    refute_nil user.reset_password_sent_at
  end

  test "should not find user with bad tokens" do
    assert_nil User.find_for_password_reset(nil)
    assert_nil User.find_for_password_reset("ariualfknsmgojqm")
  end

  test "token expiration" do
    @user.generate_reset_password_token!
    @user.update_attribute(:reset_password_sent_at, 1.week.ago)
    assert_nil User.find_for_password_reset(@user.reset_password_token)
    @user.reload
    assert_nil @user.reset_password_token
    assert_nil @user.reset_password_sent_at
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
janus-0.10.1 test/unit/reset_password_test.rb
janus-0.10.0 test/unit/reset_password_test.rb