mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Devise now allows you to have custom controlleers. Check the README for more information.
This commit is contained in:
@@ -134,9 +134,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
end
|
||||
|
||||
test 'error message is configurable by resource name' do
|
||||
store_translations :en, :devise => {
|
||||
:sessions => { :admin => { :invalid => "Invalid credentials" } }
|
||||
} do
|
||||
store_translations :en, :devise => { :sessions => { :admin => { :invalid => "Invalid credentials" } } } do
|
||||
sign_in_as_admin do
|
||||
fill_in 'password', :with => 'abcdef'
|
||||
end
|
||||
@@ -210,6 +208,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
assert_equal "Cart", @controller.user_session[:cart]
|
||||
end
|
||||
|
||||
# Scoped views
|
||||
test 'renders the scoped view if turned on and view is available' do
|
||||
swap Devise, :scoped_views => true do
|
||||
assert_raise Webrat::NotFoundError do
|
||||
@@ -249,6 +248,24 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
end
|
||||
end
|
||||
|
||||
# Default scope
|
||||
test 'uses the mapping from the default scope if specified' do
|
||||
swap Devise, :use_default_scope => true do
|
||||
get '/sign_in'
|
||||
assert_response :ok
|
||||
assert_contain 'Sign in'
|
||||
end
|
||||
end
|
||||
|
||||
# Custom controller
|
||||
test 'uses the custom controller with the custom controller view' do
|
||||
get '/admin_area/sign_in'
|
||||
assert_contain 'Sign in'
|
||||
assert_contain 'Welcome to "sessions" controller!'
|
||||
assert_contain 'Welcome to "sessions/new" view!'
|
||||
end
|
||||
|
||||
# Access
|
||||
test 'render 404 on roles without permission' do
|
||||
get '/admin_area/password/new', {}, "action_dispatch.show_exceptions" => true
|
||||
assert_response :not_found
|
||||
@@ -260,12 +277,4 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||
assert_response :not_found
|
||||
assert_not_contain 'Sign in'
|
||||
end
|
||||
|
||||
test 'uses the mapping from the default scope if specified' do
|
||||
swap Devise, :use_default_scope => true do
|
||||
get '/sign_in'
|
||||
assert_response :ok
|
||||
assert_contain 'Sign in'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
6
test/rails_app/app/controllers/sessions_controller.rb
Normal file
6
test/rails_app/app/controllers/sessions_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
class SessionsController < Devise::SessionsController
|
||||
def new
|
||||
flash[:notice] = "Welcome to #{controller_path.inspect} controller!"
|
||||
super
|
||||
end
|
||||
end
|
||||
2
test/rails_app/app/views/sessions/new.html.erb
Normal file
2
test/rails_app/app/views/sessions/new.html.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
Welcome to "sessions/new" view!
|
||||
<%= render :file => "devise/sessions/new" %>
|
||||
@@ -3,18 +3,19 @@ Rails::Application.routes.draw do
|
||||
get :expire, :on => :member
|
||||
end
|
||||
|
||||
resources :admins, :only => [:index]
|
||||
|
||||
devise_for :users
|
||||
devise_for :admin, :as => 'admin_area'
|
||||
devise_for :accounts, :scope => 'manager', :path_prefix => ':locale',
|
||||
devise_for :admin, :as => "admin_area", :controllers => { :sessions => "sessions" }
|
||||
devise_for :accounts, :scope => "manager", :path_prefix => ":locale",
|
||||
:class_name => "User", :path_names => {
|
||||
:sign_in => 'login', :sign_out => 'logout',
|
||||
:password => 'secret', :confirmation => 'verification',
|
||||
:unlock => 'unblock', :sign_up => 'register'
|
||||
:sign_in => "login", :sign_out => "logout",
|
||||
:password => "secret", :confirmation => "verification",
|
||||
:unlock => "unblock", :sign_up => "register"
|
||||
}
|
||||
|
||||
resources :admins, :only => [:index]
|
||||
root :to => "home#index"
|
||||
match "/admin_area/home", :to => "admins#index", :as => :admin_root
|
||||
match "/sign_in", :to => "devise/sessions#new"
|
||||
|
||||
match '/admin_area/home', :to => "admins#index", :as => :admin_root
|
||||
match '/sign_in', :to => "devise/sessions#new"
|
||||
end
|
||||
root :to => "home#index"
|
||||
end
|
||||
@@ -74,8 +74,12 @@ class MapRoutingTest < ActionController::TestCase
|
||||
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
||||
end
|
||||
|
||||
test 'map admin session with :as option' do
|
||||
assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
|
||||
test 'map admin with :as option' do
|
||||
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get})
|
||||
end
|
||||
|
||||
test 'map admin with :controllers option' do
|
||||
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
|
||||
end
|
||||
|
||||
test 'does not map admin confirmation' do
|
||||
|
||||
Reference in New Issue
Block a user