Added scoped views support. Just turn it on in your Devise.setup.
This commit is contained in:
parent
d5049240e2
commit
415bcdc722
|
@ -1,5 +1,6 @@
|
|||
* enhancements
|
||||
* [#42] Do not send nil to build (DataMapper compatibility)
|
||||
* [#44] Allow to have scoped views
|
||||
|
||||
== 0.5.5
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ class ConfirmationsController < ApplicationController
|
|||
# GET /resource/confirmation/new
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/confirmation
|
||||
|
@ -14,7 +15,7 @@ class ConfirmationsController < ApplicationController
|
|||
set_flash_message :success, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
else
|
||||
render :new
|
||||
render_with_scope :new
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -26,7 +27,7 @@ class ConfirmationsController < ApplicationController
|
|||
set_flash_message :success, :confirmed
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
else
|
||||
render :new
|
||||
render_with_scope :new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,7 @@ class PasswordsController < ApplicationController
|
|||
# GET /resource/password/new
|
||||
def new
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/password
|
||||
|
@ -16,7 +17,7 @@ class PasswordsController < ApplicationController
|
|||
set_flash_message :success, :send_instructions
|
||||
redirect_to new_session_path(resource_name)
|
||||
else
|
||||
render :new
|
||||
render_with_scope :new
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -24,6 +25,7 @@ class PasswordsController < ApplicationController
|
|||
def edit
|
||||
self.resource = resource_class.new
|
||||
resource.reset_password_token = params[:reset_password_token]
|
||||
render_with_scope :edit
|
||||
end
|
||||
|
||||
# PUT /resource/password
|
||||
|
@ -34,7 +36,7 @@ class PasswordsController < ApplicationController
|
|||
set_flash_message :success, :updated
|
||||
sign_in_and_redirect(resource_name, resource)
|
||||
else
|
||||
render :edit
|
||||
render_with_scope :edit
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,7 @@ class SessionsController < ApplicationController
|
|||
set_now_flash_message :failure, message if params.try(:[], message) == "true"
|
||||
end
|
||||
build_resource
|
||||
render_with_scope :new
|
||||
end
|
||||
|
||||
# POST /resource/sign_in
|
||||
|
@ -19,7 +20,7 @@ class SessionsController < ApplicationController
|
|||
else
|
||||
set_now_flash_message :failure, warden.message || :invalid
|
||||
build_resource
|
||||
render :new
|
||||
render_with_scope :new
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ Devise.setup do |config|
|
|||
# Configure the ORM. Supports :active_record and :mongo_mapper
|
||||
# config.orm = :active_record
|
||||
|
||||
# Turn scoped views on. Before rendering "sessions/new", it will first check for
|
||||
# "sessions/users/new". It's turned off by default because it's slower if you
|
||||
# are using only default views.
|
||||
# config.scoped_views = true
|
||||
|
||||
# If you want to use other strategies, that are not (yet) supported by Devise,
|
||||
# you can configure them inside the config.warden block. The example below
|
||||
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
||||
|
|
|
@ -73,6 +73,11 @@ module Devise
|
|||
mattr_accessor :apply_schema
|
||||
@@apply_schema = true
|
||||
|
||||
# Scoped views. Since it relies on fallbacks to render default views, it's
|
||||
# turned off by default.
|
||||
mattr_accessor :scoped_views
|
||||
@@scoped_views = false
|
||||
|
||||
class << self
|
||||
# Default way to setup Devise. Run script/generate devise_install to create
|
||||
# a fresh initializer with all configuration values.
|
||||
|
|
|
@ -96,6 +96,19 @@ module Devise
|
|||
set_flash_message(key, kind, true)
|
||||
end
|
||||
|
||||
# Render a view for the specified scope. Turned off by default.
|
||||
def render_with_scope(action)
|
||||
if Devise.scoped_views
|
||||
begin
|
||||
render :template => "sessions/#{devise_mapping.as}/#{action}"
|
||||
rescue ActionView::MissingTemplate
|
||||
render action
|
||||
end
|
||||
else
|
||||
render action
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,6 +44,7 @@ module ActionController::Routing
|
|||
# POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
|
||||
#
|
||||
# You can configure your routes with some options:
|
||||
#
|
||||
# * :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
|
||||
#
|
||||
# map.devise_for :users, :class_name => 'Account'
|
||||
|
|
|
@ -191,7 +191,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|||
visit 'users/index'
|
||||
assert_equal "Cart", @controller.user_session[:cart]
|
||||
end
|
||||
|
||||
|
||||
test 'destroyed account is logged out' do
|
||||
sign_in_as_user
|
||||
visit 'users/index'
|
||||
|
@ -199,4 +199,29 @@ class AuthenticationTest < ActionController::IntegrationTest
|
|||
visit 'users/index'
|
||||
assert_redirected_to '/users/sign_in?unauthenticated=true'
|
||||
end
|
||||
|
||||
test 'renders the scoped view if turned on and view is available' do
|
||||
swap Devise, :scoped_views => true do
|
||||
assert_raise Webrat::NotFoundError do
|
||||
sign_in_as_user
|
||||
end
|
||||
assert_match /Special user view/, response.body
|
||||
end
|
||||
end
|
||||
|
||||
test 'does not render the scoped view if turned off' do
|
||||
swap Devise, :scoped_views => false do
|
||||
assert_nothing_raised do
|
||||
sign_in_as_user
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test 'does not render the scoped view if not available' do
|
||||
swap Devise, :scoped_views => true do
|
||||
assert_nothing_raised do
|
||||
sign_in_as_admin
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Special user view
|
Loading…
Reference in New Issue