glennr-devise 1.0.1
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 +334 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +260 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +55 -0
- data/app/controllers/sessions_controller.rb +45 -0
- data/app/controllers/unlocks_controller.rb +33 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/views/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/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +15 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/migration.rb +23 -0
- data/generators/devise/templates/model.rb +9 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +15 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +105 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/init.rb +2 -0
- data/lib/devise.rb +256 -0
- data/lib/devise/controllers/helpers.rb +200 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +65 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +131 -0
- data/lib/devise/models.rb +112 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +172 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +160 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +92 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +48 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +50 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/rails/routes.rb +125 -0
- data/lib/devise/rails/warden_compat.rb +25 -0
- data/lib/devise/schema.rb +65 -0
- data/lib/devise/strategies/authenticatable.rb +36 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/http_authenticatable.rb +49 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +86 -0
- data/lib/devise/version.rb +3 -0
- data/test/controllers/helpers_test.rb +177 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +69 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +271 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +44 -0
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +130 -0
- data/test/integration/rememberable_test.rb +63 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +80 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +153 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +56 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
- data/test/rails_app/app/mongo_mapper/user.rb +8 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +82 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +21 -0
- data/test/routes_test.rb +110 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +202 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# These settings change the behavior of Rails 2 apps and will be defaults
|
|
4
|
+
# for Rails 3. You can remove this initializer when Rails 3 is released.
|
|
5
|
+
|
|
6
|
+
if defined?(ActiveRecord)
|
|
7
|
+
# Include Active Record class name as root for JSON serialized output.
|
|
8
|
+
ActiveRecord::Base.include_root_in_json = true
|
|
9
|
+
|
|
10
|
+
# Store the full class name (including module namespace) in STI type column.
|
|
11
|
+
ActiveRecord::Base.store_full_sti_class = true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
ActionController::Routing.generate_best_match = false
|
|
15
|
+
|
|
16
|
+
# Use ISO 8601 format for JSON serialized times and dates.
|
|
17
|
+
ActiveSupport.use_standard_json_time_format = true
|
|
18
|
+
|
|
19
|
+
# Don't escape HTML entities in JSON, leave that for the #json_escape helper.
|
|
20
|
+
# if you're including raw json in an HTML page.
|
|
21
|
+
ActiveSupport.escape_html_entities_in_json = false
|
|
22
|
+
|
|
23
|
+
# Clean up silencers
|
|
24
|
+
Rails.backtrace_cleaner.remove_silencers!
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
|
2
|
+
|
|
3
|
+
# Your secret key for verifying cookie session data integrity.
|
|
4
|
+
# If you change this key, all old sessions will become invalid!
|
|
5
|
+
# Make sure the secret is at least 30 characters and all random,
|
|
6
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
|
7
|
+
ActionController::Base.session = {
|
|
8
|
+
:key => '_rails_app_session',
|
|
9
|
+
:secret => '89e8147901a0d7c221ac130e0ded3eeab6dab4a97127255909f08fedaae371918b41dec9d4d75c5b27a55c3772d43c2b6a3cbac232c5cc2ce4b8ec22242f5e60'
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
# Use the database for sessions instead of the cookie-based default,
|
|
13
|
+
# which shouldn't be used to store highly confidential information
|
|
14
|
+
# (create the session table with "rake db:sessions:create")
|
|
15
|
+
# ActionController::Base.session_store = :active_record_store
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
ActionController::Routing::Routes.draw do |map|
|
|
2
|
+
map.devise_for :users
|
|
3
|
+
map.devise_for :admin, :as => 'admin_area'
|
|
4
|
+
map.devise_for :accounts, :scope => 'manager', :path_prefix => ':locale',
|
|
5
|
+
:class_name => "User", :requirements => { :extra => 'value' }, :path_names => {
|
|
6
|
+
:sign_in => 'login', :sign_out => 'logout',
|
|
7
|
+
:password => 'secret', :confirmation => 'verification',
|
|
8
|
+
:unlock => 'unblock', :sign_up => 'register'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
map.resources :users, :only => [:index], :member => { :expire => :get }
|
|
12
|
+
map.resources :admins, :only => :index
|
|
13
|
+
map.root :controller => :home
|
|
14
|
+
|
|
15
|
+
map.connect '/admin_area/password/new', :controller => "passwords", :action => "new"
|
|
16
|
+
map.admin_root '/admin_area/home', :controller => "admins", :action => "index"
|
|
17
|
+
|
|
18
|
+
map.connect '/sign_in', :controller => "sessions", :action => "new"
|
|
19
|
+
map.connect ':controller/:action/:id'
|
|
20
|
+
map.connect ':controller/:action/:id.:format'
|
|
21
|
+
end
|
data/test/routes_test.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
|
|
3
|
+
class MapRoutingTest < ActionController::TestCase
|
|
4
|
+
|
|
5
|
+
test 'map new user session' do
|
|
6
|
+
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'users/sign_in', :method => :get})
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'map create user session' do
|
|
10
|
+
assert_recognizes({:controller => 'sessions', :action => 'create'}, {:path => 'users/sign_in', :method => :post})
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test 'map destroy user session' do
|
|
14
|
+
assert_recognizes({:controller => 'sessions', :action => 'destroy'}, {:path => 'users/sign_out', :method => :get})
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test 'map new user confirmation' do
|
|
18
|
+
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'users/confirmation/new')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'map create user confirmation' do
|
|
22
|
+
assert_recognizes({:controller => 'confirmations', :action => 'create'}, {:path => 'users/confirmation', :method => :post})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'map show user confirmation' do
|
|
26
|
+
assert_recognizes({:controller => 'confirmations', :action => 'show'}, {:path => 'users/confirmation', :method => :get})
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'map new user password' do
|
|
30
|
+
assert_recognizes({:controller => 'passwords', :action => 'new'}, 'users/password/new')
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
test 'map create user password' do
|
|
34
|
+
assert_recognizes({:controller => 'passwords', :action => 'create'}, {:path => 'users/password', :method => :post})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'map edit user password' do
|
|
38
|
+
assert_recognizes({:controller => 'passwords', :action => 'edit'}, 'users/password/edit')
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'map update user password' do
|
|
42
|
+
assert_recognizes({:controller => 'passwords', :action => 'update'}, {:path => 'users/password', :method => :put})
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'map new user unlock' do
|
|
46
|
+
assert_recognizes({:controller => 'unlocks', :action => 'new'}, 'users/unlock/new')
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'map create user unlock' do
|
|
50
|
+
assert_recognizes({:controller => 'unlocks', :action => 'create'}, {:path => 'users/unlock', :method => :post})
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
test 'map show user unlock' do
|
|
54
|
+
assert_recognizes({:controller => 'unlocks', :action => 'show'}, {:path => 'users/unlock', :method => :get})
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
test 'map new user registration' do
|
|
58
|
+
assert_recognizes({:controller => 'registrations', :action => 'new'}, 'users/sign_up')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'map create user registration' do
|
|
62
|
+
assert_recognizes({:controller => 'registrations', :action => 'create'}, {:path => 'users', :method => :post})
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
test 'map edit user registration' do
|
|
66
|
+
assert_recognizes({:controller => 'registrations', :action => 'edit'}, {:path => 'users/edit', :method => :get})
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test 'map update user registration' do
|
|
70
|
+
assert_recognizes({:controller => 'registrations', :action => 'update'}, {:path => 'users', :method => :put})
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'map destroy user registration' do
|
|
74
|
+
assert_recognizes({:controller => 'registrations', :action => 'destroy'}, {:path => 'users', :method => :delete})
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
test 'map admin session with :as option' do
|
|
78
|
+
assert_recognizes({:controller => 'sessions', :action => 'new'}, {:path => 'admin_area/sign_in', :method => :get})
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test 'does not map admin confirmation' do
|
|
82
|
+
assert_raise ActionController::RoutingError do
|
|
83
|
+
assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'admin_area/confirmation/new')
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test 'map account with custom path name for session sign in' do
|
|
88
|
+
assert_recognizes({:controller => 'sessions', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/login')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
test 'map account with custom path name for session sign out' do
|
|
92
|
+
assert_recognizes({:controller => 'sessions', :action => 'destroy', :locale => 'en', :extra => 'value'}, '/en/accounts/logout')
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
test 'map account with custom path name for password' do
|
|
96
|
+
assert_recognizes({:controller => 'passwords', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/secret/new')
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
test 'map account with custom path name for confirmation' do
|
|
100
|
+
assert_recognizes({:controller => 'confirmations', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/verification/new')
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
test 'map account with custom path name for unlock' do
|
|
104
|
+
assert_recognizes({:controller => 'unlocks', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/unblock/new')
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
test 'map account with custom path name for registration' do
|
|
108
|
+
assert_recognizes({:controller => 'registrations', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/register')
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
class ActiveSupport::TestCase
|
|
2
|
+
def assert_not(assertion)
|
|
3
|
+
assert !assertion
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def assert_blank(assertion)
|
|
7
|
+
assert assertion.blank?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def assert_not_blank(assertion)
|
|
11
|
+
assert !assertion.blank?
|
|
12
|
+
end
|
|
13
|
+
alias :assert_present :assert_not_blank
|
|
14
|
+
|
|
15
|
+
def assert_email_sent(&block)
|
|
16
|
+
assert_difference('ActionMailer::Base.deliveries.size') { yield }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def assert_email_not_sent(&block)
|
|
20
|
+
assert_no_difference('ActionMailer::Base.deliveries.size') { yield }
|
|
21
|
+
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
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class ActionController::IntegrationTest
|
|
2
|
+
|
|
3
|
+
def warden
|
|
4
|
+
request.env['warden']
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def create_user(options={})
|
|
8
|
+
@user ||= begin
|
|
9
|
+
user = User.create!(
|
|
10
|
+
:username => 'usertest',
|
|
11
|
+
:email => 'user@test.com',
|
|
12
|
+
:password => '123456',
|
|
13
|
+
:password_confirmation => '123456',
|
|
14
|
+
:created_at => Time.now.utc
|
|
15
|
+
)
|
|
16
|
+
user.confirm! unless options[:confirm] == false
|
|
17
|
+
user.lock! if options[:locked] == true
|
|
18
|
+
user
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def create_admin(options={})
|
|
23
|
+
@admin ||= begin
|
|
24
|
+
admin = Admin.create!(
|
|
25
|
+
:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456'
|
|
26
|
+
)
|
|
27
|
+
admin
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def sign_in_as_user(options={}, &block)
|
|
32
|
+
user = create_user(options)
|
|
33
|
+
visit new_user_session_path unless options[:visit] == false
|
|
34
|
+
fill_in 'email', :with => 'user@test.com'
|
|
35
|
+
fill_in 'password', :with => '123456'
|
|
36
|
+
check 'remember me' if options[:remember_me] == true
|
|
37
|
+
yield if block_given?
|
|
38
|
+
click_button 'Sign In'
|
|
39
|
+
user
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def sign_in_as_admin(options={}, &block)
|
|
43
|
+
admin = create_admin(options)
|
|
44
|
+
visit new_admin_session_path unless options[:visit] == false
|
|
45
|
+
fill_in 'email', :with => 'admin@test.com'
|
|
46
|
+
fill_in 'password', :with => '123456'
|
|
47
|
+
yield if block_given?
|
|
48
|
+
click_button 'Sign In'
|
|
49
|
+
admin
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Fix assert_redirect_to in integration sessions because they don't take into
|
|
53
|
+
# account Middleware redirects.
|
|
54
|
+
#
|
|
55
|
+
def assert_redirected_to(url)
|
|
56
|
+
assert [301, 302].include?(@integration_session.status),
|
|
57
|
+
"Expected status to be 301 or 302, got #{@integration_session.status}"
|
|
58
|
+
|
|
59
|
+
url = prepend_host(url)
|
|
60
|
+
location = prepend_host(@integration_session.headers["Location"])
|
|
61
|
+
assert_equal url, location
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
protected
|
|
65
|
+
|
|
66
|
+
def prepend_host(url)
|
|
67
|
+
url = "http://#{request.host}#{url}" if url[0] == ?/
|
|
68
|
+
url
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class ActiveSupport::TestCase
|
|
2
|
+
VALID_AUTHENTICATION_TOKEN = 'AbCdEfGhIjKlMnOpQrSt'.freeze
|
|
3
|
+
|
|
4
|
+
def setup_mailer
|
|
5
|
+
ActionMailer::Base.deliveries = []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def store_translations(locale, translations, &block)
|
|
9
|
+
begin
|
|
10
|
+
I18n.backend.store_translations locale, translations
|
|
11
|
+
yield
|
|
12
|
+
ensure
|
|
13
|
+
I18n.reload!
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Helpers for creating new users
|
|
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
|
+
end
|
data/test/test_helper.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
|
4
|
+
DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
|
5
|
+
|
|
6
|
+
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
|
+
|
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
13
|
+
|
|
14
|
+
ActionMailer::Base.delivery_method = :test
|
|
15
|
+
ActionMailer::Base.perform_deliveries = true
|
|
16
|
+
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
|
17
|
+
|
|
18
|
+
Webrat.configure do |config|
|
|
19
|
+
config.mode = :rails
|
|
20
|
+
config.open_error_files = false
|
|
21
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
|
|
3
|
+
class TestHelpersTest < ActionController::TestCase
|
|
4
|
+
tests UsersController
|
|
5
|
+
include Devise::TestHelpers
|
|
6
|
+
|
|
7
|
+
test "redirects if attempting to access a page unauthenticated" do
|
|
8
|
+
get :show
|
|
9
|
+
assert_redirected_to "/users/sign_in?unauthenticated=true"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
test "redirects if attempting to access a page with a unconfirmed account" do
|
|
13
|
+
swap Devise, :confirm_within => 0 do
|
|
14
|
+
sign_in create_user
|
|
15
|
+
get :show
|
|
16
|
+
assert_redirected_to "/users/sign_in?unconfirmed=true"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test "does not redirect with valid user" do
|
|
21
|
+
user = create_user
|
|
22
|
+
user.confirm!
|
|
23
|
+
|
|
24
|
+
sign_in user
|
|
25
|
+
get :show
|
|
26
|
+
assert_response :success
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test "redirects if valid user signed out" do
|
|
30
|
+
user = create_user
|
|
31
|
+
user.confirm!
|
|
32
|
+
|
|
33
|
+
sign_in user
|
|
34
|
+
get :show
|
|
35
|
+
|
|
36
|
+
sign_out user
|
|
37
|
+
get :show
|
|
38
|
+
assert_redirected_to "/users/sign_in?unauthenticated=true"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test "allows to sign in with different users" do
|
|
42
|
+
first_user = create_user
|
|
43
|
+
first_user.confirm!
|
|
44
|
+
|
|
45
|
+
sign_in first_user
|
|
46
|
+
get :show
|
|
47
|
+
assert_equal first_user.id.to_s, @response.body
|
|
48
|
+
sign_out first_user
|
|
49
|
+
|
|
50
|
+
second_user = create_user
|
|
51
|
+
second_user.confirm!
|
|
52
|
+
|
|
53
|
+
sign_in second_user
|
|
54
|
+
get :show
|
|
55
|
+
assert_equal second_user.id.to_s, @response.body
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: glennr-devise
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "Jos\xC3\xA9 Valim"
|
|
8
|
+
- "Carlos Ant\xC3\xB4nio"
|
|
9
|
+
- Glenn Roberts
|
|
10
|
+
autorequire:
|
|
11
|
+
bindir: bin
|
|
12
|
+
cert_chain: []
|
|
13
|
+
|
|
14
|
+
date: 2010-02-15 00:00:00 +02:00
|
|
15
|
+
default_executable:
|
|
16
|
+
dependencies:
|
|
17
|
+
- !ruby/object:Gem::Dependency
|
|
18
|
+
name: warden
|
|
19
|
+
type: :runtime
|
|
20
|
+
version_requirement:
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ~>
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.9.0
|
|
26
|
+
version:
|
|
27
|
+
description: Flexible authentication solution for Rails with Warden. Now with added support for changing email content_type yay!
|
|
28
|
+
email: contact@plataformatec.com.br
|
|
29
|
+
executables: []
|
|
30
|
+
|
|
31
|
+
extensions: []
|
|
32
|
+
|
|
33
|
+
extra_rdoc_files:
|
|
34
|
+
- README.rdoc
|
|
35
|
+
- TODO
|
|
36
|
+
files:
|
|
37
|
+
- CHANGELOG.rdoc
|
|
38
|
+
- MIT-LICENSE
|
|
39
|
+
- README.rdoc
|
|
40
|
+
- Rakefile
|
|
41
|
+
- TODO
|
|
42
|
+
- app/controllers/confirmations_controller.rb
|
|
43
|
+
- app/controllers/passwords_controller.rb
|
|
44
|
+
- app/controllers/registrations_controller.rb
|
|
45
|
+
- app/controllers/sessions_controller.rb
|
|
46
|
+
- app/controllers/unlocks_controller.rb
|
|
47
|
+
- app/models/devise_mailer.rb
|
|
48
|
+
- app/views/confirmations/new.html.erb
|
|
49
|
+
- app/views/devise_mailer/confirmation_instructions.html.erb
|
|
50
|
+
- app/views/devise_mailer/reset_password_instructions.html.erb
|
|
51
|
+
- app/views/devise_mailer/unlock_instructions.html.erb
|
|
52
|
+
- app/views/passwords/edit.html.erb
|
|
53
|
+
- app/views/passwords/new.html.erb
|
|
54
|
+
- app/views/registrations/edit.html.erb
|
|
55
|
+
- app/views/registrations/new.html.erb
|
|
56
|
+
- app/views/sessions/new.html.erb
|
|
57
|
+
- app/views/shared/_devise_links.erb
|
|
58
|
+
- app/views/unlocks/new.html.erb
|
|
59
|
+
- generators/devise/USAGE
|
|
60
|
+
- generators/devise/devise_generator.rb
|
|
61
|
+
- generators/devise/lib/route_devise.rb
|
|
62
|
+
- generators/devise/templates/migration.rb
|
|
63
|
+
- generators/devise/templates/model.rb
|
|
64
|
+
- generators/devise_install/USAGE
|
|
65
|
+
- generators/devise_install/devise_install_generator.rb
|
|
66
|
+
- generators/devise_install/templates/README
|
|
67
|
+
- generators/devise_install/templates/devise.rb
|
|
68
|
+
- generators/devise_views/USAGE
|
|
69
|
+
- generators/devise_views/devise_views_generator.rb
|
|
70
|
+
- init.rb
|
|
71
|
+
- lib/devise.rb
|
|
72
|
+
- lib/devise/controllers/helpers.rb
|
|
73
|
+
- lib/devise/controllers/internal_helpers.rb
|
|
74
|
+
- lib/devise/controllers/url_helpers.rb
|
|
75
|
+
- lib/devise/encryptors/authlogic_sha512.rb
|
|
76
|
+
- lib/devise/encryptors/base.rb
|
|
77
|
+
- lib/devise/encryptors/bcrypt.rb
|
|
78
|
+
- lib/devise/encryptors/clearance_sha1.rb
|
|
79
|
+
- lib/devise/encryptors/restful_authentication_sha1.rb
|
|
80
|
+
- lib/devise/encryptors/sha1.rb
|
|
81
|
+
- lib/devise/encryptors/sha512.rb
|
|
82
|
+
- lib/devise/failure_app.rb
|
|
83
|
+
- lib/devise/hooks/activatable.rb
|
|
84
|
+
- lib/devise/hooks/rememberable.rb
|
|
85
|
+
- lib/devise/hooks/timeoutable.rb
|
|
86
|
+
- lib/devise/hooks/trackable.rb
|
|
87
|
+
- lib/devise/locales/en.yml
|
|
88
|
+
- lib/devise/mapping.rb
|
|
89
|
+
- lib/devise/models.rb
|
|
90
|
+
- lib/devise/models/activatable.rb
|
|
91
|
+
- lib/devise/models/authenticatable.rb
|
|
92
|
+
- lib/devise/models/confirmable.rb
|
|
93
|
+
- lib/devise/models/http_authenticatable.rb
|
|
94
|
+
- lib/devise/models/lockable.rb
|
|
95
|
+
- lib/devise/models/recoverable.rb
|
|
96
|
+
- lib/devise/models/registerable.rb
|
|
97
|
+
- lib/devise/models/rememberable.rb
|
|
98
|
+
- lib/devise/models/timeoutable.rb
|
|
99
|
+
- lib/devise/models/token_authenticatable.rb
|
|
100
|
+
- lib/devise/models/trackable.rb
|
|
101
|
+
- lib/devise/models/validatable.rb
|
|
102
|
+
- lib/devise/orm/active_record.rb
|
|
103
|
+
- lib/devise/orm/data_mapper.rb
|
|
104
|
+
- lib/devise/orm/mongo_mapper.rb
|
|
105
|
+
- lib/devise/rails.rb
|
|
106
|
+
- lib/devise/rails/routes.rb
|
|
107
|
+
- lib/devise/rails/warden_compat.rb
|
|
108
|
+
- lib/devise/schema.rb
|
|
109
|
+
- lib/devise/strategies/authenticatable.rb
|
|
110
|
+
- lib/devise/strategies/base.rb
|
|
111
|
+
- lib/devise/strategies/http_authenticatable.rb
|
|
112
|
+
- lib/devise/strategies/rememberable.rb
|
|
113
|
+
- lib/devise/strategies/token_authenticatable.rb
|
|
114
|
+
- lib/devise/test_helpers.rb
|
|
115
|
+
- lib/devise/version.rb
|
|
116
|
+
has_rdoc: true
|
|
117
|
+
homepage: http://github.com/plataformatec/devise
|
|
118
|
+
licenses: []
|
|
119
|
+
|
|
120
|
+
post_install_message:
|
|
121
|
+
rdoc_options:
|
|
122
|
+
- --charset=UTF-8
|
|
123
|
+
require_paths:
|
|
124
|
+
- lib
|
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
|
+
requirements:
|
|
127
|
+
- - ">="
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: "0"
|
|
130
|
+
version:
|
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
|
+
requirements:
|
|
133
|
+
- - ">="
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: "0"
|
|
136
|
+
version:
|
|
137
|
+
requirements: []
|
|
138
|
+
|
|
139
|
+
rubyforge_project:
|
|
140
|
+
rubygems_version: 1.3.5
|
|
141
|
+
signing_key:
|
|
142
|
+
specification_version: 3
|
|
143
|
+
summary: Flexible authentication solution for Rails with Warden
|
|
144
|
+
test_files:
|
|
145
|
+
- test/controllers/helpers_test.rb
|
|
146
|
+
- test/controllers/internal_helpers_test.rb
|
|
147
|
+
- test/controllers/url_helpers_test.rb
|
|
148
|
+
- test/devise_test.rb
|
|
149
|
+
- test/encryptors_test.rb
|
|
150
|
+
- test/failure_app_test.rb
|
|
151
|
+
- test/integration/authenticatable_test.rb
|
|
152
|
+
- test/integration/confirmable_test.rb
|
|
153
|
+
- test/integration/http_authenticatable_test.rb
|
|
154
|
+
- test/integration/lockable_test.rb
|
|
155
|
+
- test/integration/recoverable_test.rb
|
|
156
|
+
- test/integration/registerable_test.rb
|
|
157
|
+
- test/integration/rememberable_test.rb
|
|
158
|
+
- test/integration/timeoutable_test.rb
|
|
159
|
+
- test/integration/token_authenticatable_test.rb
|
|
160
|
+
- test/integration/trackable_test.rb
|
|
161
|
+
- test/mailers/confirmation_instructions_test.rb
|
|
162
|
+
- test/mailers/reset_password_instructions_test.rb
|
|
163
|
+
- test/mailers/unlock_instructions_test.rb
|
|
164
|
+
- test/mapping_test.rb
|
|
165
|
+
- test/models/authenticatable_test.rb
|
|
166
|
+
- test/models/confirmable_test.rb
|
|
167
|
+
- test/models/lockable_test.rb
|
|
168
|
+
- test/models/recoverable_test.rb
|
|
169
|
+
- test/models/rememberable_test.rb
|
|
170
|
+
- test/models/timeoutable_test.rb
|
|
171
|
+
- test/models/token_authenticatable_test.rb
|
|
172
|
+
- test/models/trackable_test.rb
|
|
173
|
+
- test/models/validatable_test.rb
|
|
174
|
+
- test/models_test.rb
|
|
175
|
+
- test/orm/active_record.rb
|
|
176
|
+
- test/orm/mongo_mapper.rb
|
|
177
|
+
- test/rails_app/app/active_record/admin.rb
|
|
178
|
+
- test/rails_app/app/active_record/user.rb
|
|
179
|
+
- test/rails_app/app/controllers/admins_controller.rb
|
|
180
|
+
- test/rails_app/app/controllers/application_controller.rb
|
|
181
|
+
- test/rails_app/app/controllers/home_controller.rb
|
|
182
|
+
- test/rails_app/app/controllers/users_controller.rb
|
|
183
|
+
- test/rails_app/app/helpers/application_helper.rb
|
|
184
|
+
- test/rails_app/app/mongo_mapper/admin.rb
|
|
185
|
+
- test/rails_app/app/mongo_mapper/user.rb
|
|
186
|
+
- test/rails_app/config/boot.rb
|
|
187
|
+
- test/rails_app/config/environment.rb
|
|
188
|
+
- test/rails_app/config/environments/development.rb
|
|
189
|
+
- test/rails_app/config/environments/production.rb
|
|
190
|
+
- test/rails_app/config/environments/test.rb
|
|
191
|
+
- test/rails_app/config/initializers/devise.rb
|
|
192
|
+
- test/rails_app/config/initializers/inflections.rb
|
|
193
|
+
- test/rails_app/config/initializers/new_rails_defaults.rb
|
|
194
|
+
- test/rails_app/config/initializers/session_store.rb
|
|
195
|
+
- test/rails_app/config/routes.rb
|
|
196
|
+
- test/routes_test.rb
|
|
197
|
+
- test/support/assertions_helper.rb
|
|
198
|
+
- test/support/integration_tests_helper.rb
|
|
199
|
+
- test/support/test_silencer.rb
|
|
200
|
+
- test/support/tests_helper.rb
|
|
201
|
+
- test/test_helper.rb
|
|
202
|
+
- test/test_helpers_test.rb
|