devise-jdguyot 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/.gitignore +10 -0
- data/CHANGELOG.rdoc +532 -0
- data/Gemfile +29 -0
- data/Gemfile.lock +152 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +353 -0
- data/Rakefile +36 -0
- data/TODO +4 -0
- data/app/controllers/devise/confirmations_controller.rb +33 -0
- data/app/controllers/devise/omniauth_callbacks_controller.rb +26 -0
- data/app/controllers/devise/passwords_controller.rb +41 -0
- data/app/controllers/devise/registrations_controller.rb +110 -0
- data/app/controllers/devise/sessions_controller.rb +25 -0
- data/app/controllers/devise/unlocks_controller.rb +34 -0
- data/app/helpers/devise_helper.rb +19 -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 +46 -0
- data/devise.gemspec +25 -0
- data/lib/devise/controllers/helpers.rb +227 -0
- data/lib/devise/controllers/internal_helpers.rb +119 -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 +132 -0
- data/lib/devise/hooks/activatable.rb +11 -0
- data/lib/devise/hooks/forgetable.rb +12 -0
- data/lib/devise/hooks/rememberable.rb +48 -0
- data/lib/devise/hooks/timeoutable.rb +22 -0
- data/lib/devise/hooks/trackable.rb +9 -0
- data/lib/devise/mapping.rb +110 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +160 -0
- data/lib/devise/models/database_authenticatable.rb +100 -0
- data/lib/devise/models/encryptable.rb +72 -0
- data/lib/devise/models/lockable.rb +169 -0
- data/lib/devise/models/omniauthable.rb +23 -0
- data/lib/devise/models/recoverable.rb +123 -0
- data/lib/devise/models/registerable.rb +21 -0
- data/lib/devise/models/rememberable.rb +130 -0
- data/lib/devise/models/timeoutable.rb +43 -0
- data/lib/devise/models/token_authenticatable.rb +72 -0
- data/lib/devise/models/trackable.rb +30 -0
- data/lib/devise/models/validatable.rb +65 -0
- data/lib/devise/models.rb +68 -0
- data/lib/devise/modules.rb +30 -0
- data/lib/devise/omniauth/config.rb +30 -0
- data/lib/devise/omniauth/test_helpers.rb +57 -0
- data/lib/devise/omniauth/url_helpers.rb +29 -0
- data/lib/devise/omniauth.rb +47 -0
- data/lib/devise/orm/active_record.rb +38 -0
- data/lib/devise/orm/mongoid.rb +31 -0
- data/lib/devise/path_checker.rb +18 -0
- data/lib/devise/rails/routes.rb +292 -0
- data/lib/devise/rails/warden_compat.rb +125 -0
- data/lib/devise/rails.rb +50 -0
- data/lib/devise/schema.rb +97 -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/devise.rb +381 -0
- data/lib/generators/active_record/devise_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +31 -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 +23 -0
- data/lib/generators/devise/views_generator.rb +106 -0
- data/lib/generators/mongoid/devise_generator.rb +17 -0
- data/lib/generators/templates/README +25 -0
- data/lib/generators/templates/devise.rb +186 -0
- data/test/controllers/helpers_test.rb +237 -0
- data/test/controllers/internal_helpers_test.rb +72 -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 +187 -0
- data/test/generators/active_record_generator_test.rb +24 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/mongoid_generator_test.rb +22 -0
- data/test/generators/views_generator_test.rb +35 -0
- data/test/indifferent_hash.rb +33 -0
- data/test/integration/authenticatable_test.rb +447 -0
- data/test/integration/confirmable_test.rb +104 -0
- data/test/integration/database_authenticatable_test.rb +60 -0
- data/test/integration/http_authenticatable_test.rb +74 -0
- data/test/integration/lockable_test.rb +109 -0
- data/test/integration/omniauthable_test.rb +107 -0
- data/test/integration/recoverable_test.rb +160 -0
- data/test/integration/registerable_test.rb +179 -0
- data/test/integration/rememberable_test.rb +180 -0
- data/test/integration/timeoutable_test.rb +89 -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 +119 -0
- data/test/models/confirmable_test.rb +221 -0
- data/test/models/database_authenticatable_test.rb +98 -0
- data/test/models/encryptable_test.rb +65 -0
- data/test/models/lockable_test.rb +204 -0
- data/test/models/recoverable_test.rb +190 -0
- data/test/models/rememberable_test.rb +279 -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 +84 -0
- data/test/omniauth/url_helpers_test.rb +47 -0
- data/test/orm/active_record.rb +9 -0
- data/test/orm/mongoid.rb +11 -0
- data/test/rails_app/Rakefile +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 +8 -0
- data/test/rails_app/app/controllers/home_controller.rb +16 -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/omniauth_callbacks_controller.rb +7 -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 +29 -0
- data/test/rails_app/app/mongoid/user.rb +10 -0
- data/test/rails_app/app/views/admins/index.html.erb +1 -0
- data/test/rails_app/app/views/admins/sessions/new.html.erb +2 -0
- data/test/rails_app/app/views/home/index.html.erb +1 -0
- data/test/rails_app/app/views/home/private.html.erb +1 -0
- data/test/rails_app/app/views/layouts/application.html.erb +24 -0
- data/test/rails_app/app/views/users/index.html.erb +1 -0
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +1 -0
- data/test/rails_app/app/views/users/sessions/new.html.erb +1 -0
- data/test/rails_app/config/application.rb +40 -0
- data/test/rails_app/config/boot.rb +13 -0
- data/test/rails_app/config/database.yml +18 -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 +176 -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 +55 -0
- data/test/rails_app/config.ru +4 -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 +23 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/routes_test.rb +179 -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/locale/en.yml +4 -0
- data/test/support/webrat/integrations/rails.rb +24 -0
- data/test/test_helper.rb +29 -0
- data/test/test_helpers_test.rb +118 -0
- metadata +388 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
|
|
4
|
+
class FailureTest < ActiveSupport::TestCase
|
|
5
|
+
def self.context(name, &block)
|
|
6
|
+
instance_eval(&block)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def call_failure(env_params={})
|
|
10
|
+
env = {
|
|
11
|
+
'REQUEST_URI' => 'http://test.host/',
|
|
12
|
+
'HTTP_HOST' => 'test.host',
|
|
13
|
+
'REQUEST_METHOD' => 'GET',
|
|
14
|
+
'warden.options' => { :scope => :user },
|
|
15
|
+
'rack.session' => {},
|
|
16
|
+
'action_dispatch.request.formats' => Array(env_params.delete('formats') || :html),
|
|
17
|
+
'rack.input' => "",
|
|
18
|
+
'warden' => OpenStruct.new(:message => nil)
|
|
19
|
+
}.merge!(env_params)
|
|
20
|
+
|
|
21
|
+
@response = Devise::FailureApp.call(env).to_a
|
|
22
|
+
@request = ActionDispatch::Request.new(env)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'When redirecting' do
|
|
26
|
+
test 'return 302 status' do
|
|
27
|
+
call_failure
|
|
28
|
+
assert_equal 302, @response.first
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test 'return 302 status for wildcard requests' do
|
|
32
|
+
call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'
|
|
33
|
+
assert_equal 302, @response.first
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
test 'return to the default redirect location' do
|
|
37
|
+
call_failure
|
|
38
|
+
assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
|
|
39
|
+
assert_equal 'http://test.host/users/sign_in', @response.second['Location']
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'uses the proxy failure message as symbol' do
|
|
43
|
+
call_failure('warden' => OpenStruct.new(:message => :test))
|
|
44
|
+
assert_equal 'test', @request.flash[:alert]
|
|
45
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
test 'uses the proxy failure message as string' do
|
|
49
|
+
call_failure('warden' => OpenStruct.new(:message => 'Hello world'))
|
|
50
|
+
assert_equal 'Hello world', @request.flash[:alert]
|
|
51
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
test 'set content type to default text/html' do
|
|
55
|
+
call_failure
|
|
56
|
+
assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
test 'setup a default message' do
|
|
60
|
+
call_failure
|
|
61
|
+
assert_match /You are being/, @response.last.body
|
|
62
|
+
assert_match /redirected/, @response.last.body
|
|
63
|
+
assert_match /users\/sign_in/, @response.last.body
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
test 'works for any navigational format' do
|
|
67
|
+
swap Devise, :navigational_formats => [:xml] do
|
|
68
|
+
call_failure('formats' => :xml)
|
|
69
|
+
assert_equal 302, @response.first
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'redirects the correct format if it is a non-html format request' do
|
|
74
|
+
swap Devise, :navigational_formats => [:js] do
|
|
75
|
+
call_failure('formats' => :js)
|
|
76
|
+
assert_equal 'http://test.host/users/sign_in.js', @response.second["Location"]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
context 'For HTTP request' do
|
|
82
|
+
test 'return 401 status' do
|
|
83
|
+
call_failure('formats' => :xml)
|
|
84
|
+
assert_equal 401, @response.first
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test 'return 401 status for unknown formats' do
|
|
88
|
+
call_failure 'formats' => []
|
|
89
|
+
assert_equal 401, @response.first
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
test 'return WWW-authenticate headers if model allows' do
|
|
93
|
+
call_failure('formats' => :xml)
|
|
94
|
+
assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
test 'does not return WWW-authenticate headers if model does not allow' do
|
|
98
|
+
swap Devise, :http_authenticatable => false do
|
|
99
|
+
call_failure('formats' => :xml)
|
|
100
|
+
assert_nil @response.second["WWW-Authenticate"]
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
test 'works for any non navigational format' do
|
|
105
|
+
swap Devise, :navigational_formats => [] do
|
|
106
|
+
call_failure('formats' => :html)
|
|
107
|
+
assert_equal 401, @response.first
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
test 'uses the failure message as response body' do
|
|
112
|
+
call_failure('formats' => :xml, 'warden' => OpenStruct.new(:message => :invalid))
|
|
113
|
+
assert_match '<error>Invalid email or password.</error>', @response.third.body
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
context 'on ajax call' do
|
|
117
|
+
context 'when http_authenticatable_on_xhr is false' do
|
|
118
|
+
test 'dont return 401 with navigational formats' do
|
|
119
|
+
swap Devise, :http_authenticatable_on_xhr => false do
|
|
120
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
121
|
+
assert_equal 302, @response.first
|
|
122
|
+
assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
test 'dont return 401 with non navigational formats' do
|
|
127
|
+
swap Devise, :http_authenticatable_on_xhr => false do
|
|
128
|
+
call_failure('formats' => :json, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
129
|
+
assert_equal 302, @response.first
|
|
130
|
+
assert_equal 'http://test.host/users/sign_in.json', @response.second["Location"]
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
context 'when http_authenticatable_on_xhr is true' do
|
|
136
|
+
test 'return 401' do
|
|
137
|
+
swap Devise, :http_authenticatable_on_xhr => true do
|
|
138
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
139
|
+
assert_equal 401, @response.first
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
test 'skip WWW-Authenticate header' do
|
|
144
|
+
swap Devise, :http_authenticatable_on_xhr => true do
|
|
145
|
+
call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')
|
|
146
|
+
assert_nil @response.second['WWW-Authenticate']
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
context 'With recall' do
|
|
154
|
+
test 'calls the original controller if invalid email or password' do
|
|
155
|
+
env = {
|
|
156
|
+
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in" },
|
|
157
|
+
"devise.mapping" => Devise.mappings[:user],
|
|
158
|
+
"warden" => stub_everything
|
|
159
|
+
}
|
|
160
|
+
call_failure(env)
|
|
161
|
+
assert @response.third.body.include?('<h2>Sign in</h2>')
|
|
162
|
+
assert @response.third.body.include?('Invalid email or password.')
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
test 'calls the original controller if not confirmed email' do
|
|
166
|
+
env = {
|
|
167
|
+
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :unconfirmed },
|
|
168
|
+
"devise.mapping" => Devise.mappings[:user],
|
|
169
|
+
"warden" => stub_everything
|
|
170
|
+
}
|
|
171
|
+
call_failure(env)
|
|
172
|
+
assert @response.third.body.include?('<h2>Sign in</h2>')
|
|
173
|
+
assert @response.third.body.include?('You have to confirm your account before continuing.')
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
test 'calls the original controller if inactive account' do
|
|
177
|
+
env = {
|
|
178
|
+
"warden.options" => { :recall => "devise/sessions#new", :attempted_path => "/users/sign_in", :message => :inactive },
|
|
179
|
+
"devise.mapping" => Devise.mappings[:user],
|
|
180
|
+
"warden" => stub_everything
|
|
181
|
+
}
|
|
182
|
+
call_failure(env)
|
|
183
|
+
assert @response.third.body.include?('<h2>Sign in</h2>')
|
|
184
|
+
assert @response.third.body.include?('Your account was not activated yet.')
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
if DEVISE_ORM == :active_record
|
|
4
|
+
require "generators/active_record/devise_generator"
|
|
5
|
+
|
|
6
|
+
class ActiveRecordGeneratorTest < Rails::Generators::TestCase
|
|
7
|
+
tests ActiveRecord::Generators::DeviseGenerator
|
|
8
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
9
|
+
setup :prepare_destination
|
|
10
|
+
|
|
11
|
+
test "all files are properly created" do
|
|
12
|
+
run_generator %w(monster)
|
|
13
|
+
assert_file "app/models/monster.rb", /devise/, /attr_accessible (:[a-z_]+(, )?)+/
|
|
14
|
+
assert_migration "db/migrate/devise_create_monsters.rb"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test "all files are properly deleted" do
|
|
18
|
+
run_generator %w(monster)
|
|
19
|
+
run_generator %w(monster), :behavior => :revoke
|
|
20
|
+
assert_no_file "app/models/monster.rb"
|
|
21
|
+
assert_no_migration "db/migrate/devise_create_monsters.rb"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class InstallGeneratorTest < Rails::Generators::TestCase
|
|
4
|
+
tests Devise::Generators::InstallGenerator
|
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
6
|
+
setup :prepare_destination
|
|
7
|
+
|
|
8
|
+
test "Assert all files are properly created" do
|
|
9
|
+
run_generator
|
|
10
|
+
assert_file "config/initializers/devise.rb"
|
|
11
|
+
assert_file "config/locales/devise.en.yml"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
if DEVISE_ORM == :mongo_id
|
|
4
|
+
require "generators/mongo_id/devise_generator"
|
|
5
|
+
|
|
6
|
+
class MongoidGeneratorTest < Rails::Generators::TestCase
|
|
7
|
+
tests Mongoid::Generators::DeviseGenerator
|
|
8
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
9
|
+
setup :prepare_destination
|
|
10
|
+
|
|
11
|
+
test "all files are properly created" do
|
|
12
|
+
run_generator %w(monster)
|
|
13
|
+
assert_file "app/models/monster.rb", /devise/
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test "all files are properly deleted" do
|
|
17
|
+
run_generator %w(monster)
|
|
18
|
+
run_generator %w(monster), :behavior => :revoke
|
|
19
|
+
assert_no_file "app/models/monster.rb"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
class ViewsGeneratorTest < Rails::Generators::TestCase
|
|
4
|
+
tests Devise::Generators::ViewsGenerator
|
|
5
|
+
destination File.expand_path("../../tmp", __FILE__)
|
|
6
|
+
setup :prepare_destination
|
|
7
|
+
|
|
8
|
+
test "Assert all views are properly created with no params" do
|
|
9
|
+
run_generator
|
|
10
|
+
assert_files
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test "Assert all views are properly created with scope param param" do
|
|
14
|
+
run_generator %w(users)
|
|
15
|
+
assert_files "users"
|
|
16
|
+
|
|
17
|
+
run_generator %w(admins)
|
|
18
|
+
assert_files "admins"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def assert_files(scope = nil, template_engine = nil)
|
|
22
|
+
scope = "devise" if scope.nil?
|
|
23
|
+
assert_file "app/views/#{scope}/confirmations/new.html.erb"
|
|
24
|
+
assert_file "app/views/#{scope}/mailer/confirmation_instructions.html.erb"
|
|
25
|
+
assert_file "app/views/#{scope}/mailer/reset_password_instructions.html.erb"
|
|
26
|
+
assert_file "app/views/#{scope}/mailer/unlock_instructions.html.erb"
|
|
27
|
+
assert_file "app/views/#{scope}/passwords/edit.html.erb"
|
|
28
|
+
assert_file "app/views/#{scope}/passwords/new.html.erb"
|
|
29
|
+
assert_file "app/views/#{scope}/registrations/new.html.erb"
|
|
30
|
+
assert_file "app/views/#{scope}/registrations/edit.html.erb"
|
|
31
|
+
assert_file "app/views/#{scope}/sessions/new.html.erb"
|
|
32
|
+
assert_file "app/views/#{scope}/shared/_links.erb"
|
|
33
|
+
assert_file "app/views/#{scope}/unlocks/new.html.erb"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class IndifferentHashTest < ActiveSupport::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
@hash = Devise::IndifferentHash.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
test "it overwrites getter and setter" do
|
|
9
|
+
@hash[:foo] = "bar"
|
|
10
|
+
assert_equal "bar", @hash["foo"]
|
|
11
|
+
assert_equal "bar", @hash[:foo]
|
|
12
|
+
|
|
13
|
+
@hash["foo"] = "baz"
|
|
14
|
+
assert_equal "baz", @hash["foo"]
|
|
15
|
+
assert_equal "baz", @hash[:foo]
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test "it overwrites update" do
|
|
19
|
+
@hash.update :foo => "bar"
|
|
20
|
+
assert_equal "bar", @hash["foo"]
|
|
21
|
+
assert_equal "bar", @hash[:foo]
|
|
22
|
+
|
|
23
|
+
@hash.update "foo" => "baz"
|
|
24
|
+
assert_equal "baz", @hash["foo"]
|
|
25
|
+
assert_equal "baz", @hash[:foo]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test "it returns a Hash on to_hash" do
|
|
29
|
+
@hash[:foo] = "bar"
|
|
30
|
+
assert_equal Hash["foo", "bar"], @hash.to_hash
|
|
31
|
+
assert_kind_of Hash, @hash.to_hash
|
|
32
|
+
end
|
|
33
|
+
end if defined?(Devise::IndifferentHash)
|