mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-06 03:01:21 -04:00
More specs.
This commit is contained in:
@@ -98,15 +98,13 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
assert_not warden.authenticated?(:admin)
|
||||
end
|
||||
|
||||
test 'already confirmed admin should be able to sign in successfully' do
|
||||
test 'authenticated admin should not be able to sign as admin again' do
|
||||
sign_in_as_admin
|
||||
get new_admin_session_path
|
||||
|
||||
assert_response :success
|
||||
assert_template 'home/index'
|
||||
assert_contain 'Signed in successfully'
|
||||
assert_not_contain 'Sign In'
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
assert warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'authenticated admin should be able to sign out' do
|
||||
@@ -131,7 +129,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
assert_not_contain 'Signed out successfully'
|
||||
end
|
||||
|
||||
test 'redirect from warden show error message' do
|
||||
test 'redirect with warden show error message' do
|
||||
get admins_path
|
||||
|
||||
warden_path = new_admin_session_path(:unauthenticated => true)
|
||||
@@ -142,7 +140,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
end
|
||||
|
||||
test 'render 404 on roles without permission' do
|
||||
get "users/password/new"
|
||||
get "admin_area/password/new"
|
||||
assert_response :not_found
|
||||
assert_not_contain 'Send me reset password instructions'
|
||||
end
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
require 'test/test_helper'
|
||||
|
||||
class AdminsConfirmationTest < ActionController::IntegrationTest
|
||||
class UsersConfirmationTest < ActionController::IntegrationTest
|
||||
|
||||
test 'admin should be able to request a new confirmation' do
|
||||
admin = create_admin
|
||||
test 'user should be able to request a new confirmation' do
|
||||
user = create_user
|
||||
ActionMailer::Base.deliveries.clear
|
||||
|
||||
visit new_admin_session_path
|
||||
visit new_user_session_path
|
||||
click_link 'Didn\'t receive confirmation instructions?'
|
||||
|
||||
fill_in 'email', :with => admin.email
|
||||
fill_in 'email', :with => user.email
|
||||
click_button 'Resend confirmation instructions'
|
||||
|
||||
assert_template 'sessions/new'
|
||||
@@ -17,7 +17,7 @@ class AdminsConfirmationTest < ActionController::IntegrationTest
|
||||
assert_equal 1, ActionMailer::Base.deliveries.size
|
||||
end
|
||||
|
||||
test 'admin with invalid perishable token should not be able to confirm an account' do
|
||||
test 'user with invalid perishable token should not be able to confirm an account' do
|
||||
visit user_confirmation_path(:perishable_token => 'invalid_perishable')
|
||||
|
||||
assert_response :success
|
||||
@@ -26,21 +26,21 @@ class AdminsConfirmationTest < ActionController::IntegrationTest
|
||||
assert_contain 'invalid confirmation'
|
||||
end
|
||||
|
||||
test 'admin with valid perishable token should be able to confirm an account' do
|
||||
admin = create_admin(:confirm => false)
|
||||
assert_not admin.confirmed?
|
||||
test 'user with valid perishable token should be able to confirm an account' do
|
||||
user = create_user(:confirm => false)
|
||||
assert_not user.confirmed?
|
||||
|
||||
visit admin_confirmation_path(:perishable_token => admin.perishable_token)
|
||||
visit user_confirmation_path(:perishable_token => user.perishable_token)
|
||||
|
||||
assert_template 'sessions/new'
|
||||
assert_contain 'Your account was successfully confirmed!'
|
||||
|
||||
assert admin.reload.confirmed?
|
||||
assert user.reload.confirmed?
|
||||
end
|
||||
|
||||
test 'admin already confirmed user should not be able to confirm the account again' do
|
||||
admin = create_admin
|
||||
visit admin_confirmation_path(:perishable_token => admin.perishable_token)
|
||||
test 'user already confirmed user should not be able to confirm the account again' do
|
||||
user = create_user
|
||||
visit user_confirmation_path(:perishable_token => user.perishable_token)
|
||||
|
||||
assert_template 'confirmations/new'
|
||||
assert_have_selector '#errorExplanation'
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require 'test/test_helper'
|
||||
|
||||
class AdminsPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
class UsersPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
|
||||
def visit_new_password_path
|
||||
visit new_admin_session_path
|
||||
visit new_user_session_path
|
||||
click_link 'Forgot password?'
|
||||
end
|
||||
|
||||
@@ -12,15 +12,15 @@ class AdminsPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
|
||||
assert_response :success
|
||||
assert_template 'passwords/new'
|
||||
assert_not warden.authenticated?(:admin)
|
||||
assert_not warden.authenticated?(:user)
|
||||
|
||||
fill_in 'email', :with => 'admin@test.com'
|
||||
fill_in 'email', :with => 'user@test.com'
|
||||
yield if block_given?
|
||||
click_button 'Send me reset password instructions'
|
||||
end
|
||||
|
||||
def reset_password(options={}, &block)
|
||||
visit edit_admin_password_path(:perishable_token => options[:perishable_token])
|
||||
visit edit_user_password_path(:perishable_token => options[:perishable_token])
|
||||
assert_response :success
|
||||
assert_template 'passwords/edit'
|
||||
|
||||
@@ -30,25 +30,25 @@ class AdminsPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
click_button 'Change my password'
|
||||
end
|
||||
|
||||
test 'authenticated admin should not be able to visit forgot password page' do
|
||||
sign_in_as_admin
|
||||
assert warden.authenticated?(:admin)
|
||||
test 'authenticated user should not be able to visit forgot password page' do
|
||||
sign_in_as_user
|
||||
assert warden.authenticated?(:user)
|
||||
|
||||
get new_admin_password_path
|
||||
get new_user_password_path
|
||||
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
end
|
||||
|
||||
test 'not authenticated admin should be able to request a forgot password' do
|
||||
create_admin
|
||||
test 'not authenticated user should be able to request a forgot password' do
|
||||
create_user
|
||||
request_forgot_password
|
||||
|
||||
assert_template 'sessions/new'
|
||||
assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
|
||||
end
|
||||
|
||||
test 'not authenticated admin with invalid email should receive an error message' do
|
||||
test 'not authenticated user with invalid email should receive an error message' do
|
||||
request_forgot_password do
|
||||
fill_in 'email', :with => 'invalid.test@test.com'
|
||||
end
|
||||
@@ -59,30 +59,30 @@ class AdminsPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
assert_contain 'Email not found'
|
||||
end
|
||||
|
||||
test 'authenticated admin should not be able to visit edit password page' do
|
||||
sign_in_as_admin
|
||||
test 'authenticated user should not be able to visit edit password page' do
|
||||
sign_in_as_user
|
||||
|
||||
get edit_admin_password_path
|
||||
get edit_user_password_path
|
||||
|
||||
assert_response :redirect
|
||||
assert_redirected_to root_path
|
||||
assert warden.authenticated?(:admin)
|
||||
assert warden.authenticated?(:user)
|
||||
end
|
||||
|
||||
test 'not authenticated admin with invalid perishable token should not be able to change his password' do
|
||||
admin = create_admin
|
||||
test 'not authenticated user with invalid perishable token should not be able to change his password' do
|
||||
user = create_user
|
||||
reset_password :perishable_token => 'invalid_perishable'
|
||||
|
||||
assert_response :success
|
||||
assert_template 'passwords/edit'
|
||||
assert_have_selector '#errorExplanation'
|
||||
assert_contain 'invalid confirmation'
|
||||
assert_not admin.reload.valid_password?('987654321')
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
end
|
||||
|
||||
test 'not authenticated admin with valid perisable token but invalid password should not be able to change his password' do
|
||||
admin = create_admin
|
||||
reset_password :perishable_token => admin.perishable_token do
|
||||
test 'not authenticated user with valid perisable token but invalid password should not be able to change his password' do
|
||||
user = create_user
|
||||
reset_password :perishable_token => user.perishable_token do
|
||||
fill_in 'Password confirmation', :with => 'other_password'
|
||||
end
|
||||
|
||||
@@ -90,15 +90,15 @@ class AdminsPasswordRecoveryTest < ActionController::IntegrationTest
|
||||
assert_template 'passwords/edit'
|
||||
assert_have_selector '#errorExplanation'
|
||||
assert_contain 'Password doesn\'t match confirmation'
|
||||
assert_not admin.reload.valid_password?('987654321')
|
||||
assert_not user.reload.valid_password?('987654321')
|
||||
end
|
||||
|
||||
test 'not authenticated admin with valid data should be able to change his password' do
|
||||
admin = create_admin
|
||||
reset_password :perishable_token => admin.perishable_token
|
||||
test 'not authenticated user with valid data should be able to change his password' do
|
||||
user = create_user
|
||||
reset_password :perishable_token => user.perishable_token
|
||||
|
||||
assert_template 'sessions/new'
|
||||
assert_contain 'Your password was changed successfully.'
|
||||
assert admin.reload.valid_password?('987654321')
|
||||
assert user.reload.valid_password?('987654321')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -49,4 +49,15 @@ class MapTest < ActiveSupport::TestCase
|
||||
assert Devise.mappings[:participant].allows?(:confirmations)
|
||||
assert_not Devise.mappings[:participant].allows?(:passwords)
|
||||
end
|
||||
|
||||
test 'return mapping by path' do
|
||||
Devise.map :participant, :for => [:authenticable, :confirmable]
|
||||
assert_equal Devise.mappings[:participant], Devise.find_mapping_by_path("/participants/session")
|
||||
assert_nil Devise.find_mapping_by_path("/foo/bar")
|
||||
end
|
||||
|
||||
test 'return mapping by customized path' do
|
||||
Devise.map :participant, :for => [:authenticable, :confirmable], :as => "participantes"
|
||||
assert_equal Devise.mappings[:participant], Devise.find_mapping_by_path("/participantes/session")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
Devise.map :user, :for => [:authenticable, :confirmable, :validatable]
|
||||
Devise.map :admin, :for => [:authenticable, :recoverable, :confirmable, :validatable], :as => 'admin_area'
|
||||
Devise.map :user, :for => [:authenticable, :recoverable, :confirmable, :validatable]
|
||||
Devise.map :admin, :for => [:authenticable, :confirmable, :validatable], :as => 'admin_area'
|
||||
|
||||
@@ -23,6 +23,8 @@ class MapRoutingTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'map devise admin password with :as option' do
|
||||
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'admin_area/password/new')
|
||||
assert_raise ActionController::RoutingError do
|
||||
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'admin_area/password/new')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user