devise 1.0.10 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +62 -10
- data/Gemfile +23 -0
- data/Gemfile.lock +118 -0
- data/README.rdoc +116 -77
- data/Rakefile +4 -2
- data/TODO +3 -2
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +1 -1
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +1 -1
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +12 -8
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +1 -8
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +71 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/passwords/edit.html.erb +16 -0
- data/app/views/devise/passwords/new.html.erb +12 -0
- data/app/views/devise/registrations/edit.html.erb +25 -0
- data/app/views/devise/registrations/new.html.erb +18 -0
- data/app/views/devise/sessions/new.html.erb +17 -0
- data/app/views/devise/shared/_links.erb +19 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/{lib/devise → config}/locales/en.yml +16 -12
- data/lib/devise/controllers/helpers.rb +57 -52
- data/lib/devise/controllers/internal_helpers.rb +19 -50
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/controllers/url_helpers.rb +1 -1
- data/lib/devise/encryptors/authlogic_sha512.rb +0 -2
- data/lib/devise/encryptors/base.rb +1 -1
- data/lib/devise/encryptors/bcrypt.rb +2 -4
- data/lib/devise/encryptors/clearance_sha1.rb +0 -2
- data/lib/devise/encryptors/sha1.rb +6 -8
- data/lib/devise/encryptors/sha512.rb +6 -8
- data/lib/devise/failure_app.rb +76 -39
- data/lib/devise/hooks/activatable.rb +6 -10
- data/lib/devise/hooks/forgetable.rb +11 -0
- data/lib/devise/hooks/rememberable.rb +40 -30
- data/lib/devise/hooks/timeoutable.rb +7 -3
- data/lib/devise/hooks/trackable.rb +5 -14
- data/lib/devise/mapping.rb +35 -62
- data/lib/devise/models/authenticatable.rb +126 -0
- data/lib/devise/models/confirmable.rb +19 -22
- data/lib/devise/models/database_authenticatable.rb +26 -60
- data/lib/devise/models/lockable.rb +43 -28
- data/lib/devise/models/recoverable.rb +11 -10
- data/lib/devise/models/rememberable.rb +56 -26
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +14 -43
- data/lib/devise/models/trackable.rb +14 -0
- data/lib/devise/models/validatable.rb +16 -2
- data/lib/devise/models.rb +16 -53
- data/lib/devise/modules.rb +23 -0
- data/lib/devise/orm/active_record.rb +10 -15
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +232 -117
- data/lib/devise/rails/warden_compat.rb +18 -39
- data/lib/devise/rails.rb +64 -9
- data/lib/devise/schema.rb +47 -23
- data/lib/devise/strategies/authenticatable.rb +123 -0
- data/lib/devise/strategies/base.rb +2 -3
- data/lib/devise/strategies/database_authenticatable.rb +7 -22
- data/lib/devise/strategies/rememberable.rb +21 -7
- data/lib/devise/strategies/token_authenticatable.rb +31 -19
- data/lib/devise/test_helpers.rb +6 -6
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +174 -157
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/{generators/devise → lib/generators/active_record}/templates/migration.rb +9 -3
- data/lib/generators/devise/devise_generator.rb +17 -0
- data/lib/generators/devise/install_generator.rb +24 -0
- data/lib/generators/devise/orm_helpers.rb +23 -0
- data/{generators/devise_install → lib/generators/devise}/templates/README +9 -7
- data/lib/generators/devise/templates/devise.rb +142 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/devise_install_generator.rb +4 -0
- data/lib/generators/devise_views_generator.rb +4 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/test/controllers/helpers_test.rb +48 -19
- data/test/controllers/internal_helpers_test.rb +12 -16
- data/test/controllers/url_helpers_test.rb +21 -10
- data/test/devise_test.rb +16 -25
- data/test/encryptors_test.rb +2 -3
- data/test/failure_app_test.rb +106 -27
- data/test/integration/authenticatable_test.rb +138 -126
- data/test/integration/confirmable_test.rb +22 -15
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +9 -12
- data/test/integration/lockable_test.rb +22 -15
- data/test/integration/recoverable_test.rb +6 -6
- data/test/integration/registerable_test.rb +42 -33
- data/test/integration/rememberable_test.rb +84 -22
- data/test/integration/timeoutable_test.rb +16 -4
- data/test/integration/token_authenticatable_test.rb +45 -12
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +11 -17
- data/test/mailers/reset_password_instructions_test.rb +7 -7
- data/test/mailers/unlock_instructions_test.rb +7 -7
- data/test/mapping_test.rb +22 -95
- data/test/models/confirmable_test.rb +12 -19
- data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +24 -56
- data/test/models/lockable_test.rb +32 -46
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +118 -35
- data/test/models/timeoutable_test.rb +1 -1
- data/test/models/token_authenticatable_test.rb +5 -19
- data/test/models/trackable_test.rb +1 -1
- data/test/models/validatable_test.rb +20 -27
- data/test/models_test.rb +12 -5
- data/test/orm/active_record.rb +1 -23
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +1 -5
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +2 -5
- data/test/rails_app/app/controllers/home_controller.rb +3 -0
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +2 -0
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +2 -0
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +7 -5
- data/test/rails_app/app/mongoid/admin.rb +6 -0
- data/test/rails_app/app/mongoid/shim.rb +16 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/config/application.rb +35 -0
- data/test/rails_app/config/boot.rb +10 -107
- data/test/rails_app/config/environment.rb +4 -41
- data/test/rails_app/config/environments/development.rb +15 -13
- data/test/rails_app/config/environments/production.rb +25 -20
- data/test/rails_app/config/environments/test.rb +33 -28
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +95 -38
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +47 -25
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
- data/test/rails_app/db/schema.rb +86 -0
- data/test/routes_test.rb +62 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +2 -15
- data/test/support/{tests_helper.rb → helpers.rb} +18 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +24 -7
- data/test/support/webrat/integrations/rails.rb +32 -0
- data/test/test_helper.rb +11 -11
- data/test/test_helpers_test.rb +30 -15
- metadata +105 -64
- data/app/controllers/sessions_controller.rb +0 -42
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/confirmations/new.html.erb +0 -12
- data/app/views/passwords/edit.html.erb +0 -16
- data/app/views/passwords/new.html.erb +0 -12
- data/app/views/registrations/edit.html.erb +0 -25
- data/app/views/registrations/new.html.erb +0 -17
- data/app/views/sessions/new.html.erb +0 -17
- data/app/views/shared/_devise_links.erb +0 -19
- data/app/views/unlocks/new.html.erb +0 -12
- data/generators/devise/USAGE +0 -5
- data/generators/devise/devise_generator.rb +0 -15
- data/generators/devise/lib/route_devise.rb +0 -32
- data/generators/devise/templates/model.rb +0 -9
- data/generators/devise_install/USAGE +0 -3
- data/generators/devise_install/devise_install_generator.rb +0 -15
- data/generators/devise_install/templates/devise.rb +0 -105
- data/generators/devise_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/lib/devise/models/activatable.rb +0 -16
- data/lib/devise/models/http_authenticatable.rb +0 -23
- data/lib/devise/orm/data_mapper.rb +0 -83
- data/lib/devise/orm/mongo_mapper.rb +0 -52
- data/lib/devise/strategies/http_authenticatable.rb +0 -59
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/orm/mongo_mapper.rb +0 -20
- data/test/rails_app/app/mongo_mapper/admin.rb +0 -13
- data/test/rails_app/app/mongo_mapper/user.rb +0 -14
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
- data/test/rails_app/config/initializers/session_store.rb +0 -15
- /data/app/views/{devise_mailer → devise/mailer}/confirmation_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/reset_password_instructions.html.erb +0 -0
- /data/app/views/{devise_mailer → devise/mailer}/unlock_instructions.html.erb +0 -0
|
@@ -1,25 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
Rails.application.routes.draw do
|
|
2
|
+
# Resources for testing
|
|
3
|
+
resources :users, :only => [:index] do
|
|
4
|
+
get :expire, :on => :member
|
|
5
|
+
get :accept, :on => :member
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
resources :admins, :only => [:index]
|
|
9
|
+
|
|
10
|
+
# Users scope
|
|
11
|
+
devise_for :users do
|
|
12
|
+
match "/devise_for/sign_in", :to => "devise/sessions#new"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
as :user do
|
|
16
|
+
match "/as/sign_in", :to => "devise/sessions#new"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
match "/sign_in", :to => "devise/sessions#new"
|
|
20
|
+
|
|
21
|
+
# Admin scope
|
|
22
|
+
devise_for :admin, :path => "admin_area", :controllers => { :sessions => "sessions" }, :skip => :passwords
|
|
23
|
+
|
|
24
|
+
match "/admin_area/home", :to => "admins#index", :as => :admin_root
|
|
25
|
+
match "/anywhere", :to => "foo#bar", :as => :new_admin_password
|
|
26
|
+
|
|
27
|
+
authenticate(:admin) do
|
|
28
|
+
match "/private", :to => "home#private", :as => :private
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Other routes for routing_test.rb
|
|
32
|
+
namespace :publisher, :path_names => { :sign_in => "i_don_care", :sign_out => "get_out" } do
|
|
33
|
+
devise_for :accounts, :class_name => "User", :path_names => { :sign_in => "get_in" }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
scope ":locale" do
|
|
37
|
+
devise_for :accounts, :singular => "manager", :class_name => "User",
|
|
38
|
+
:path_names => {
|
|
39
|
+
:sign_in => "login", :sign_out => "logout",
|
|
40
|
+
:password => "secret", :confirmation => "verification",
|
|
41
|
+
:unlock => "unblock", :sign_up => "register",
|
|
42
|
+
:registration => "management"
|
|
43
|
+
}
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
root :to => "home#index"
|
|
47
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
class CreateTables < ActiveRecord::Migration
|
|
2
|
+
def self.up
|
|
3
|
+
[:users, :admins, :accounts].each do |table|
|
|
4
|
+
create_table table do |t|
|
|
5
|
+
t.database_authenticatable :null => (table == :admins)
|
|
6
|
+
|
|
7
|
+
if table != :admin
|
|
8
|
+
t.string :username
|
|
9
|
+
t.confirmable
|
|
10
|
+
t.recoverable
|
|
11
|
+
t.rememberable
|
|
12
|
+
t.trackable
|
|
13
|
+
t.lockable
|
|
14
|
+
t.token_authenticatable
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
t.timestamps
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.down
|
|
23
|
+
[:users, :admins, :accounts].each do |table|
|
|
24
|
+
drop_table table
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
|
3
|
+
# then regenerate this schema definition.
|
|
4
|
+
#
|
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
9
|
+
#
|
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
|
11
|
+
|
|
12
|
+
ActiveRecord::Schema.define(:version => 20100401102949) do
|
|
13
|
+
|
|
14
|
+
create_table "accounts", :force => true do |t|
|
|
15
|
+
t.string "email", :default => "", :null => false
|
|
16
|
+
t.string "encrypted_password", :default => "", :null => false
|
|
17
|
+
t.string "password_salt", :default => "", :null => false
|
|
18
|
+
t.string "username"
|
|
19
|
+
t.string "confirmation_token"
|
|
20
|
+
t.datetime "confirmed_at"
|
|
21
|
+
t.datetime "confirmation_sent_at"
|
|
22
|
+
t.string "reset_password_token"
|
|
23
|
+
t.string "remember_token"
|
|
24
|
+
t.datetime "remember_created_at"
|
|
25
|
+
t.integer "sign_in_count", :default => 0
|
|
26
|
+
t.datetime "current_sign_in_at"
|
|
27
|
+
t.datetime "last_sign_in_at"
|
|
28
|
+
t.string "current_sign_in_ip"
|
|
29
|
+
t.string "last_sign_in_ip"
|
|
30
|
+
t.integer "failed_attempts", :default => 0
|
|
31
|
+
t.string "unlock_token"
|
|
32
|
+
t.datetime "locked_at"
|
|
33
|
+
t.string "authentication_token"
|
|
34
|
+
t.datetime "created_at"
|
|
35
|
+
t.datetime "updated_at"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
create_table "admins", :force => true do |t|
|
|
39
|
+
t.string "email", :default => ""
|
|
40
|
+
t.string "encrypted_password", :default => ""
|
|
41
|
+
t.string "password_salt", :default => ""
|
|
42
|
+
t.string "username"
|
|
43
|
+
t.string "confirmation_token"
|
|
44
|
+
t.datetime "confirmed_at"
|
|
45
|
+
t.datetime "confirmation_sent_at"
|
|
46
|
+
t.string "reset_password_token"
|
|
47
|
+
t.string "remember_token"
|
|
48
|
+
t.datetime "remember_created_at"
|
|
49
|
+
t.integer "sign_in_count", :default => 0
|
|
50
|
+
t.datetime "current_sign_in_at"
|
|
51
|
+
t.datetime "last_sign_in_at"
|
|
52
|
+
t.string "current_sign_in_ip"
|
|
53
|
+
t.string "last_sign_in_ip"
|
|
54
|
+
t.integer "failed_attempts", :default => 0
|
|
55
|
+
t.string "unlock_token"
|
|
56
|
+
t.datetime "locked_at"
|
|
57
|
+
t.string "authentication_token"
|
|
58
|
+
t.datetime "created_at"
|
|
59
|
+
t.datetime "updated_at"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
create_table "users", :force => true do |t|
|
|
63
|
+
t.string "email", :default => "", :null => false
|
|
64
|
+
t.string "encrypted_password", :default => "", :null => false
|
|
65
|
+
t.string "password_salt", :default => "", :null => false
|
|
66
|
+
t.string "username"
|
|
67
|
+
t.string "confirmation_token"
|
|
68
|
+
t.datetime "confirmed_at"
|
|
69
|
+
t.datetime "confirmation_sent_at"
|
|
70
|
+
t.string "reset_password_token"
|
|
71
|
+
t.string "remember_token"
|
|
72
|
+
t.datetime "remember_created_at"
|
|
73
|
+
t.integer "sign_in_count", :default => 0
|
|
74
|
+
t.datetime "current_sign_in_at"
|
|
75
|
+
t.datetime "last_sign_in_at"
|
|
76
|
+
t.string "current_sign_in_ip"
|
|
77
|
+
t.string "last_sign_in_ip"
|
|
78
|
+
t.integer "failed_attempts", :default => 0
|
|
79
|
+
t.string "unlock_token"
|
|
80
|
+
t.datetime "locked_at"
|
|
81
|
+
t.string "authentication_token"
|
|
82
|
+
t.datetime "created_at"
|
|
83
|
+
t.datetime "updated_at"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
end
|
data/test/routes_test.rb
CHANGED
|
@@ -1,131 +1,146 @@
|
|
|
1
|
-
require '
|
|
2
|
-
|
|
3
|
-
class MapRoutingTest < ActionController::TestCase
|
|
1
|
+
require 'test_helper'
|
|
4
2
|
|
|
3
|
+
class DefaultRoutingTest < ActionController::TestCase
|
|
5
4
|
test 'map new user session' do
|
|
6
|
-
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'users/sign_in', :method => :get})
|
|
5
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'new'}, {:path => 'users/sign_in', :method => :get})
|
|
6
|
+
assert_named_route "/users/sign_in", :new_user_session_path
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
test 'map create user session' do
|
|
10
|
-
assert_recognizes({:controller => 'sessions', :action => 'create'}, {:path => 'users/sign_in', :method => :post})
|
|
10
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'create'}, {:path => 'users/sign_in', :method => :post})
|
|
11
|
+
assert_named_route "/users/sign_in", :user_session_path
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
test 'map destroy user session' do
|
|
14
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => 'users/sign_out', :method => :get})
|
|
15
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => 'users/sign_out', :method => :get})
|
|
16
|
+
assert_named_route "/users/sign_out", :destroy_user_session_path
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
test 'map new user confirmation' do
|
|
18
|
-
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'users/confirmation/new')
|
|
20
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'new'}, 'users/confirmation/new')
|
|
21
|
+
assert_named_route "/users/confirmation/new", :new_user_confirmation_path
|
|
19
22
|
end
|
|
20
23
|
|
|
21
24
|
test 'map create user confirmation' do
|
|
22
|
-
assert_recognizes({:controller => 'confirmations', :action => 'create'}, {:path => 'users/confirmation', :method => :post})
|
|
25
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'create'}, {:path => 'users/confirmation', :method => :post})
|
|
26
|
+
assert_named_route "/users/confirmation", :user_confirmation_path
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
test 'map show user confirmation' do
|
|
26
|
-
assert_recognizes({:controller => 'confirmations', :action => 'show'}, {:path => 'users/confirmation', :method => :get})
|
|
30
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'show'}, {:path => 'users/confirmation', :method => :get})
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
test 'map new user password' do
|
|
30
|
-
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'users/password/new')
|
|
34
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'users/password/new')
|
|
35
|
+
assert_named_route "/users/password/new", :new_user_password_path
|
|
31
36
|
end
|
|
32
37
|
|
|
33
38
|
test 'map create user password' do
|
|
34
|
-
assert_recognizes({:controller => 'passwords', :action => 'create'}, {:path => 'users/password', :method => :post})
|
|
39
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'create'}, {:path => 'users/password', :method => :post})
|
|
40
|
+
assert_named_route "/users/password", :user_password_path
|
|
35
41
|
end
|
|
36
42
|
|
|
37
43
|
test 'map edit user password' do
|
|
38
|
-
assert_recognizes({:controller => 'passwords', :action => 'edit'}, 'users/password/edit')
|
|
44
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'edit'}, 'users/password/edit')
|
|
45
|
+
assert_named_route "/users/password/edit", :edit_user_password_path
|
|
39
46
|
end
|
|
40
47
|
|
|
41
48
|
test 'map update user password' do
|
|
42
|
-
assert_recognizes({:controller => 'passwords', :action => 'update'}, {:path => 'users/password', :method => :put})
|
|
49
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'update'}, {:path => 'users/password', :method => :put})
|
|
43
50
|
end
|
|
44
51
|
|
|
45
52
|
test 'map new user unlock' do
|
|
46
|
-
assert_recognizes({:controller => 'unlocks', :action => 'new'}, 'users/unlock/new')
|
|
53
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'new'}, 'users/unlock/new')
|
|
54
|
+
assert_named_route "/users/unlock/new", :new_user_unlock_path
|
|
47
55
|
end
|
|
48
56
|
|
|
49
57
|
test 'map create user unlock' do
|
|
50
|
-
assert_recognizes({:controller => 'unlocks', :action => 'create'}, {:path => 'users/unlock', :method => :post})
|
|
58
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'create'}, {:path => 'users/unlock', :method => :post})
|
|
59
|
+
assert_named_route "/users/unlock", :user_unlock_path
|
|
51
60
|
end
|
|
52
61
|
|
|
53
62
|
test 'map show user unlock' do
|
|
54
|
-
assert_recognizes({:controller => 'unlocks', :action => 'show'}, {:path => 'users/unlock', :method => :get})
|
|
63
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => 'users/unlock', :method => :get})
|
|
55
64
|
end
|
|
56
65
|
|
|
57
66
|
test 'map new user registration' do
|
|
58
|
-
assert_recognizes({:controller => 'registrations', :action => 'new'}, 'users/sign_up')
|
|
67
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, 'users/sign_up')
|
|
68
|
+
assert_named_route "/users/sign_up", :new_user_registration_path
|
|
59
69
|
end
|
|
60
70
|
|
|
61
71
|
test 'map create user registration' do
|
|
62
|
-
assert_recognizes({:controller => 'registrations', :action => 'create'}, {:path => 'users', :method => :post})
|
|
72
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'create'}, {:path => 'users', :method => :post})
|
|
73
|
+
assert_named_route "/users", :user_registration_path
|
|
63
74
|
end
|
|
64
75
|
|
|
65
76
|
test 'map edit user registration' do
|
|
66
|
-
assert_recognizes({:controller => 'registrations', :action => 'edit'}, {:path => 'users/edit', :method => :get})
|
|
77
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'edit'}, {:path => 'users/edit', :method => :get})
|
|
78
|
+
assert_named_route "/users/edit", :edit_user_registration_path
|
|
67
79
|
end
|
|
68
80
|
|
|
69
81
|
test 'map update user registration' do
|
|
70
|
-
assert_recognizes({:controller => 'registrations', :action => 'update'}, {:path => 'users', :method => :put})
|
|
82
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'update'}, {:path => 'users', :method => :put})
|
|
71
83
|
end
|
|
72
84
|
|
|
73
85
|
test 'map destroy user registration' do
|
|
74
|
-
assert_recognizes({:controller => 'registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
|
86
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
protected
|
|
90
|
+
|
|
91
|
+
def assert_named_route(result, name)
|
|
92
|
+
assert_equal result, @routes.url_helpers.send(name)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
class CustomizedRoutingTest < ActionController::TestCase
|
|
97
|
+
test 'map admin with :path option' do
|
|
98
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get})
|
|
75
99
|
end
|
|
76
100
|
|
|
77
|
-
test 'map admin
|
|
101
|
+
test 'map admin with :controllers option' do
|
|
78
102
|
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
|
|
79
103
|
end
|
|
80
104
|
|
|
81
|
-
test 'does not map admin
|
|
105
|
+
test 'does not map admin password' do
|
|
82
106
|
assert_raise ActionController::RoutingError do
|
|
83
|
-
assert_recognizes({:controller => '
|
|
107
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'admin_area/password/new')
|
|
84
108
|
end
|
|
85
109
|
end
|
|
86
110
|
|
|
87
111
|
test 'map account with custom path name for session sign in' do
|
|
88
|
-
assert_recognizes({:controller => 'sessions', :action => 'new', :locale => 'en'
|
|
112
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'new', :locale => 'en'}, '/en/accounts/login')
|
|
89
113
|
end
|
|
90
114
|
|
|
91
115
|
test 'map account with custom path name for session sign out' do
|
|
92
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy', :locale => 'en'
|
|
116
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy', :locale => 'en'}, '/en/accounts/logout')
|
|
93
117
|
end
|
|
94
118
|
|
|
95
119
|
test 'map account with custom path name for password' do
|
|
96
|
-
assert_recognizes({:controller => 'passwords', :action => 'new', :locale => 'en'
|
|
120
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new', :locale => 'en'}, '/en/accounts/secret/new')
|
|
97
121
|
end
|
|
98
122
|
|
|
99
123
|
test 'map account with custom path name for confirmation' do
|
|
100
|
-
assert_recognizes({:controller => 'confirmations', :action => 'new', :locale => 'en'
|
|
124
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'new', :locale => 'en'}, '/en/accounts/verification/new')
|
|
101
125
|
end
|
|
102
126
|
|
|
103
127
|
test 'map account with custom path name for unlock' do
|
|
104
|
-
assert_recognizes({:controller => 'unlocks', :action => 'new', :locale => 'en'
|
|
128
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'new', :locale => 'en'}, '/en/accounts/unblock/new')
|
|
105
129
|
end
|
|
106
130
|
|
|
107
131
|
test 'map account with custom path name for registration' do
|
|
108
|
-
assert_recognizes({:controller => 'registrations', :action => 'new', :locale => 'en'
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
test 'map deletes with :sign_out_via option' do
|
|
112
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => '/sign_out_via_deletes/sign_out', :method => :delete})
|
|
113
|
-
assert_raise ActionController::MethodNotAllowed do
|
|
114
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => '/sign_out_via_deletes/sign_out', :method => :get})
|
|
115
|
-
end
|
|
132
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
|
|
116
133
|
end
|
|
134
|
+
end
|
|
117
135
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
end
|
|
136
|
+
class ScopedRoutingTest < ActionController::TestCase
|
|
137
|
+
test 'map publisher account' do
|
|
138
|
+
assert_recognizes({:controller => 'publisher/registrations', :action => 'new'}, {:path => '/publisher/accounts/sign_up', :method => :get})
|
|
139
|
+
assert_equal '/publisher/accounts/sign_up', @routes.url_helpers.new_publisher_account_registration_path
|
|
123
140
|
end
|
|
124
141
|
|
|
125
|
-
test 'map
|
|
126
|
-
assert_recognizes({:controller => 'sessions', :action => '
|
|
127
|
-
|
|
128
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => '/sign_out_via_anymethods/sign_out', :method => :delete})
|
|
129
|
-
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => '/sign_out_via_anymethods/sign_out', :method => :put})
|
|
142
|
+
test 'map publisher account merges path names' do
|
|
143
|
+
assert_recognizes({:controller => 'publisher/sessions', :action => 'new'}, {:path => '/publisher/accounts/get_in', :method => :get})
|
|
144
|
+
assert_equal '/publisher/accounts/get_in', @routes.url_helpers.new_publisher_account_session_path
|
|
130
145
|
end
|
|
131
146
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'active_support/test_case'
|
|
2
|
+
|
|
1
3
|
class ActiveSupport::TestCase
|
|
2
4
|
def assert_not(assertion)
|
|
3
5
|
assert !assertion
|
|
@@ -19,19 +21,4 @@ class ActiveSupport::TestCase
|
|
|
19
21
|
def assert_email_not_sent(&block)
|
|
20
22
|
assert_no_difference('ActionMailer::Base.deliveries.size') { yield }
|
|
21
23
|
end
|
|
22
|
-
|
|
23
|
-
# Execute the block setting the given values and restoring old values after
|
|
24
|
-
# the block is executed.
|
|
25
|
-
def swap(object, new_values)
|
|
26
|
-
old_values = {}
|
|
27
|
-
new_values.each do |key, value|
|
|
28
|
-
old_values[key] = object.send key
|
|
29
|
-
object.send :"#{key}=", value
|
|
30
|
-
end
|
|
31
|
-
yield
|
|
32
|
-
ensure
|
|
33
|
-
old_values.each do |key, value|
|
|
34
|
-
object.send :"#{key}=", value
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
24
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'active_support/test_case'
|
|
2
|
+
|
|
1
3
|
class ActiveSupport::TestCase
|
|
2
4
|
VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
|
|
3
5
|
|
|
@@ -7,15 +9,13 @@ class ActiveSupport::TestCase
|
|
|
7
9
|
|
|
8
10
|
def store_translations(locale, translations, &block)
|
|
9
11
|
begin
|
|
10
|
-
I18n.backend.store_translations
|
|
12
|
+
I18n.backend.store_translations(locale, translations)
|
|
11
13
|
yield
|
|
12
14
|
ensure
|
|
13
15
|
I18n.reload!
|
|
14
16
|
end
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
# Helpers for creating new users
|
|
18
|
-
#
|
|
19
19
|
def generate_unique_email
|
|
20
20
|
@@email_count ||= 0
|
|
21
21
|
@@email_count += 1
|
|
@@ -36,4 +36,19 @@ class ActiveSupport::TestCase
|
|
|
36
36
|
def create_user(attributes={})
|
|
37
37
|
User.create!(valid_attributes(attributes))
|
|
38
38
|
end
|
|
39
|
+
|
|
40
|
+
# Execute the block setting the given values and restoring old values after
|
|
41
|
+
# the block is executed.
|
|
42
|
+
def swap(object, new_values)
|
|
43
|
+
old_values = {}
|
|
44
|
+
new_values.each do |key, value|
|
|
45
|
+
old_values[key] = object.send key
|
|
46
|
+
object.send :"#{key}=", value
|
|
47
|
+
end
|
|
48
|
+
yield
|
|
49
|
+
ensure
|
|
50
|
+
old_values.each do |key, value|
|
|
51
|
+
object.send :"#{key}=", value
|
|
52
|
+
end
|
|
53
|
+
end
|
|
39
54
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
require 'action_dispatch/testing/integration'
|
|
2
2
|
|
|
3
|
+
class ActionDispatch::IntegrationTest
|
|
3
4
|
def warden
|
|
4
5
|
request.env['warden']
|
|
5
6
|
end
|
|
@@ -30,7 +31,7 @@ class ActionController::IntegrationTest
|
|
|
30
31
|
|
|
31
32
|
def sign_in_as_user(options={}, &block)
|
|
32
33
|
user = create_user(options)
|
|
33
|
-
|
|
34
|
+
visit_with_option options[:visit], new_user_session_path
|
|
34
35
|
fill_in 'email', :with => 'user@test.com'
|
|
35
36
|
fill_in 'password', :with => options[:password] || '123456'
|
|
36
37
|
check 'remember me' if options[:remember_me] == true
|
|
@@ -41,7 +42,7 @@ class ActionController::IntegrationTest
|
|
|
41
42
|
|
|
42
43
|
def sign_in_as_admin(options={}, &block)
|
|
43
44
|
admin = create_admin(options)
|
|
44
|
-
|
|
45
|
+
visit_with_option options[:visit], new_admin_session_path
|
|
45
46
|
fill_in 'email', :with => 'admin@test.com'
|
|
46
47
|
fill_in 'password', :with => '123456'
|
|
47
48
|
yield if block_given?
|
|
@@ -56,16 +57,32 @@ class ActionController::IntegrationTest
|
|
|
56
57
|
assert [301, 302].include?(@integration_session.status),
|
|
57
58
|
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
|
58
59
|
|
|
59
|
-
url
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
assert_url url, @integration_session.headers["Location"]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def assert_current_url(expected)
|
|
64
|
+
assert_url expected, current_url
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def assert_url(expected, actual)
|
|
68
|
+
assert_equal prepend_host(expected), prepend_host(actual)
|
|
62
69
|
end
|
|
63
70
|
|
|
64
71
|
protected
|
|
65
72
|
|
|
73
|
+
def visit_with_option(given, default)
|
|
74
|
+
case given
|
|
75
|
+
when String
|
|
76
|
+
visit given
|
|
77
|
+
when FalseClass
|
|
78
|
+
# Do nothing
|
|
79
|
+
else
|
|
80
|
+
visit default
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
66
84
|
def prepend_host(url)
|
|
67
85
|
url = "http://#{request.host}#{url}" if url[0] == ?/
|
|
68
86
|
url
|
|
69
87
|
end
|
|
70
|
-
|
|
71
88
|
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'webrat/core/elements/field'
|
|
2
|
+
require 'action_dispatch/testing/integration'
|
|
3
|
+
|
|
4
|
+
module Webrat
|
|
5
|
+
Field.class_eval do
|
|
6
|
+
def parse_rails_request_params(params)
|
|
7
|
+
Rack::Utils.parse_nested_query(params)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module ActionDispatch #:nodoc:
|
|
13
|
+
IntegrationTest.class_eval do
|
|
14
|
+
include Webrat::Methods
|
|
15
|
+
include Webrat::Matchers
|
|
16
|
+
|
|
17
|
+
# The Rails version of within supports passing in a model and Webrat
|
|
18
|
+
# will apply a scope based on Rails' dom_id for that model.
|
|
19
|
+
#
|
|
20
|
+
# Example:
|
|
21
|
+
# within User.last do
|
|
22
|
+
# click_link "Delete"
|
|
23
|
+
# end
|
|
24
|
+
def within(selector_or_object, &block)
|
|
25
|
+
if selector_or_object.is_a?(String)
|
|
26
|
+
super
|
|
27
|
+
else
|
|
28
|
+
super('#' + RecordIdentifier.dom_id(selector_or_object), &block)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/test/test_helper.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
|
|
3
1
|
ENV["RAILS_ENV"] = "test"
|
|
4
2
|
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
|
5
3
|
|
|
4
|
+
$:.unshift File.dirname(__FILE__)
|
|
6
5
|
puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
|
|
7
|
-
require File.join(File.dirname(__FILE__), 'orm', DEVISE_ORM.to_s)
|
|
8
|
-
|
|
9
|
-
require 'webrat'
|
|
10
|
-
require 'mocha'
|
|
11
6
|
|
|
12
|
-
|
|
7
|
+
require "rails_app/config/environment"
|
|
8
|
+
require "rails/test_help"
|
|
9
|
+
require "orm/#{DEVISE_ORM}"
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
|
11
|
+
I18n.load_path << File.expand_path("../support/locale/en.yml", __FILE__)
|
|
12
|
+
require 'mocha'
|
|
17
13
|
|
|
18
14
|
Webrat.configure do |config|
|
|
19
15
|
config.mode = :rails
|
|
20
16
|
config.open_error_files = false
|
|
21
|
-
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Add support to load paths so we can overwrite broken webrat setup
|
|
20
|
+
$:.unshift File.expand_path('../support', __FILE__)
|
|
21
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|