From 198167d978c58c4b6588999844602eb56c74403f Mon Sep 17 00:00:00 2001 From: "Carlos A. da Silva" Date: Sat, 10 Oct 2009 18:07:25 -0300 Subject: [PATCH] Removing default mapping and Updating tests at all --- .../confirmation_instructions.html.erb | 2 +- .../reset_password_instructions.html.erb | 2 +- lib/devise.rb | 3 --- test/controllers/resources_test.rb | 20 +++++++++---------- test/map_test.rb | 15 -------------- test/models/authenticable_test.rb | 2 +- test/models/confirmable_test.rb | 2 +- test/models/perishable_test.rb | 2 +- test/models/recoverable_test.rb | 2 +- test/models/validatable_test.rb | 2 +- .../app/controllers/admins_controller.rb | 6 ++++++ .../app/controllers/application_controller.rb | 4 +--- .../app/controllers/users_controller.rb | 6 ++++++ test/rails_app/app/models/account.rb | 3 --- test/rails_app/app/models/admin.rb | 3 +++ .../rails_app/app/views/admins/index.html.erb | 1 + test/rails_app/app/views/home/index.html.erb | 2 +- test/rails_app/app/views/users/index.html.erb | 1 + test/rails_app/config/initializers/devise.rb | 4 ++-- test/rails_app/config/routes.rb | 3 ++- test/routes/confirmation_routing_test.rb | 14 ++++++------- test/routes/map_routing_test.rb | 12 +++++------ test/routes/password_routing_test.rb | 18 ++++++++--------- test/routes/session_routing_test.rb | 14 ++++++------- test/test_helper.rb | 2 +- 25 files changed, 70 insertions(+), 75 deletions(-) create mode 100644 test/rails_app/app/controllers/admins_controller.rb create mode 100644 test/rails_app/app/controllers/users_controller.rb delete mode 100644 test/rails_app/app/models/account.rb create mode 100644 test/rails_app/app/models/admin.rb create mode 100644 test/rails_app/app/views/admins/index.html.erb create mode 100644 test/rails_app/app/views/users/index.html.erb diff --git a/app/views/notifier/confirmation_instructions.html.erb b/app/views/notifier/confirmation_instructions.html.erb index 83b21ccb..5af97418 100644 --- a/app/views/notifier/confirmation_instructions.html.erb +++ b/app/views/notifier/confirmation_instructions.html.erb @@ -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) %> diff --git a/app/views/notifier/reset_password_instructions.html.erb b/app/views/notifier/reset_password_instructions.html.erb index baf5f780..cf3a0a87 100644 --- a/app/views/notifier/reset_password_instructions.html.erb +++ b/app/views/notifier/reset_password_instructions.html.erb @@ -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. diff --git a/lib/devise.rb b/lib/devise.rb index fcb78874..12c6dfee 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -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 diff --git a/test/controllers/resources_test.rb b/test/controllers/resources_test.rb index 3202266a..3f47db76 100644 --- a/test/controllers/resources_test.rb +++ b/test/controllers/resources_test.rb @@ -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 diff --git a/test/map_test.rb b/test/map_test.rb index 35085c1a..03e65e05 100644 --- a/test/map_test.rb +++ b/test/map_test.rb @@ -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] diff --git a/test/models/authenticable_test.rb b/test/models/authenticable_test.rb index e69e58df..8cd4578e 100644 --- a/test/models/authenticable_test.rb +++ b/test/models/authenticable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'test/test_helper' require 'digest/sha1' class AuthenticableTest < ActiveSupport::TestCase diff --git a/test/models/confirmable_test.rb b/test/models/confirmable_test.rb index 1dde058b..a62a306b 100644 --- a/test/models/confirmable_test.rb +++ b/test/models/confirmable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'test/test_helper' class ConfirmableTest < ActiveSupport::TestCase diff --git a/test/models/perishable_test.rb b/test/models/perishable_test.rb index 1fd0926b..4342e316 100644 --- a/test/models/perishable_test.rb +++ b/test/models/perishable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'test/test_helper' class PerishableTest < ActiveSupport::TestCase diff --git a/test/models/recoverable_test.rb b/test/models/recoverable_test.rb index 9eba0e47..55fa2613 100644 --- a/test/models/recoverable_test.rb +++ b/test/models/recoverable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'test/test_helper' class RecoverableTest < ActiveSupport::TestCase diff --git a/test/models/validatable_test.rb b/test/models/validatable_test.rb index ca4c9f5d..ffa6448c 100644 --- a/test/models/validatable_test.rb +++ b/test/models/validatable_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'test/test_helper' class ValidatableTest < ActiveSupport::TestCase diff --git a/test/rails_app/app/controllers/admins_controller.rb b/test/rails_app/app/controllers/admins_controller.rb new file mode 100644 index 00000000..c2d68742 --- /dev/null +++ b/test/rails_app/app/controllers/admins_controller.rb @@ -0,0 +1,6 @@ +class AdminsController < ApplicationController + before_filter :admin_authenticate! + + def index + end +end diff --git a/test/rails_app/app/controllers/application_controller.rb b/test/rails_app/app/controllers/application_controller.rb index e4604cf3..dc35335f 100644 --- a/test/rails_app/app/controllers/application_controller.rb +++ b/test/rails_app/app/controllers/application_controller.rb @@ -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 diff --git a/test/rails_app/app/controllers/users_controller.rb b/test/rails_app/app/controllers/users_controller.rb new file mode 100644 index 00000000..881a860a --- /dev/null +++ b/test/rails_app/app/controllers/users_controller.rb @@ -0,0 +1,6 @@ +class UsersController < ApplicationController + before_filter :user_authenticate! + + def index + end +end diff --git a/test/rails_app/app/models/account.rb b/test/rails_app/app/models/account.rb deleted file mode 100644 index cac9a24f..00000000 --- a/test/rails_app/app/models/account.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Account < ActiveRecord::Base - devise :all -end diff --git a/test/rails_app/app/models/admin.rb b/test/rails_app/app/models/admin.rb new file mode 100644 index 00000000..3a87055c --- /dev/null +++ b/test/rails_app/app/models/admin.rb @@ -0,0 +1,3 @@ +class Admin < ActiveRecord::Base + devise :all +end diff --git a/test/rails_app/app/views/admins/index.html.erb b/test/rails_app/app/views/admins/index.html.erb new file mode 100644 index 00000000..798119e9 --- /dev/null +++ b/test/rails_app/app/views/admins/index.html.erb @@ -0,0 +1 @@ +Welcome Admin! diff --git a/test/rails_app/app/views/home/index.html.erb b/test/rails_app/app/views/home/index.html.erb index 980a0d5f..c3942a09 100644 --- a/test/rails_app/app/views/home/index.html.erb +++ b/test/rails_app/app/views/home/index.html.erb @@ -1 +1 @@ -Hello World! +Home! diff --git a/test/rails_app/app/views/users/index.html.erb b/test/rails_app/app/views/users/index.html.erb new file mode 100644 index 00000000..93b6afc3 --- /dev/null +++ b/test/rails_app/app/views/users/index.html.erb @@ -0,0 +1 @@ +Welcome User! diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index 5271325d..9b237014 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -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' diff --git a/test/rails_app/config/routes.rb b/test/rails_app/config/routes.rb index de50e7f9..08e8fade 100644 --- a/test/rails_app/config/routes.rb +++ b/test/rails_app/config/routes.rb @@ -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 diff --git a/test/routes/confirmation_routing_test.rb b/test/routes/confirmation_routing_test.rb index ef7f2c9a..72643b13 100644 --- a/test/routes/confirmation_routing_test.rb +++ b/test/routes/confirmation_routing_test.rb @@ -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 diff --git a/test/routes/map_routing_test.rb b/test/routes/map_routing_test.rb index 5f486111..819faa16 100644 --- a/test/routes/map_routing_test.rb +++ b/test/routes/map_routing_test.rb @@ -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 diff --git a/test/routes/password_routing_test.rb b/test/routes/password_routing_test.rb index 415bd4bf..6c0dd6c0 100644 --- a/test/routes/password_routing_test.rb +++ b/test/routes/password_routing_test.rb @@ -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 diff --git a/test/routes/session_routing_test.rb b/test/routes/session_routing_test.rb index cd2c36bb..4bc72571 100644 --- a/test/routes/session_routing_test.rb +++ b/test/routes/session_routing_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 93fa3e60..ab6d493f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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