Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Last active December 10, 2015 07:28
Show Gist options
  • Save pinzolo/8a2ac20964721c17f5ee to your computer and use it in GitHub Desktop.
Save pinzolo/8a2ac20964721c17f5ee to your computer and use it in GitHub Desktop.
確認メールの有効期限を設定した場合のテスト
require 'test_helper'
class Users::ConfirmationsControllerTest < ActionController::TestCase
setup do
@request.env['devise.mapping'] = Devise.mappings[:user]
@user = create(:user)
end
test '登録して30日以内なら確認可' do
assert_not @user.confirmed?
Time.stub(:now, @user.confirmation_sent_at + 30.days) do
get :show, confirmation_token: @user.confirmation_token
end
assert user.reload.confirmed?
end
test '登録して30日以降なら確認不可' do
assert_not @user.confirmed?
Time.stub(:now, @user.confirmation_sent_at + 30.days + 1.second) do
get :show, confirmation_token: @user.confirmation_token
end
assert_not @user.reload.confirmed?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment