devise 1.0.11 → 1.1.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of devise might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +6 -72
- data/Gemfile +18 -0
- data/README.rdoc +51 -46
- data/Rakefile +5 -4
- data/app/controllers/{confirmations_controller.rb → devise/confirmations_controller.rb} +2 -2
- data/app/controllers/{passwords_controller.rb → devise/passwords_controller.rb} +4 -3
- data/app/controllers/{registrations_controller.rb → devise/registrations_controller.rb} +11 -7
- data/app/controllers/{sessions_controller.rb → devise/sessions_controller.rb} +11 -8
- data/app/controllers/{unlocks_controller.rb → devise/unlocks_controller.rb} +2 -10
- data/app/models/devise/mailer.rb +55 -0
- data/app/views/{confirmations → devise/confirmations}/new.html.erb +1 -1
- 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 → devise/passwords}/edit.html.erb +1 -1
- data/app/views/{passwords → devise/passwords}/new.html.erb +1 -1
- data/app/views/{registrations → devise/registrations}/edit.html.erb +1 -1
- data/app/views/{registrations → devise/registrations}/new.html.erb +1 -1
- data/app/views/{sessions → devise/sessions}/new.html.erb +1 -1
- data/app/views/{shared/_devise_links.erb → devise/shared/_links.erb} +0 -0
- data/app/views/{unlocks → devise/unlocks}/new.html.erb +1 -1
- data/{lib/devise → config}/locales/en.yml +7 -1
- data/lib/devise.rb +6 -29
- data/lib/devise/controllers/helpers.rb +16 -43
- data/lib/devise/controllers/internal_helpers.rb +10 -36
- data/lib/devise/controllers/scoped_views.rb +35 -0
- data/lib/devise/failure_app.rb +7 -14
- data/lib/devise/hooks/rememberable.rb +3 -6
- data/lib/devise/hooks/trackable.rb +1 -1
- data/lib/devise/mapping.rb +17 -18
- data/lib/devise/models.rb +4 -20
- data/lib/devise/models/{database_authenticatable.rb → authenticatable.rb} +16 -28
- data/lib/devise/models/confirmable.rb +25 -23
- data/lib/devise/models/http_authenticatable.rb +3 -7
- data/lib/devise/models/lockable.rb +40 -35
- data/lib/devise/models/recoverable.rb +4 -8
- data/lib/devise/models/rememberable.rb +6 -9
- data/lib/devise/models/timeoutable.rb +1 -3
- data/lib/devise/models/token_authenticatable.rb +4 -5
- data/lib/devise/models/validatable.rb +10 -1
- data/lib/devise/orm/mongo_mapper.rb +10 -23
- data/lib/devise/rails.rb +11 -9
- data/lib/devise/rails/routes.rb +113 -107
- data/lib/devise/rails/warden_compat.rb +3 -41
- data/lib/devise/schema.rb +13 -21
- data/lib/devise/strategies/{database_authenticatable.rb → authenticatable.rb} +3 -3
- data/lib/devise/strategies/http_authenticatable.rb +4 -22
- data/lib/devise/test_helpers.rb +1 -8
- data/lib/devise/version.rb +1 -1
- data/lib/generators/devise/devise_generator.rb +57 -0
- data/{generators → lib/generators}/devise/templates/migration.rb +1 -1
- data/lib/generators/devise_install/devise_install_generator.rb +25 -0
- data/{generators → lib/generators}/devise_install/templates/README +4 -8
- data/{generators → lib/generators}/devise_install/templates/devise.rb +0 -3
- data/lib/generators/devise_views/devise_views_generator.rb +11 -0
- data/test/controllers/helpers_test.rb +15 -9
- data/test/devise_test.rb +1 -6
- data/test/encryptors_test.rb +0 -3
- data/test/failure_app_test.rb +6 -1
- data/test/integration/authenticatable_test.rb +25 -85
- data/test/integration/http_authenticatable_test.rb +2 -10
- data/test/integration/lockable_test.rb +3 -22
- data/test/integration/recoverable_test.rb +1 -1
- data/test/integration/registerable_test.rb +31 -36
- data/test/integration/rememberable_test.rb +6 -24
- data/test/integration/token_authenticatable_test.rb +2 -4
- data/test/integration/trackable_test.rb +1 -1
- data/test/mailers/confirmation_instructions_test.rb +4 -10
- data/test/mailers/unlock_instructions_test.rb +1 -1
- data/test/mapping_test.rb +12 -24
- data/test/models/authenticatable_test.rb +3 -3
- data/test/models/confirmable_test.rb +29 -29
- data/test/models/http_authenticatable_test.rb +19 -0
- data/test/models/lockable_test.rb +45 -44
- data/test/models/recoverable_test.rb +7 -7
- data/test/models/rememberable_test.rb +7 -10
- data/test/models/validatable_test.rb +19 -24
- data/test/models_test.rb +2 -16
- data/test/orm/active_record.rb +3 -4
- data/test/orm/mongo_mapper.rb +2 -10
- data/test/rails_app/app/active_record/admin.rb +1 -1
- data/test/rails_app/app/active_record/user.rb +3 -3
- data/test/rails_app/app/controllers/application_controller.rb +1 -7
- data/test/rails_app/app/controllers/sessions_controller.rb +6 -0
- data/test/rails_app/app/controllers/users_controller.rb +0 -4
- data/test/rails_app/app/mongo_mapper/admin.rb +4 -7
- data/test/rails_app/app/mongo_mapper/user.rb +5 -8
- data/test/rails_app/config/application.rb +32 -0
- data/test/rails_app/config/boot.rb +7 -108
- 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 +23 -22
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/cookie_verification_secret.rb +7 -0
- data/test/rails_app/config/initializers/devise.rb +0 -3
- data/test/rails_app/config/initializers/session_store.rb +2 -2
- data/test/rails_app/config/routes.rb +17 -21
- data/test/routes_test.rb +30 -47
- data/test/support/{assertions_helper.rb → assertions.rb} +0 -15
- data/test/support/{tests_helper.rb → helpers.rb} +16 -3
- data/test/support/{integration_tests_helper.rb → integration.rb} +8 -4
- data/test/support/webrat/integrations/rails.rb +31 -0
- data/test/test_helper.rb +8 -7
- data/test/test_helpers_test.rb +9 -9
- metadata +53 -128
- data/app/models/devise_mailer.rb +0 -68
- data/app/views/devise_mailer/confirmation_instructions.html.erb +0 -5
- data/app/views/devise_mailer/reset_password_instructions.html.erb +0 -8
- data/app/views/devise_mailer/unlock_instructions.html.erb +0 -7
- 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_views/USAGE +0 -3
- data/generators/devise_views/devise_views_generator.rb +0 -21
- data/rails/init.rb +0 -2
- data/test/integration/rack_middleware_test.rb +0 -47
- data/test/rails_app/config/initializers/new_rails_defaults.rb +0 -24
@@ -1,6 +1,6 @@
|
|
1
1
|
module Warden::Mixins::Common
|
2
2
|
def request
|
3
|
-
@request ||= env
|
3
|
+
@request ||= ActionDispatch::Request.new(env)
|
4
4
|
end
|
5
5
|
|
6
6
|
def reset_session!
|
@@ -9,7 +9,7 @@ module Warden::Mixins::Common
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def response
|
12
|
-
@response ||= env['action_controller.
|
12
|
+
@response ||= env['action_controller.instance'].response
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -22,42 +22,4 @@ class Warden::SessionSerializer
|
|
22
22
|
klass, id = keys
|
23
23
|
klass.find(:first, :conditions => { :id => id })
|
24
24
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class ActionController::Request
|
28
|
-
def reset_session
|
29
|
-
session.destroy if session && session.respond_to?(:destroy)
|
30
|
-
self.session = {}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Solve a bug in Rails where Set-Cookie is returning an array.
|
35
|
-
class Devise::CookieSanitizer
|
36
|
-
SET_COOKIE = "Set-Cookie".freeze
|
37
|
-
|
38
|
-
def initialize(app)
|
39
|
-
@app = app
|
40
|
-
end
|
41
|
-
|
42
|
-
def call(env)
|
43
|
-
response = @app.call(env)
|
44
|
-
headers = response[1]
|
45
|
-
cookies = headers[SET_COOKIE]
|
46
|
-
if cookies.respond_to?(:join)
|
47
|
-
headers[SET_COOKIE] = cookies.join("\n").squeeze("\n")
|
48
|
-
end
|
49
|
-
response
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
Rails.configuration.middleware.insert_after ActionController::Failsafe, Devise::CookieSanitizer
|
54
|
-
|
55
|
-
Warden::Manager.after_set_user :event => [:set_user, :authentication] do |record, warden, options|
|
56
|
-
if options[:scope] && warden.authenticated?(options[:scope])
|
57
|
-
request = warden.request
|
58
|
-
backup = request.session.to_hash
|
59
|
-
backup.delete(:session_id)
|
60
|
-
request.reset_session
|
61
|
-
request.session.update(backup)
|
62
|
-
end
|
63
|
-
end
|
25
|
+
end
|
data/lib/devise/schema.rb
CHANGED
@@ -3,55 +3,47 @@ module Devise
|
|
3
3
|
# and overwrite the apply_schema method.
|
4
4
|
module Schema
|
5
5
|
|
6
|
-
def authenticatable(*args)
|
7
|
-
ActiveSupport::Deprecation.warn "t.authenticatable in migrations is deprecated. Please use t.database_authenticatable instead.", caller
|
8
|
-
database_authenticatable(*args)
|
9
|
-
end
|
10
|
-
|
11
6
|
# Creates email, encrypted_password and password_salt.
|
12
7
|
#
|
13
8
|
# == Options
|
14
9
|
# * :null - When true, allow columns to be null.
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
if options.delete(:encryptor)
|
20
|
-
ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it."
|
21
|
-
end
|
10
|
+
# * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length.
|
11
|
+
def authenticatable(options={})
|
12
|
+
null = options[:null] || false
|
13
|
+
encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1)
|
22
14
|
|
23
|
-
apply_schema :email, String, :null => null
|
24
|
-
apply_schema :encrypted_password, String, :null => null, :
|
25
|
-
apply_schema :password_salt, String, :null => null
|
15
|
+
apply_schema :email, String, :null => null
|
16
|
+
apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
|
17
|
+
apply_schema :password_salt, String, :null => null
|
26
18
|
end
|
27
19
|
|
28
20
|
# Creates authentication_token.
|
29
21
|
def token_authenticatable
|
30
|
-
apply_schema :authentication_token, String
|
22
|
+
apply_schema :authentication_token, String, :limit => 20
|
31
23
|
end
|
32
24
|
|
33
25
|
# Creates confirmation_token, confirmed_at and confirmation_sent_at.
|
34
26
|
def confirmable
|
35
|
-
apply_schema :confirmation_token, String
|
27
|
+
apply_schema :confirmation_token, String, :limit => 20
|
36
28
|
apply_schema :confirmed_at, DateTime
|
37
29
|
apply_schema :confirmation_sent_at, DateTime
|
38
30
|
end
|
39
31
|
|
40
32
|
# Creates reset_password_token.
|
41
33
|
def recoverable
|
42
|
-
apply_schema :reset_password_token, String
|
34
|
+
apply_schema :reset_password_token, String, :limit => 20
|
43
35
|
end
|
44
36
|
|
45
37
|
# Creates remember_token and remember_created_at.
|
46
38
|
def rememberable
|
47
|
-
apply_schema :remember_token, String
|
39
|
+
apply_schema :remember_token, String, :limit => 20
|
48
40
|
apply_schema :remember_created_at, DateTime
|
49
41
|
end
|
50
42
|
|
51
43
|
# Creates sign_in_count, current_sign_in_at, last_sign_in_at,
|
52
44
|
# current_sign_in_ip, last_sign_in_ip.
|
53
45
|
def trackable
|
54
|
-
apply_schema :sign_in_count, Integer
|
46
|
+
apply_schema :sign_in_count, Integer
|
55
47
|
apply_schema :current_sign_in_at, DateTime
|
56
48
|
apply_schema :last_sign_in_at, DateTime
|
57
49
|
apply_schema :current_sign_in_ip, String
|
@@ -61,7 +53,7 @@ module Devise
|
|
61
53
|
# Creates failed_attempts, unlock_token and locked_at
|
62
54
|
def lockable
|
63
55
|
apply_schema :failed_attempts, Integer, :default => 0
|
64
|
-
apply_schema :unlock_token, String
|
56
|
+
apply_schema :unlock_token, String, :limit => 20
|
65
57
|
apply_schema :locked_at, DateTime
|
66
58
|
end
|
67
59
|
|
@@ -4,7 +4,7 @@ module Devise
|
|
4
4
|
module Strategies
|
5
5
|
# Default strategy for signing in a user, based on his email and password.
|
6
6
|
# Redirects to sign_in page if it's not authenticated
|
7
|
-
class
|
7
|
+
class Authenticatable < Base
|
8
8
|
def valid?
|
9
9
|
valid_controller? && valid_params? && mapping.to.respond_to?(:authenticate)
|
10
10
|
end
|
@@ -16,7 +16,7 @@ module Devise
|
|
16
16
|
if resource = mapping.to.authenticate(params[scope])
|
17
17
|
success!(resource)
|
18
18
|
else
|
19
|
-
fail(:invalid)
|
19
|
+
fail!(:invalid)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -33,4 +33,4 @@ module Devise
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
Warden::Strategies.add(:
|
36
|
+
Warden::Strategies.add(:authenticatable, Devise::Strategies::Authenticatable)
|
@@ -5,7 +5,7 @@ module Devise
|
|
5
5
|
# Sign in an user using HTTP authentication.
|
6
6
|
class HttpAuthenticatable < Base
|
7
7
|
def valid?
|
8
|
-
|
8
|
+
request.authorization && mapping.to.respond_to?(:authenticate_with_http)
|
9
9
|
end
|
10
10
|
|
11
11
|
def authenticate!
|
@@ -14,7 +14,7 @@ module Devise
|
|
14
14
|
if resource = mapping.to.authenticate_with_http(username, password)
|
15
15
|
success!(resource)
|
16
16
|
else
|
17
|
-
custom!([401, custom_headers, [
|
17
|
+
custom!([401, custom_headers, ["HTTP Basic: Access denied.\n"]])
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -24,34 +24,16 @@ module Devise
|
|
24
24
|
decode_credentials(request).split(/:/, 2)
|
25
25
|
end
|
26
26
|
|
27
|
-
def response_body
|
28
|
-
body = "HTTP Basic: Access denied."
|
29
|
-
method = :"to_#{request_format.to_sym}"
|
30
|
-
{}.respond_to?(method) ? { :error => body }.send(method) : body
|
31
|
-
end
|
32
|
-
|
33
|
-
def http_authentication
|
34
|
-
request.env['HTTP_AUTHORIZATION'] ||
|
35
|
-
request.env['X-HTTP_AUTHORIZATION'] ||
|
36
|
-
request.env['X_HTTP_AUTHORIZATION'] ||
|
37
|
-
request.env['REDIRECT_X_HTTP_AUTHORIZATION']
|
38
|
-
end
|
39
|
-
alias :http_authentication? :http_authentication
|
40
|
-
|
41
27
|
def decode_credentials(request)
|
42
|
-
ActiveSupport::Base64.decode64(
|
28
|
+
ActiveSupport::Base64.decode64(request.authorization.split(' ', 2).last || '')
|
43
29
|
end
|
44
30
|
|
45
31
|
def custom_headers
|
46
32
|
{
|
47
|
-
"Content-Type" =>
|
33
|
+
"Content-Type" => "text/plain",
|
48
34
|
"WWW-Authenticate" => %(Basic realm="#{Devise.http_authentication_realm.gsub(/"/, "")}")
|
49
35
|
}
|
50
36
|
end
|
51
|
-
|
52
|
-
def request_format
|
53
|
-
@request_format ||= Mime::Type.lookup_by_extension(request.template_format.to_s)
|
54
|
-
end
|
55
37
|
end
|
56
38
|
end
|
57
39
|
end
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -24,10 +24,6 @@ module Devise
|
|
24
24
|
catch_with_redirect { super }
|
25
25
|
end
|
26
26
|
|
27
|
-
def user(*args)
|
28
|
-
catch_with_redirect { super }
|
29
|
-
end
|
30
|
-
|
31
27
|
def catch_with_redirect(&block)
|
32
28
|
result = catch(:warden, &block)
|
33
29
|
|
@@ -49,10 +45,7 @@ module Devise
|
|
49
45
|
|
50
46
|
# We need to setup the environment variables and the response in the controller.
|
51
47
|
def setup_controller_for_warden #:nodoc:
|
52
|
-
@request.env['action_controller.
|
53
|
-
@request.env['action_controller.rescue.response'] = @response
|
54
|
-
@request.env['rack.session'] = session
|
55
|
-
@controller.response = @response
|
48
|
+
@request.env['action_controller.instance'] = @controller
|
56
49
|
end
|
57
50
|
|
58
51
|
# Quick access to Warden::Proxy.
|
data/lib/devise/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class DeviseGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
desc "Generates a model with the given NAME (if one does not exist) with devise " <<
|
7
|
+
"configuration plus a migration file and devise routes."
|
8
|
+
|
9
|
+
def self.source_root
|
10
|
+
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.orm_has_migration?
|
14
|
+
Rails::Generators.options[:rails][:orm] == :active_record
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.next_migration_number(path)
|
18
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
19
|
+
end
|
20
|
+
|
21
|
+
class_option :migration, :type => :boolean, :default => orm_has_migration?
|
22
|
+
|
23
|
+
def invoke_orm_model
|
24
|
+
if File.exists?(File.join(destination_root, model_path))
|
25
|
+
say "* Model already exists. Adding Devise behavior."
|
26
|
+
else
|
27
|
+
invoke "model", [name], :migration => false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def inject_devise_config_into_model
|
32
|
+
inject_into_class model_path, class_name, <<-CONTENT
|
33
|
+
# Include default devise modules. Others available are:
|
34
|
+
# :http_authenticatable, :token_authenticatable, :lockable, :timeoutable and :activatable
|
35
|
+
devise :registerable, :authenticatable, :confirmable, :recoverable,
|
36
|
+
:rememberable, :trackable, :validatable
|
37
|
+
|
38
|
+
# Setup accessible (or protected) attributes for your model
|
39
|
+
attr_accessible :email, :password, :password_confirmation
|
40
|
+
CONTENT
|
41
|
+
end
|
42
|
+
|
43
|
+
def copy_migration_template
|
44
|
+
return unless options.migration?
|
45
|
+
migration_template "migration.rb", "db/migrate/devise_create_#{table_name}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_devise_routes
|
49
|
+
route "devise_for :#{table_name}"
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def model_path
|
55
|
+
@model_path ||= File.join("app", "models", "#{file_path}.rb")
|
56
|
+
end
|
57
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
4
|
-
t.
|
4
|
+
t.authenticatable :encryptor => :sha1, :null => false
|
5
5
|
t.confirmable
|
6
6
|
t.recoverable
|
7
7
|
t.rememberable
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class DeviseInstallGenerator < Rails::Generators::Base
|
2
|
+
desc "Creates a Devise initializer and copy locale files to your application."
|
3
|
+
|
4
|
+
def self.source_root
|
5
|
+
@_devise_source_root ||= File.expand_path("../templates", __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "devise.rb", "config/initializers/devise.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_locale
|
13
|
+
copy_file "../../../../config/locales/en.yml", "config/locales/devise.en.yml"
|
14
|
+
end
|
15
|
+
|
16
|
+
def show_readme
|
17
|
+
readme "README"
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def readme(path)
|
23
|
+
say File.read(File.expand_path(path, self.class.source_root))
|
24
|
+
end
|
25
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
===============================================================================
|
2
3
|
|
3
4
|
Some setup you must do manually if you haven't yet:
|
@@ -10,14 +11,9 @@ Some setup you must do manually if you haven't yet:
|
|
10
11
|
This is a required Rails configuration. In production is must be the
|
11
12
|
actual host of your application
|
12
13
|
|
13
|
-
2. Ensure you have defined root_url to *something* in your config/routes.rb
|
14
|
-
|
15
|
-
map.root :controller => 'home'
|
16
|
-
|
17
|
-
3. Ensure you have a default layout in app/views/layouts and it shows
|
18
|
-
flash messages. For example:
|
14
|
+
2. Ensure you have defined root_url to *something* in your config/routes.rb.
|
15
|
+
For example:
|
19
16
|
|
20
|
-
|
21
|
-
<p class="alert"><%= flash[:alert] %></p>
|
17
|
+
root :to => "home#index"
|
22
18
|
|
23
19
|
===============================================================================
|
@@ -3,9 +3,6 @@
|
|
3
3
|
Devise.setup do |config|
|
4
4
|
# Configure the e-mail address which will be shown in DeviseMailer.
|
5
5
|
config.mailer_sender = "please-change-me@config-initializers-devise.com"
|
6
|
-
|
7
|
-
# Configure the content type of DeviseMailer mails (defaults to text/html")
|
8
|
-
# config.mailer_content_type = "text/plain"
|
9
6
|
|
10
7
|
# ==> Configuration for :authenticatable
|
11
8
|
# Invoke `rake secret` and use the printed value to setup a pepper to generate
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class DeviseViewsGenerator < Rails::Generators::Base
|
2
|
+
desc "Copies all Devise views to your application."
|
3
|
+
|
4
|
+
def self.source_root
|
5
|
+
@_devise_source_root ||= File.expand_path("../../../../app/views", __FILE__)
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_views
|
9
|
+
directory "devise"
|
10
|
+
end
|
11
|
+
end
|
@@ -11,16 +11,29 @@ class MockController < ApplicationController
|
|
11
11
|
def path
|
12
12
|
''
|
13
13
|
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
end
|
17
|
+
|
18
|
+
def host_with_port
|
19
|
+
"test.host:3000"
|
20
|
+
end
|
21
|
+
|
22
|
+
def protocol
|
23
|
+
"http"
|
24
|
+
end
|
25
|
+
|
26
|
+
def symbolized_path_parameters
|
27
|
+
{}
|
28
|
+
end
|
14
29
|
end
|
15
30
|
|
16
31
|
class ControllerAuthenticableTest < ActionController::TestCase
|
17
32
|
tests MockController
|
18
33
|
|
19
34
|
def setup
|
20
|
-
@controller = MockController.new
|
21
35
|
@mock_warden = OpenStruct.new
|
22
36
|
@controller.env = { 'warden' => @mock_warden }
|
23
|
-
@controller.session = {}
|
24
37
|
end
|
25
38
|
|
26
39
|
test 'setup warden' do
|
@@ -36,13 +49,6 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
|
36
49
|
@controller.signed_in?(:my_scope)
|
37
50
|
end
|
38
51
|
|
39
|
-
test 'proxy anybody_signed_in? to signed_in?' do
|
40
|
-
Devise.mappings.keys.each { |scope| # :user, :admin, :manager
|
41
|
-
@controller.expects(:signed_in?).with(scope)
|
42
|
-
}
|
43
|
-
@controller.anybody_signed_in?
|
44
|
-
end
|
45
|
-
|
46
52
|
test 'proxy current_admin to authenticate with admin scope' do
|
47
53
|
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
48
54
|
@controller.current_admin
|
data/test/devise_test.rb
CHANGED
@@ -25,7 +25,7 @@ class DeviseTest < ActiveSupport::TestCase
|
|
25
25
|
Devise.configure_warden(config)
|
26
26
|
|
27
27
|
assert_equal Devise::FailureApp, config.failure_app
|
28
|
-
assert_equal [:rememberable, :http_authenticatable, :token_authenticatable, :
|
28
|
+
assert_equal [:rememberable, :http_authenticatable, :token_authenticatable, :authenticatable], config.default_strategies
|
29
29
|
assert_equal :user, config.default_scope
|
30
30
|
assert config.silence_missing_strategies?
|
31
31
|
end
|
@@ -63,11 +63,6 @@ class DeviseTest < ActiveSupport::TestCase
|
|
63
63
|
Devise::ALL.delete(:kivi)
|
64
64
|
Devise::CONTROLLERS.delete(:fruits)
|
65
65
|
|
66
|
-
assert_nothing_raised(Exception) { Devise.add_module(:carrot, :route => :vegetable) }
|
67
|
-
assert_equal 1, Devise::ROUTES.select { |v| v == :vegetable }.size
|
68
|
-
Devise::ALL.delete(:carrot)
|
69
|
-
Devise::ROUTES.delete(:vegetable)
|
70
|
-
|
71
66
|
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
72
67
|
assert defined?(Devise::Models::AuthenticatableAgain)
|
73
68
|
end
|