1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Removing default mapping and Updating tests at all

This commit is contained in:
Carlos A. da Silva 2009-10-10 18:07:25 -03:00
parent 561833e060
commit 198167d978
25 changed files with 70 additions and 75 deletions

View file

@ -2,4 +2,4 @@ Welcome <%= @user.email %>!
You can confirm your account through the link below:
<%= link_to 'Confirm my account', confirmation_url(@user, :perishable_token => @user.perishable_token) %>
<%#= link_to 'Confirm my account', confirmation_url(@user, :perishable_token => @user.perishable_token) %>

View file

@ -2,7 +2,7 @@ Hello <%= @user.email %>!
Someone has requested a link to change your password, and you can do this through the link below.
<%= link_to 'Change my password', edit_password_url(@user, :perishable_token => @user.perishable_token) %>
<%#= link_to 'Change my password', edit_password_url(@user, :perishable_token => @user.perishable_token) %>
If you didn't request this, please ignore this email.
Your password won't change until you access the link above and create a new one.

View file

@ -42,7 +42,6 @@ module Devise
options.assert_valid_keys(:to, :for, :as)
mapping = mapping.to_s.singularize.to_sym
mappings[mapping] = Mapping.new(options.merge(:resource => mapping))
mappings.default = mapping if mappings.default.nil?
end
def self.find_mapping(map)
@ -52,8 +51,6 @@ module Devise
mappings[map_sym]
elsif mapping = mappings.detect{|m, options| options[:as] == map}.try(:first)
mappings[mapping]
else
mappings[mappings.default]
end
end

View file

@ -9,8 +9,8 @@ class ResourcesTest < ActionController::TestCase
end
test 'get translated resource name from request path' do
@request.path = '/conta/session'
assert_equal 'account', @controller.resource_name
@request.path = '/admin_area/session'
assert_equal 'admin', @controller.resource_name
end
test 'get resource class from request path' do
@ -19,16 +19,16 @@ class ResourcesTest < ActionController::TestCase
end
test 'get resource ivar from request path' do
@request.path = '/conta/session'
@controller.instance_variable_set(:@account, account = Account.new)
assert_equal account, @controller.resource
assert_equal account, @controller.instance_variable_get(:@resource)
@request.path = '/admin_area/session'
@controller.instance_variable_set(:@admin, admin = Admin.new)
assert_equal admin, @controller.resource
assert_equal admin, @controller.instance_variable_get(:@resource)
end
test 'set resource ivar from request path' do
@request.path = '/conta/session'
@controller.resource = account = @controller.resource_class.new
assert_equal account, @controller.resource
assert_equal account, @controller.instance_variable_get(:@resource)
@request.path = '/admin_area/session'
@controller.resource = admin = @controller.resource_class.new
assert_equal admin, @controller.resource
assert_equal admin, @controller.instance_variable_get(:@resource)
end
end

View file

@ -35,15 +35,6 @@ class MapTest < ActiveSupport::TestCase
end
end
test 'set the first mapping as default' do
Devise.mappings.default = nil
assert_nil Devise.mappings.default
Devise.map :participants, :for => [:authenticable]
assert_equal :participant, Devise.mappings.default
Devise.map :organizers, :for => [:authenticable]
assert_equal :participant, Devise.mappings.default
end
test 'singularize map' do
Devise.map :participants, :for => [:authenticable]
assert_not_nil Devise.mappings[:participant]
@ -69,12 +60,6 @@ class MapTest < ActiveSupport::TestCase
assert_equal :participant, Devise.find_mapping('usuarios').resource
end
test 'find mapping should return default map in no one is found or empty is given' do
Devise.map :participants, :for => [:authenticable]
assert_equal :participant, Devise.find_mapping('test_drive').resource
assert_equal :participant, Devise.find_mapping(nil).resource
end
test 'find mapping receiving a path should split it' do
Devise.map :participants, :for => [:authenticable]
Devise.map :organizer, :for => [:authenticable]

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
require 'digest/sha1'
class AuthenticableTest < ActiveSupport::TestCase

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class ConfirmableTest < ActiveSupport::TestCase

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class PerishableTest < ActiveSupport::TestCase

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class RecoverableTest < ActiveSupport::TestCase

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class ValidatableTest < ActiveSupport::TestCase

View file

@ -0,0 +1,6 @@
class AdminsController < ApplicationController
before_filter :admin_authenticate!
def index
end
end

View file

@ -6,7 +6,5 @@ class ApplicationController < ActionController::Base
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
before_filter :authenticate!
filter_parameter_logging :password
end

View file

@ -0,0 +1,6 @@
class UsersController < ApplicationController
before_filter :user_authenticate!
def index
end
end

View file

@ -1,3 +0,0 @@
class Account < ActiveRecord::Base
devise :all
end

View file

@ -0,0 +1,3 @@
class Admin < ActiveRecord::Base
devise :all
end

View file

@ -0,0 +1 @@
Welcome Admin!

View file

@ -1 +1 @@
Hello World!
Home!

View file

@ -0,0 +1 @@
Welcome User!

View file

@ -1,2 +1,2 @@
Devise.map :users, :to => User, :for => [:authenticable, :recoverable, :confirmable]
Devise.map :account, :to => Account, :for => [:authenticable, :confirmable], :as => 'conta'
Devise.map :user, :for => [:authenticable, :recoverable, :confirmable, :validatable]
Devise.map :admin, :for => [:authenticable, :recoverable, :confirmable, :validatable], :as => 'admin_area'

View file

@ -1,4 +1,5 @@
ActionController::Routing::Routes.draw do |map|
map.resources :home, :only => :index
map.resources :users, :only => :index
map.resources :admins, :only => :index
map.root :controller => :home
end

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class ConfirmationRoutingTest < ActionController::TestCase
@ -20,15 +20,15 @@ class ConfirmationRoutingTest < ActionController::TestCase
end
end
test 'new account session route' do
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'conta/confirmation/new')
test 'new admin session route' do
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'admin_area/confirmation/new')
end
test 'create account confirmation route' do
assert_recognizes({:controller => 'confirmations', :action => 'create'}, {:path => 'conta/confirmation', :method => :post})
test 'create admin confirmation route' do
assert_recognizes({:controller => 'confirmations', :action => 'create'}, {:path => 'admin_area/confirmation', :method => :post})
end
test 'show account confirmation route' do
assert_recognizes({:controller => 'confirmations', :action => 'show'}, 'conta/confirmation')
test 'show admin confirmation route' do
assert_recognizes({:controller => 'confirmations', :action => 'show'}, 'admin_area/confirmation')
end
end

View file

@ -14,15 +14,15 @@ class MapRoutingTest < ActionController::TestCase
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'users/password/new')
end
test 'map devise account session with :as option' do
assert_recognizes({:controller => 'sessions', :action => 'new'}, 'conta/session/new')
test 'map devise admin session with :as option' do
assert_recognizes({:controller => 'sessions', :action => 'new'}, 'admin_area/session/new')
end
test 'map devise account confirmation with :as option' do
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'conta/confirmation/new')
test 'map devise admin confirmation with :as option' do
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'admin_area/confirmation/new')
end
test 'map devise account password with :as option' do
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'conta/password/new')
test 'map devise admin password with :as option' do
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'admin_area/password/new')
end
end

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class PasswordRoutingTest < ActionController::TestCase
@ -24,19 +24,19 @@ class PasswordRoutingTest < ActionController::TestCase
end
end
test 'new account password route' do
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'conta/password/new')
test 'new admin password route' do
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'admin_area/password/new')
end
test 'create account password route' do
assert_recognizes({:controller => 'passwords', :action => 'create'}, {:path => 'conta/password', :method => :post})
test 'create admin password route' do
assert_recognizes({:controller => 'passwords', :action => 'create'}, {:path => 'admin_area/password', :method => :post})
end
test 'edit account password route' do
assert_recognizes({:controller => 'passwords', :action => 'edit'}, 'conta/password/edit')
test 'edit admin password route' do
assert_recognizes({:controller => 'passwords', :action => 'edit'}, 'admin_area/password/edit')
end
test 'update account password route' do
assert_recognizes({:controller => 'passwords', :action => 'update'}, {:path => 'conta/password', :method => :put})
test 'update admin password route' do
assert_recognizes({:controller => 'passwords', :action => 'update'}, {:path => 'admin_area/password', :method => :put})
end
end

View file

@ -1,4 +1,4 @@
require 'test_helper'
require 'test/test_helper'
class SessionRoutingTest < ActionController::TestCase
@ -20,15 +20,15 @@ class SessionRoutingTest < ActionController::TestCase
end
end
test 'new account session route' do
assert_recognizes({:controller => 'sessions', :action => 'new'}, 'conta/session/new')
test 'new admin session route' do
assert_recognizes({:controller => 'sessions', :action => 'new'}, 'admin_area/session/new')
end
test 'create account session route' do
assert_recognizes({:controller => 'sessions', :action => 'create'}, {:path => 'conta/session', :method => :post})
test 'create admin session route' do
assert_recognizes({:controller => 'sessions', :action => 'create'}, {:path => 'admin_area/session', :method => :post})
end
test 'destroy account session route' do
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => 'conta/session', :method => :delete})
test 'destroy admin session route' do
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => 'admin_area/session', :method => :delete})
end
end

View file

@ -22,7 +22,7 @@ ActiveRecord::Schema.define(:version => 1) do
t.datetime :confirmed_at
end
create_table :accounts do |t|
create_table :admins do |t|
t.string :email, :null => false
t.string :encrypted_password, :null => false
t.string :password_salt, :null => false