devise-edge 1.2.rc
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 +500 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +335 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/oauth_callbacks_controller.rb +4 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +75 -0
- data/app/controllers/devise/sessions_controller.rb +23 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +17 -0
- data/app/mailers/devise/mailer.rb +88 -0
- data/app/views/devise/confirmations/new.html.erb +12 -0
- data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise/mailer/unlock_instructions.html.erb +7 -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 +25 -0
- data/app/views/devise/unlocks/new.html.erb +12 -0
- data/config/locales/en.yml +42 -0
- data/lib/devise.rb +371 -0
- data/lib/devise/controllers/helpers.rb +261 -0
- data/lib/devise/controllers/internal_helpers.rb +113 -0
- data/lib/devise/controllers/scoped_views.rb +33 -0
- data/lib/devise/controllers/url_helpers.rb +39 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +19 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/clearance_sha1.rb +17 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +25 -0
- data/lib/devise/encryptors/sha512.rb +25 -0
- data/lib/devise/failure_app.rb +126 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +45 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +105 -0
- data/lib/devise/models.rb +66 -0
- data/lib/devise/models/authenticatable.rb +143 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +94 -0
- data/lib/devise/models/encryptable.rb +65 -0
- data/lib/devise/models/lockable.rb +168 -0
- data/lib/devise/models/oauthable.rb +49 -0
- data/lib/devise/models/recoverable.rb +83 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +122 -0
- data/lib/devise/models/timeoutable.rb +33 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +60 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/oauth.rb +41 -0
- data/lib/devise/oauth/config.rb +33 -0
- data/lib/devise/oauth/helpers.rb +18 -0
- data/lib/devise/oauth/internal_helpers.rb +182 -0
- data/lib/devise/oauth/test_helpers.rb +29 -0
- data/lib/devise/oauth/url_helpers.rb +35 -0
- data/lib/devise/orm/active_record.rb +36 -0
- data/lib/devise/orm/mongo_mapper.rb +46 -0
- data/lib/devise/orm/mongoid.rb +29 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails.rb +67 -0
- data/lib/devise/rails/routes.rb +260 -0
- data/lib/devise/rails/warden_compat.rb +42 -0
- data/lib/devise/schema.rb +96 -0
- data/lib/devise/strategies/authenticatable.rb +150 -0
- data/lib/devise/strategies/base.rb +15 -0
- data/lib/devise/strategies/database_authenticatable.rb +21 -0
- data/lib/devise/strategies/rememberable.rb +51 -0
- data/lib/devise/strategies/token_authenticatable.rb +53 -0
- data/lib/devise/test_helpers.rb +100 -0
- data/lib/devise/version.rb +3 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +30 -0
- 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 +24 -0
- data/lib/generators/devise/views_generator.rb +63 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +168 -0
- data/test/controllers/helpers_test.rb +220 -0
- data/test/controllers/internal_helpers_test.rb +56 -0
- data/test/controllers/url_helpers_test.rb +59 -0
- data/test/devise_test.rb +65 -0
- data/test/encryptors_test.rb +30 -0
- data/test/failure_app_test.rb +148 -0
- data/test/integration/authenticatable_test.rb +424 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +38 -0
- data/test/integration/http_authenticatable_test.rb +64 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/oauthable_test.rb +258 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +179 -0
- data/test/integration/timeoutable_test.rb +80 -0
- data/test/integration/token_authenticatable_test.rb +99 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +84 -0
- data/test/mailers/reset_password_instructions_test.rb +72 -0
- data/test/mailers/unlock_instructions_test.rb +66 -0
- data/test/mapping_test.rb +95 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +82 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/oauthable_test.rb +21 -0
- data/test/models/recoverable_test.rb +155 -0
- data/test/models/rememberable_test.rb +271 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +37 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +99 -0
- data/test/models_test.rb +77 -0
- data/test/oauth/config_test.rb +44 -0
- data/test/oauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +10 -0
- data/test/rails_app/app/active_record/admin.rb +6 -0
- data/test/rails_app/app/active_record/shim.rb +2 -0
- data/test/rails_app/app/active_record/user.rb +8 -0
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +9 -0
- data/test/rails_app/app/controllers/home_controller.rb +12 -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/users_controller.rb +18 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/shim.rb +24 -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 +13 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +19 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +172 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +54 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +31 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/lib/shared_admin.rb +9 -0
- data/test/rails_app/lib/shared_user.rb +48 -0
- data/test/routes_test.rb +189 -0
- data/test/support/assertions.rb +24 -0
- data/test/support/helpers.rb +60 -0
- data/test/support/integration.rb +88 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +23 -0
- data/test/test_helpers_test.rb +101 -0
- metadata +335 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead
|
|
2
|
+
# of editing this file, please use the migrations feature of Active Record to
|
|
3
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
|
4
|
+
#
|
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your
|
|
6
|
+
# database schema. If you need to create the application database on another
|
|
7
|
+
# system, you should be using db:schema:load, not running all the migrations
|
|
8
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
9
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
10
|
+
#
|
|
11
|
+
# It's strongly recommended to check this file into your version control system.
|
|
12
|
+
|
|
13
|
+
ActiveRecord::Schema.define(:version => 20100401102949) do
|
|
14
|
+
|
|
15
|
+
create_table "admins", :force => true do |t|
|
|
16
|
+
t.string "email"
|
|
17
|
+
t.string "encrypted_password", :limit => 128
|
|
18
|
+
t.string "password_salt"
|
|
19
|
+
t.string "remember_token"
|
|
20
|
+
t.datetime "remember_created_at"
|
|
21
|
+
t.string "reset_password_token"
|
|
22
|
+
t.integer "failed_attempts", :default => 0
|
|
23
|
+
t.string "unlock_token"
|
|
24
|
+
t.datetime "locked_at"
|
|
25
|
+
t.datetime "created_at"
|
|
26
|
+
t.datetime "updated_at"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
create_table "users", :force => true do |t|
|
|
30
|
+
t.string "username"
|
|
31
|
+
t.string "facebook_token"
|
|
32
|
+
t.string "email", :default => "", :null => false
|
|
33
|
+
t.string "encrypted_password", :limit => 128, :default => "", :null => false
|
|
34
|
+
t.string "confirmation_token"
|
|
35
|
+
t.datetime "confirmed_at"
|
|
36
|
+
t.datetime "confirmation_sent_at"
|
|
37
|
+
t.string "reset_password_token"
|
|
38
|
+
t.datetime "remember_created_at"
|
|
39
|
+
t.integer "sign_in_count", :default => 0
|
|
40
|
+
t.datetime "current_sign_in_at"
|
|
41
|
+
t.datetime "last_sign_in_at"
|
|
42
|
+
t.string "current_sign_in_ip"
|
|
43
|
+
t.string "last_sign_in_ip"
|
|
44
|
+
t.integer "failed_attempts", :default => 0
|
|
45
|
+
t.string "unlock_token"
|
|
46
|
+
t.datetime "locked_at"
|
|
47
|
+
t.string "authentication_token"
|
|
48
|
+
t.datetime "created_at"
|
|
49
|
+
t.datetime "updated_at"
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module SharedUser
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
devise :database_authenticatable, :confirmable, :lockable, :recoverable,
|
|
6
|
+
:registerable, :rememberable, :timeoutable, :token_authenticatable,
|
|
7
|
+
:trackable, :validatable, :oauthable
|
|
8
|
+
|
|
9
|
+
# They need to be included after Devise is called.
|
|
10
|
+
extend ExtendMethods
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module ExtendMethods
|
|
14
|
+
def find_for_facebook_oauth(access_token, signed_in_resource=nil)
|
|
15
|
+
data = ActiveSupport::JSON.decode(access_token.get('/me'))
|
|
16
|
+
user = signed_in_resource || User.find_by_email(data["email"]) || User.new
|
|
17
|
+
user.update_with_facebook_oauth(access_token, data)
|
|
18
|
+
user.save
|
|
19
|
+
user
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def new_with_session(params, session)
|
|
23
|
+
super.tap do |user|
|
|
24
|
+
if session[:user_facebook_oauth_token]
|
|
25
|
+
access_token = oauth_access_token(:facebook, session[:user_facebook_oauth_token])
|
|
26
|
+
user.update_with_facebook_oauth(access_token)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update_with_facebook_oauth(access_token, data=nil)
|
|
33
|
+
data ||= ActiveSupport::JSON.decode(access_token.get('/me'))
|
|
34
|
+
|
|
35
|
+
self.username = data["username"] unless username.present?
|
|
36
|
+
self.email = data["email"] unless email.present?
|
|
37
|
+
|
|
38
|
+
self.confirmed_at ||= Time.now
|
|
39
|
+
self.facebook_token = access_token.token
|
|
40
|
+
|
|
41
|
+
unless encrypted_password.present?
|
|
42
|
+
self.password = Devise.friendly_token[0, 10]
|
|
43
|
+
self.password_confirmation = nil
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
yield self if block_given?
|
|
47
|
+
end
|
|
48
|
+
end
|
data/test/routes_test.rb
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class DefaultRoutingTest < ActionController::TestCase
|
|
4
|
+
test 'map new user session' do
|
|
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
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'map create user session' do
|
|
10
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'create'}, {:path => 'users/sign_in', :method => :post})
|
|
11
|
+
assert_named_route "/users/sign_in", :user_session_path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'map destroy user session' do
|
|
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
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'map new user confirmation' do
|
|
20
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'new'}, 'users/confirmation/new')
|
|
21
|
+
assert_named_route "/users/confirmation/new", :new_user_confirmation_path
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
test 'map create user confirmation' do
|
|
25
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'create'}, {:path => 'users/confirmation', :method => :post})
|
|
26
|
+
assert_named_route "/users/confirmation", :user_confirmation_path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'map show user confirmation' do
|
|
30
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'show'}, {:path => 'users/confirmation', :method => :get})
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'map new user password' do
|
|
34
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'users/password/new')
|
|
35
|
+
assert_named_route "/users/password/new", :new_user_password_path
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
test 'map create user password' do
|
|
39
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'create'}, {:path => 'users/password', :method => :post})
|
|
40
|
+
assert_named_route "/users/password", :user_password_path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test 'map edit user password' do
|
|
44
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'edit'}, 'users/password/edit')
|
|
45
|
+
assert_named_route "/users/password/edit", :edit_user_password_path
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'map update user password' do
|
|
49
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'update'}, {:path => 'users/password', :method => :put})
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test 'map new user unlock' do
|
|
53
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'new'}, 'users/unlock/new')
|
|
54
|
+
assert_named_route "/users/unlock/new", :new_user_unlock_path
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test 'map create user unlock' do
|
|
58
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'create'}, {:path => 'users/unlock', :method => :post})
|
|
59
|
+
assert_named_route "/users/unlock", :user_unlock_path
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
test 'map show user unlock' do
|
|
63
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'show'}, {:path => 'users/unlock', :method => :get})
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
test 'map new user registration' do
|
|
67
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, 'users/sign_up')
|
|
68
|
+
assert_named_route "/users/sign_up", :new_user_registration_path
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
test 'map create user registration' do
|
|
72
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'create'}, {:path => 'users', :method => :post})
|
|
73
|
+
assert_named_route "/users", :user_registration_path
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
test 'map edit user registration' do
|
|
77
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'edit'}, {:path => 'users/edit', :method => :get})
|
|
78
|
+
assert_named_route "/users/edit", :edit_user_registration_path
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test 'map update user registration' do
|
|
82
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'update'}, {:path => 'users', :method => :put})
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
test 'map destroy user registration' do
|
|
86
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
test 'map cancel user registration' do
|
|
90
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel'}, {:path => 'users/cancel', :method => :get})
|
|
91
|
+
assert_named_route "/users/cancel", :cancel_user_registration_path
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
test 'map oauth callbacks' do
|
|
95
|
+
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'facebook'}, {:path => 'users/oauth/facebook/callback', :method => :get})
|
|
96
|
+
assert_named_route "/users/oauth/facebook/callback", :user_oauth_callback_path, :facebook
|
|
97
|
+
|
|
98
|
+
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'github'}, {:path => 'users/oauth/github/callback', :method => :get})
|
|
99
|
+
assert_named_route "/users/oauth/github/callback", :user_oauth_callback_path, :github
|
|
100
|
+
|
|
101
|
+
assert_raise ActionController::RoutingError do
|
|
102
|
+
assert_recognizes({:controller => 'devise/oauth_callbacks', :action => 'twitter'}, {:path => 'users/oauth/twitter/callback', :method => :get})
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
protected
|
|
107
|
+
|
|
108
|
+
def assert_named_route(result, *args)
|
|
109
|
+
assert_equal result, @routes.url_helpers.send(*args)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class CustomizedRoutingTest < ActionController::TestCase
|
|
114
|
+
test 'map admin with :path option' do
|
|
115
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new'}, {:path => 'admin_area/sign_up', :method => :get})
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
test 'map admin with :controllers option' do
|
|
119
|
+
assert_recognizes({:controller => 'admins/sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
test 'does not map admin password' do
|
|
123
|
+
assert_raise ActionController::RoutingError do
|
|
124
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new'}, 'admin_area/password/new')
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
test 'map account with custom path name for session sign in' do
|
|
129
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'new', :locale => 'en'}, '/en/accounts/login')
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
test 'map account with custom path name for session sign out' do
|
|
133
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy', :locale => 'en'}, '/en/accounts/logout')
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
test 'map account with custom path name for password' do
|
|
137
|
+
assert_recognizes({:controller => 'devise/passwords', :action => 'new', :locale => 'en'}, '/en/accounts/secret/new')
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
test 'map account with custom path name for confirmation' do
|
|
141
|
+
assert_recognizes({:controller => 'devise/confirmations', :action => 'new', :locale => 'en'}, '/en/accounts/verification/new')
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
test 'map account with custom path name for unlock' do
|
|
145
|
+
assert_recognizes({:controller => 'devise/unlocks', :action => 'new', :locale => 'en'}, '/en/accounts/unblock/new')
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
test 'map account with custom path name for registration' do
|
|
149
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'new', :locale => 'en'}, '/en/accounts/management/register')
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
test 'map account with custom path name for cancel registration' do
|
|
153
|
+
assert_recognizes({:controller => 'devise/registrations', :action => 'cancel', :locale => 'en'}, '/en/accounts/management/giveup')
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
test 'map deletes with :sign_out_via option' do
|
|
157
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/deletes/sign_out', :method => :delete})
|
|
158
|
+
assert_raise ActionController::RoutingError do
|
|
159
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/deletes/sign_out', :method => :get})
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
test 'map posts with :sign_out_via option' do
|
|
164
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/posts/sign_out', :method => :post})
|
|
165
|
+
assert_raise ActionController::RoutingError do
|
|
166
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/posts/sign_out', :method => :get})
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
test 'map delete_or_posts with :sign_out_via option' do
|
|
171
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :post})
|
|
172
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :delete})
|
|
173
|
+
assert_raise ActionController::RoutingError do
|
|
174
|
+
assert_recognizes({:controller => 'devise/sessions', :action => 'destroy'}, {:path => '/sign_out_via/delete_or_posts/sign_out', :method => :get})
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
class ScopedRoutingTest < ActionController::TestCase
|
|
180
|
+
test 'map publisher account' do
|
|
181
|
+
assert_recognizes({:controller => 'publisher/registrations', :action => 'new'}, {:path => '/publisher/accounts/sign_up', :method => :get})
|
|
182
|
+
assert_equal '/publisher/accounts/sign_up', @routes.url_helpers.new_publisher_account_registration_path
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
test 'map publisher account merges path names' do
|
|
186
|
+
assert_recognizes({:controller => 'publisher/sessions', :action => 'new'}, {:path => '/publisher/accounts/get_in', :method => :get})
|
|
187
|
+
assert_equal '/publisher/accounts/get_in', @routes.url_helpers.new_publisher_account_session_path
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'active_support/test_case'
|
|
2
|
+
|
|
3
|
+
class ActiveSupport::TestCase
|
|
4
|
+
def assert_not(assertion)
|
|
5
|
+
assert !assertion
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def assert_blank(assertion)
|
|
9
|
+
assert assertion.blank?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def assert_not_blank(assertion)
|
|
13
|
+
assert !assertion.blank?
|
|
14
|
+
end
|
|
15
|
+
alias :assert_present :assert_not_blank
|
|
16
|
+
|
|
17
|
+
def assert_email_sent(&block)
|
|
18
|
+
assert_difference('ActionMailer::Base.deliveries.size') { yield }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def assert_email_not_sent(&block)
|
|
22
|
+
assert_no_difference('ActionMailer::Base.deliveries.size') { yield }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'active_support/test_case'
|
|
2
|
+
|
|
3
|
+
class ActiveSupport::TestCase
|
|
4
|
+
VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
|
|
5
|
+
|
|
6
|
+
def setup_mailer
|
|
7
|
+
ActionMailer::Base.deliveries = []
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def store_translations(locale, translations, &block)
|
|
11
|
+
begin
|
|
12
|
+
I18n.backend.store_translations(locale, translations)
|
|
13
|
+
yield
|
|
14
|
+
ensure
|
|
15
|
+
I18n.reload!
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def generate_unique_email
|
|
20
|
+
@@email_count ||= 0
|
|
21
|
+
@@email_count += 1
|
|
22
|
+
"test#{@@email_count}@email.com"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def valid_attributes(attributes={})
|
|
26
|
+
{ :username => "usertest",
|
|
27
|
+
:email => generate_unique_email,
|
|
28
|
+
:password => '123456',
|
|
29
|
+
:password_confirmation => '123456' }.update(attributes)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def new_user(attributes={})
|
|
33
|
+
User.new(valid_attributes(attributes))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def create_user(attributes={})
|
|
37
|
+
User.create!(valid_attributes(attributes))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create_admin(attributes={})
|
|
41
|
+
valid_attributes = valid_attributes(attributes)
|
|
42
|
+
valid_attributes.delete(:username)
|
|
43
|
+
Admin.create!(valid_attributes)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Execute the block setting the given values and restoring old values after
|
|
47
|
+
# the block is executed.
|
|
48
|
+
def swap(object, new_values)
|
|
49
|
+
old_values = {}
|
|
50
|
+
new_values.each do |key, value|
|
|
51
|
+
old_values[key] = object.send key
|
|
52
|
+
object.send :"#{key}=", value
|
|
53
|
+
end
|
|
54
|
+
yield
|
|
55
|
+
ensure
|
|
56
|
+
old_values.each do |key, value|
|
|
57
|
+
object.send :"#{key}=", value
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
require 'action_dispatch/testing/integration'
|
|
2
|
+
|
|
3
|
+
class ActionDispatch::IntegrationTest
|
|
4
|
+
def warden
|
|
5
|
+
request.env['warden']
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def create_user(options={})
|
|
9
|
+
@user ||= begin
|
|
10
|
+
user = User.create!(
|
|
11
|
+
:username => 'usertest',
|
|
12
|
+
:email => 'user@test.com',
|
|
13
|
+
:password => '123456',
|
|
14
|
+
:password_confirmation => '123456',
|
|
15
|
+
:created_at => Time.now.utc
|
|
16
|
+
)
|
|
17
|
+
user.confirm! unless options[:confirm] == false
|
|
18
|
+
user.lock_access! if options[:locked] == true
|
|
19
|
+
user
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create_admin(options={})
|
|
24
|
+
@admin ||= begin
|
|
25
|
+
admin = Admin.create!(
|
|
26
|
+
:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456'
|
|
27
|
+
)
|
|
28
|
+
admin
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def sign_in_as_user(options={}, &block)
|
|
33
|
+
user = create_user(options)
|
|
34
|
+
visit_with_option options[:visit], new_user_session_path
|
|
35
|
+
fill_in 'email', :with => 'user@test.com'
|
|
36
|
+
fill_in 'password', :with => options[:password] || '123456'
|
|
37
|
+
check 'remember me' if options[:remember_me] == true
|
|
38
|
+
yield if block_given?
|
|
39
|
+
click_button 'Sign In'
|
|
40
|
+
user
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def sign_in_as_admin(options={}, &block)
|
|
44
|
+
admin = create_admin(options)
|
|
45
|
+
visit_with_option options[:visit], new_admin_session_path
|
|
46
|
+
fill_in 'email', :with => 'admin@test.com'
|
|
47
|
+
fill_in 'password', :with => '123456'
|
|
48
|
+
yield if block_given?
|
|
49
|
+
click_button 'Sign In'
|
|
50
|
+
admin
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Fix assert_redirect_to in integration sessions because they don't take into
|
|
54
|
+
# account Middleware redirects.
|
|
55
|
+
#
|
|
56
|
+
def assert_redirected_to(url)
|
|
57
|
+
assert [301, 302].include?(@integration_session.status),
|
|
58
|
+
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
|
59
|
+
|
|
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)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
protected
|
|
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
|
+
|
|
84
|
+
def prepend_host(url)
|
|
85
|
+
url = "http://#{request.host}#{url}" if url[0] == ?/
|
|
86
|
+
url
|
|
87
|
+
end
|
|
88
|
+
end
|