devise 0.3.0 → 0.4.0

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.

@@ -1,3 +1,16 @@
1
+ * deprecations
2
+ * Notifier is deprecated, use DeviseMailer instead. Remember to rename
3
+ app/views/notifier to app/views/devise_mailer and I18n key from
4
+ devise.notifier to devise.mailer
5
+ * :authenticable calls are deprecated, use :authenticatable instead
6
+
7
+ * enhancements
8
+ * [#16] Allow devise to be more agnostic. Do not require ActiveRecord to be loaded.
9
+ * Allow Warden::Manager to be configured through Devise
10
+ * Created a generator which creates an initializer
11
+
12
+ == 0.3.0
13
+
1
14
  * bug fix
2
15
  * [#15] Allow yml messages to be configured by not using engine locales
3
16
 
@@ -91,29 +91,11 @@ You could also include the other devise modules as below:
91
91
 
92
92
  Note that validations aren't added by default, so you're able to customize it. In order to have automatic validations working just include :validatable.
93
93
 
94
- == Configuration values
94
+ == Model configuration
95
95
 
96
- In addition to :except, you can provide some options to devise call:
96
+ In addition to :except, you can provide :pepper, :stretches, :confirm_within and :remember_for as options to devise method.
97
97
 
98
- * pepper: setup a pepper to generate de encrypted password. By default no pepper is used:
99
-
100
- devise :all, :pepper => 'my_pepper'
101
-
102
- * stretches: configure how many times you want the password is reencrypted.
103
-
104
- devise :all, :stretches => 20
105
-
106
- * confirm_within: the time the user can access the site before being blocked because his account was not confirmed
107
-
108
- devise :all, :confirm_within => 1.week
109
-
110
- * remember_for: the time to store the remember me cookie in the user
111
-
112
- devise :all, :remember_for => 2.weeks
113
-
114
- All those values can also be set in a global way by setting them in Devise:
115
-
116
- Devise.confirm_within = 1.week
98
+ All those options are described in "config/initializers/devise.rb", which is generated when you invoke `ruby script/generate devise_install` in your application root.
117
99
 
118
100
  == Routes
119
101
 
@@ -140,23 +122,12 @@ This is going to look inside you User model and create the needed routes:
140
122
  POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
141
123
 
142
124
  You can run the routes rake task to verify what routes are being created by devise.
143
- There are also some options available for configuring your routes:
144
-
145
- * :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
146
-
147
- map.devise_for :users, :class_name => 'Account'
148
-
149
- * :as => allows you to setup path name that will be used, as rails routes does. The following route configuration would setup your route as /accounts instead of /users:
150
125
 
151
- map.devise_for :users, :as => 'accounts'
126
+ There are also some options available for configuring your routes, as :class_name (to set the class for that route), :as and :path_names, where the last two have the same meaning as in routes. The available :path_names are:
152
127
 
153
- * :singular => setup the name used to create named routes. By default, for a :users key, it is going to be the singularized version, :user. To configure a named route like account_session_path instead of user_session_path just do:
128
+ map.devise_for :users, :as => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
154
129
 
155
- map.devise_for :users, :singular => :account
156
-
157
- * :path_names => configure different path names to overwrite defaults :sign_in, :sign_out, :password and :confirmation.
158
-
159
- map.devise_for :users, :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification' }
130
+ Be sure to check devise_for documentation for detailed description.
160
131
 
161
132
  == Controller filters
162
133
 
@@ -182,7 +153,7 @@ After signing in a user, confirming it's account or updating it's password, devi
182
153
 
183
154
  You also need to setup default url options for the mailer, if you are using confirmable or recoverable. Here's is the configuration for development:
184
155
 
185
- Notifier.sender = "no-reply@yourapp.com"
156
+ DeviseMailer.sender = "no-reply@yourapp.com"
186
157
  ActionMailer::Base.default_url_options = { :host => 'localhost:3000' }
187
158
 
188
159
  == Tidying up
@@ -212,15 +183,19 @@ Devise let's you setup as many roles as you want, so let's say you already have
212
183
 
213
184
  Devise comes with some generators to help you start:
214
185
 
215
- script/generate devise Model
186
+ ruby script/generate devise_install
187
+
188
+ This will generate an initializer, with a description of all configuration values. You can also generate models through:
189
+
190
+ ruby script/generate devise Model
216
191
 
217
- Will generate a model, configured with all devise modules, and add attr_accessible for default fields, so you can setup more accessible attributes later. The generator will also create the migration and configure your route for devise.
192
+ A model configured with all devise modules and attr_accessible for default fields will be created. The generator will also create the migration and configure your routes for devise.
218
193
 
219
194
  You can also copy devise views to your application, being able to modify them based on your needs. To do it so, run the following command:
220
195
 
221
- script/generate devise_views
196
+ ruby script/generate devise_views
222
197
 
223
- This is gonna copy all session, password, confirmation and notifier views to your app/views folder.
198
+ This is gonna copy all session, password, confirmation and mailer views to your app/views folder.
224
199
 
225
200
  == I18n
226
201
 
@@ -241,11 +216,11 @@ You can also create distinct messages based on the resource you've configured us
241
216
  admin:
242
217
  signed_in: 'Hello admin!'
243
218
 
244
- Devise notifier uses the same pattern to create subject messages:
219
+ Devise mailer uses the same pattern to create subject messages:
245
220
 
246
221
  en:
247
222
  devise:
248
- notifier:
223
+ mailer:
249
224
  confirmation_instructions: 'Hello everybody!'
250
225
  user:
251
226
  confirmation_instructions: 'Hello User! Please confirm your email'
@@ -1,5 +1,15 @@
1
- class Notifier < ::ActionMailer::Base
2
- cattr_accessor :sender
1
+ class DeviseMailer < ::ActionMailer::Base
2
+
3
+ # Sets who is sending the e-mail
4
+ def self.sender=(value)
5
+ @@sender = value
6
+ end
7
+
8
+ # Reads who is sending the e-mail
9
+ def self.sender
10
+ @@sender
11
+ end
12
+ self.sender = nil
3
13
 
4
14
  # Deliver confirmation instructions when the user is created or its email is
5
15
  # updated, and also when confirmation is manually requested
@@ -33,12 +43,11 @@ class Notifier < ::ActionMailer::Base
33
43
  #
34
44
  # en:
35
45
  # devise:
36
- # notifier:
46
+ # mailer:
37
47
  # confirmation_instructions: '...'
38
48
  # user:
39
- # notifier:
40
- # confirmation_instructions: '...'
49
+ # confirmation_instructions: '...'
41
50
  def translate(mapping, key)
42
- I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :notifier], :default => key)
51
+ I18n.t(:"#{mapping.name}.#{key}", :scope => [:devise, :mailer], :default => key)
43
52
  end
44
53
  end
@@ -0,0 +1,3 @@
1
+ To copy a Devise initializer to your Rails App, with some configuration values, just do:
2
+
3
+ script/generate devise_install
@@ -0,0 +1,9 @@
1
+ class DeviseInstallGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.file "devise.rb", "config/initializers/devise.rb"
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,33 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # Invoke `rake secret` and use the printed value to setup a pepper to generate
5
+ # the encrypted password. By default no pepper is used.
6
+ # config.pepper = "rake secret output"
7
+
8
+ # Configure how many times you want the password is reencrypted. Default is 10.
9
+ # config.stretches = 10
10
+
11
+ # The time you want give to your user to confirm his account. During this time
12
+ # he will be able to access your application without confirming. Default is nil.
13
+ # config.confirm_within = 2.days
14
+
15
+ # The time the user will be remembered without asking for credentials again.
16
+ # config.remember_for = 2.weeks
17
+
18
+ # Configure the e-mail address which will be shown in DeviseMailer.
19
+ # config.mail_sender = "foo.bar@yourapp.com"
20
+
21
+ # If you want to use other strategies, that are not (yet) supported by Devise,
22
+ # you can configure them inside the config.warden block. The example below
23
+ # allows you to setup OAuth, using http://github.com/roman/warden_oauth
24
+ #
25
+ # config.manager do |manager|
26
+ # manager.oauth(:twitter) do |twitter|
27
+ # twitter.consumer_secret = <YOUR CONSUMER SECRET>
28
+ # twitter.consumer_key = <YOUR CONSUMER KEY>
29
+ # twitter.options :site => 'http://twitter.com'
30
+ # end
31
+ # manager.default_strategies.unshift :twitter_oauth
32
+ # end
33
+ end
@@ -1,3 +1,3 @@
1
- To copy all session, password and confirmation views from devise to your app just run the following command:
1
+ To copy all session, password, confirmation and mailer views from devise to your app just run the following command:
2
2
 
3
3
  script/generate devise_views
@@ -8,67 +8,50 @@ module Devise
8
8
  :confirmations => :confirmable
9
9
  }.freeze
10
10
 
11
+ STRATEGIES = [:rememberable, :authenticatable].freeze
11
12
  TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
12
13
 
13
- # Creates configuration values for Devise and for the given module.
14
- #
15
- # Devise.model_config(Devise::Authenticable, :stretches, 10)
16
- #
17
- # The line above creates:
18
- #
19
- # 1) An accessor called Devise.stretches, which value is used by default;
20
- #
21
- # 2) Some class methods for your model Model.stretches and Model.stretches=
22
- # which have higher priority than Devise.stretches;
23
- #
24
- # 3) And an instance method stretches.
25
- #
26
- # To add the class methods you need to have a module ClassMethods defined
27
- # inside the given class.
28
- #
29
- def self.model_config(mod, accessor, default=nil) #:nodoc:
30
- mattr_accessor accessor
31
- send(:"#{accessor}=", default)
32
-
33
- mod.class_eval <<-METHOD, __FILE__, __LINE__
34
- def #{accessor}
35
- self.class.#{accessor}
36
- end
37
- METHOD
38
-
39
- mod.const_get(:ClassMethods).class_eval <<-METHOD, __FILE__, __LINE__
40
- def #{accessor}
41
- if defined?(@#{accessor})
42
- @#{accessor}
43
- elsif superclass.respond_to?(:#{accessor})
44
- superclass.#{accessor}
45
- else
46
- Devise.#{accessor}
47
- end
48
- end
49
-
50
- def #{accessor}=(value)
51
- @#{accessor} = value
52
- end
53
- METHOD
14
+ class << self
15
+ # Default way to setup Devise. Run script/generate devise_install to create
16
+ # a fresh initializer with all configuration values.
17
+ def setup
18
+ yield self
19
+ end
20
+
21
+ # Sets the sender in DeviseMailer.
22
+ def mail_sender=(value)
23
+ DeviseMailer.sender = value
24
+ end
25
+ alias :sender= :mail_sender=
26
+
27
+ # Sets warden configuration using a block that will be invoked on warden
28
+ # initialization.
29
+ #
30
+ # Devise.initialize do |config|
31
+ # config.confirm_within = 2.days
32
+ #
33
+ # config.warden do |manager|
34
+ # # Configure warden to use other strategies, like oauth.
35
+ # manager.oauth(:twitter)
36
+ # end
37
+ # end
38
+ def warden(&block)
39
+ @warden_config = block
40
+ end
41
+
42
+ # A method used internally to setup warden manager from the Rails initialize
43
+ # block.
44
+ def configure_warden_manager(manager) #:nodoc:
45
+ manager.default_strategies *Devise::STRATEGIES
46
+ manager.failure_app = Devise::Failure
47
+ manager.silence_missing_strategies!
48
+
49
+ # If the user provided a warden hook, call it now.
50
+ @warden_config.try :call, manager
51
+ end
54
52
  end
55
53
  end
56
54
 
57
- # Devise initialization process goes like this:
58
- #
59
- # 1) Include Devise::ActiveRecord and Devise::Migrations
60
- # 2) Load and config warden
61
- # 3) Load devise mapping structure
62
- # 4) Add routes extensions
63
- # 5) Load routes definitions
64
- # 6) Include filters and helpers in controllers and views
65
- #
66
- Rails.configuration.after_initialize do
67
- ActiveRecord::Base.extend Devise::ActiveRecord
68
- ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Migrations
69
- I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'devise', 'locales', 'en.yml'))
70
- end
71
-
72
55
  require 'devise/warden'
73
56
  require 'devise/mapping'
74
- require 'devise/routes'
57
+ require 'devise/rails'
@@ -9,10 +9,13 @@ module Devise
9
9
  def self.call(env)
10
10
  options = env['warden.options']
11
11
  scope = options[:scope]
12
- params = if env['warden'].try(:message)
13
- { env['warden'].message => true }
14
- else
15
- options[:params]
12
+ params = case env['warden'].try(:message)
13
+ when Symbol
14
+ { env['warden'].message => true }
15
+ when String
16
+ { :message => env['warden'].message }
17
+ else
18
+ options[:params]
16
19
  end
17
20
 
18
21
  redirect_path = if mapping = Devise.mappings[scope]
@@ -12,7 +12,7 @@ en:
12
12
  confirmations:
13
13
  send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
14
14
  confirmed: 'Your account was successfully confirmed. You are now signed in.'
15
- notifier:
15
+ mailer:
16
16
  confirmation_instructions: 'Confirmation instructions'
17
17
  reset_password_instructions: 'Reset password instructions'
18
18
 
@@ -26,13 +26,6 @@ module Devise
26
26
  string :password_salt, :limit => 20, :null => null
27
27
  end
28
28
 
29
- # TODO Remove me in a next release.
30
- #
31
- def authenticable(*args)
32
- ActiveSupport::Deprecation.warn "authenticable in migrations is deprecated, use authenticatable instead"
33
- authenticatable(*args)
34
- end
35
-
36
29
  # Creates confirmation_token, confirmed_at and confirmation_sent_at.
37
30
  #
38
31
  def confirmable
@@ -1,34 +1,59 @@
1
1
  module Devise
2
- module ActiveRecord
3
- # Shortcut method for including all devise modules inside your model.
4
- # You can give some extra options while declaring devise in your model:
2
+ module Models
3
+ # Creates configuration values for Devise and for the given module.
5
4
  #
6
- # * except: convenient option that allows you to add all devise modules,
7
- # removing only the modules you setup here:
5
+ # Devise::Models.config(Devise::Authenticable, :stretches, 10)
8
6
  #
9
- # devise :all, :except => :rememberable
7
+ # The line above creates:
10
8
  #
11
- # * pepper: setup a pepper to generate de encrypted password. By default no
12
- # pepper is used:
9
+ # 1) An accessor called Devise.stretches, which value is used by default;
13
10
  #
14
- # devise :all, :pepper => 'my_pepper'
11
+ # 2) Some class methods for your model Model.stretches and Model.stretches=
12
+ # which have higher priority than Devise.stretches;
15
13
  #
16
- # * stretches: configure how many times you want the password is reencrypted.
14
+ # 3) And an instance method stretches.
17
15
  #
18
- # devise :all, :stretches => 20
16
+ # To add the class methods you need to have a module ClassMethods defined
17
+ # inside the given class.
19
18
  #
20
- # * confirm_within: the time you want your user to confirm it's account. During
21
- # this time he will be able to access your application without confirming.
22
- #
23
- # devise :all, :confirm_within => 7.days
19
+ def self.config(mod, accessor, default=nil) #:nodoc:
20
+ Devise.send :mattr_accessor, accessor
21
+ Devise.send :"#{accessor}=", default
22
+
23
+ mod.class_eval <<-METHOD, __FILE__, __LINE__
24
+ def #{accessor}
25
+ self.class.#{accessor}
26
+ end
27
+ METHOD
28
+
29
+ mod.const_get(:ClassMethods).class_eval <<-METHOD, __FILE__, __LINE__
30
+ def #{accessor}
31
+ if defined?(@#{accessor})
32
+ @#{accessor}
33
+ elsif superclass.respond_to?(:#{accessor})
34
+ superclass.#{accessor}
35
+ else
36
+ Devise.#{accessor}
37
+ end
38
+ end
39
+
40
+ def #{accessor}=(value)
41
+ @#{accessor} = value
42
+ end
43
+ METHOD
44
+ end
45
+
46
+ # Shortcut method for including all devise modules inside your model.
47
+ # You can give some extra options while declaring devise in your model:
24
48
  #
25
- # * remember_for: the time the user will be remembered without asking for
26
- # credentials again.
49
+ # * except: convenient option that allows you to add all devise modules,
50
+ # removing only the modules you setup here:
27
51
  #
28
- # devise :all, :remember_for => 2.weeks
52
+ # devise :all, :except => :rememberable
29
53
  #
30
- # You can refer to Authenticable, Confirmable and Rememberable for more
31
- # information about writing your own method to setup each model apart.
54
+ # You can also give the following configuration values in a hash: :pepper,
55
+ # :stretches, :confirm_within and :remember_for. Please check your Devise
56
+ # initialiazer for a complete description on those values.
32
57
  #
33
58
  # Examples:
34
59
  #
@@ -59,13 +84,6 @@ module Devise
59
84
  def devise(*modules)
60
85
  options = modules.extract_options!
61
86
 
62
- # TODO Remove me in a next release
63
- if modules.include?(:authenticable)
64
- modules.delete(:authenticable)
65
- modules.unshift(:authenticatable)
66
- ActiveSupport::Deprecation.warn "devise :authenticate is deprecated, use authenticatable instead"
67
- end
68
-
69
87
  modules = Devise::ALL if modules.include?(:all)
70
88
  modules -= Array(options.delete(:except))
71
89
  modules = [:authenticatable] | modules
@@ -90,8 +90,8 @@ module Devise
90
90
  end
91
91
  end
92
92
 
93
- Devise.model_config(self, :pepper)
94
- Devise.model_config(self, :stretches, 10)
93
+ Devise::Models.config(self, :pepper)
94
+ Devise::Models.config(self, :stretches, 10)
95
95
  end
96
96
  end
97
97
  end
@@ -56,7 +56,7 @@ module Devise
56
56
 
57
57
  # Send confirmation instructions by email
58
58
  def send_confirmation_instructions
59
- ::Notifier.deliver_confirmation_instructions(self)
59
+ ::DeviseMailer.deliver_confirmation_instructions(self)
60
60
  end
61
61
 
62
62
  # Remove confirmation date and send confirmation instructions, to ensure
@@ -101,7 +101,7 @@ module Devise
101
101
  #
102
102
  def confirmation_period_valid?
103
103
  confirmation_sent_at? &&
104
- (Date.today - confirmation_sent_at.to_date).days < confirm_within
104
+ (Time.now.utc - confirmation_sent_at.utc) < confirm_within
105
105
  end
106
106
 
107
107
  # Checks whether the record is confirmed or not, yielding to the block
@@ -150,7 +150,7 @@ module Devise
150
150
  end
151
151
  end
152
152
 
153
- Devise.model_config(self, :confirm_within, 0.days)
153
+ Devise::Models.config(self, :confirm_within, 0.days)
154
154
  end
155
155
  end
156
156
  end
@@ -35,7 +35,7 @@ module Devise
35
35
  # Resets reset password token and send reset password instructions by email
36
36
  def send_reset_password_instructions
37
37
  generate_reset_password_token!
38
- ::Notifier.deliver_reset_password_instructions(self)
38
+ ::DeviseMailer.deliver_reset_password_instructions(self)
39
39
  end
40
40
 
41
41
  protected
@@ -45,7 +45,7 @@ module Devise
45
45
  # Generate a new remember token and save the record without validations.
46
46
  def remember_me!
47
47
  self.remember_token = friendly_token
48
- self.remember_created_at = Time.now
48
+ self.remember_created_at = Time.now.utc
49
49
  save(false)
50
50
  end
51
51
 
@@ -66,7 +66,7 @@ module Devise
66
66
 
67
67
  # Remember token should be expired if expiration time not overpass now.
68
68
  def remember_expired?
69
- remember_expires_at <= Time.now
69
+ remember_expires_at <= Time.now.utc
70
70
  end
71
71
 
72
72
  # Remember token expires at created time + remember_for configuration
@@ -89,7 +89,7 @@ module Devise
89
89
  end
90
90
  end
91
91
 
92
- Devise.model_config(self, :remember_for, 2.weeks)
92
+ Devise::Models.config(self, :remember_for, 2.weeks)
93
93
  end
94
94
  end
95
95
  end
@@ -0,0 +1,17 @@
1
+ require 'devise/rails/routes'
2
+ require 'devise/rails/warden_compat'
3
+
4
+ Rails.configuration.after_initialize do
5
+ if defined?(ActiveRecord)
6
+ ActiveRecord::Base.extend Devise::Models
7
+ ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Migrations
8
+ end
9
+
10
+ # Adds Warden Manager to Rails middleware stack, configuring default devise
11
+ # strategy and also the failure app.
12
+ Rails.configuration.middleware.use Warden::Manager do |manager|
13
+ Devise.configure_warden_manager(manager)
14
+ end
15
+
16
+ I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'locales', 'en.yml'))
17
+ end
@@ -0,0 +1,26 @@
1
+ # Taken from RailsWarden, thanks to Hassox. http://github.com/hassox/rails_warden
2
+ module Warden::Mixins::Common
3
+ # Gets the rails request object by default if it's available
4
+ def request
5
+ return @request if @request
6
+ if env['action_controller.rescue.request']
7
+ @request = env['action_controller.rescue.request']
8
+ else
9
+ Rack::Request.new(env)
10
+ end
11
+ end
12
+
13
+ def raw_session
14
+ request.session
15
+ end
16
+
17
+ def reset_session!
18
+ raw_session.inspect # why do I have to inspect it to get it to clear?
19
+ raw_session.clear
20
+ end
21
+
22
+ # Proxy to request cookies
23
+ def cookies
24
+ request.cookies
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -5,33 +5,6 @@ rescue
5
5
  require 'warden'
6
6
  end
7
7
 
8
- # Taken from RailsWarden, thanks to Hassox. http://github.com/hassox/rails_warden
9
- module Warden::Mixins::Common
10
- # Gets the rails request object by default if it's available
11
- def request
12
- return @request if @request
13
- if env['action_controller.rescue.request']
14
- @request = env['action_controller.rescue.request']
15
- else
16
- Rack::Request.new(env)
17
- end
18
- end
19
-
20
- def raw_session
21
- request.session
22
- end
23
-
24
- def reset_session!
25
- raw_session.inspect # why do I have to inspect it to get it to clear?
26
- raw_session.clear
27
- end
28
-
29
- # Proxy to request cookies
30
- def cookies
31
- request.cookies
32
- end
33
- end
34
-
35
8
  # Session Serialization in. This block determines how the user will be stored
36
9
  # in the session. If you're using a complex object like an ActiveRecord model,
37
10
  # it is not a good idea to store the complete object. An ID is sufficient.
@@ -43,19 +16,5 @@ Warden::Manager.serialize_from_session do |klass, id|
43
16
  klass.find(id)
44
17
  end
45
18
 
46
- # Be a good citizen and always set the controller action, even if Devise is
47
- # never calling the failure app through warden.
48
- Warden::Manager.before_failure do |env, opts|
49
- env['warden'].request.params['action'] = 'new'
50
- end
51
-
52
19
  # Setup devise strategies for Warden
53
20
  require 'devise/strategies/base'
54
-
55
- # Adds Warden Manager to Rails middleware stack, configuring default devise
56
- # strategy and also the controller who will manage not authenticated users.
57
- Rails.configuration.middleware.use Warden::Manager do |manager|
58
- manager.default_strategies :rememberable, :authenticatable
59
- manager.failure_app = Devise::Failure
60
- manager.silence_missing_strategies!
61
- end
@@ -0,0 +1,72 @@
1
+ require 'test/test_helper'
2
+
3
+ module Devise
4
+ def self.clean_warden_config!
5
+ @warden_config = nil
6
+ end
7
+ end
8
+
9
+ class DeviseTest < ActiveSupport::TestCase
10
+ class MockManager
11
+ attr_accessor :failure_app
12
+ attr_reader :default_strategies, :silence_missing_strategies
13
+
14
+ def silence_missing_strategies!
15
+ @silence_missing_strategies = true
16
+ end
17
+
18
+ def default_strategies(*args)
19
+ if args.empty?
20
+ @default_strategies
21
+ else
22
+ @default_strategies = args
23
+ end
24
+ end
25
+ end
26
+
27
+ test 'DeviseMailer.sender can be configured through Devise' do
28
+ swap DeviseMailer, :sender => "foo@bar" do
29
+ assert_equal "foo@bar", DeviseMailer.sender
30
+ Devise.mail_sender = "bar@foo"
31
+ assert_equal "bar@foo", DeviseMailer.sender
32
+ end
33
+ end
34
+
35
+ test 'model options can be configured through Devise' do
36
+ swap Devise, :confirm_within => 113, :pepper => "foo" do
37
+ assert_equal 113, Devise.confirm_within
38
+ assert_equal "foo", Devise.pepper
39
+ end
40
+ end
41
+
42
+ test 'setup block yields self' do
43
+ Devise.setup do |config|
44
+ assert_equal Devise, config
45
+ end
46
+ end
47
+
48
+ test 'warden manager configuration' do
49
+ manager = MockManager.new
50
+ Devise.configure_warden_manager(manager)
51
+
52
+ assert_equal Devise::Failure, manager.failure_app
53
+ assert_equal [:rememberable, :authenticatable], manager.default_strategies
54
+ assert manager.silence_missing_strategies
55
+ end
56
+
57
+ test 'warden manager user configuration through a block' do
58
+ begin
59
+ @executed = false
60
+ Devise.warden do |manager|
61
+ @executed = true
62
+ assert_kind_of MockManager, manager
63
+ end
64
+
65
+ manager = MockManager.new
66
+ Devise.configure_warden_manager(manager)
67
+ assert @executed
68
+ ensure
69
+ Devise.clean_warden_config!
70
+ end
71
+ end
72
+ end
@@ -4,7 +4,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
4
4
 
5
5
  def setup
6
6
  setup_mailer
7
- Notifier.sender = 'test@example.com'
7
+ DeviseMailer.sender = 'test@example.com'
8
8
  end
9
9
 
10
10
  def user
@@ -36,13 +36,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
36
36
  end
37
37
 
38
38
  test 'setup subject from I18n' do
39
- store_translations :en, :devise => { :notifier => { :confirmation_instructions => 'Account Confirmation' } } do
39
+ store_translations :en, :devise => { :mailer => { :confirmation_instructions => 'Account Confirmation' } } do
40
40
  assert_equal 'Account Confirmation', mail.subject
41
41
  end
42
42
  end
43
43
 
44
44
  test 'subject namespaced by model' do
45
- store_translations :en, :devise => { :notifier => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do
45
+ store_translations :en, :devise => { :mailer => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do
46
46
  assert_equal 'User Account Confirmation', mail.subject
47
47
  end
48
48
  end
@@ -4,7 +4,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
4
4
 
5
5
  def setup
6
6
  setup_mailer
7
- Notifier.sender = 'test@example.com'
7
+ DeviseMailer.sender = 'test@example.com'
8
8
  end
9
9
 
10
10
  def user
@@ -39,13 +39,13 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
39
39
  end
40
40
 
41
41
  test 'setup subject from I18n' do
42
- store_translations :en, :devise => { :notifier => { :reset_password_instructions => 'Reset instructions' } } do
42
+ store_translations :en, :devise => { :mailer => { :reset_password_instructions => 'Reset instructions' } } do
43
43
  assert_equal 'Reset instructions', mail.subject
44
44
  end
45
45
  end
46
46
 
47
47
  test 'subject namespaced by model' do
48
- store_translations :en, :devise => { :notifier => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do
48
+ store_translations :en, :devise => { :mailer => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do
49
49
  assert_equal 'User Reset Instructions', mail.subject
50
50
  end
51
51
  end
@@ -1,6 +1,6 @@
1
1
  require 'test/test_helper'
2
2
 
3
- class MapTest < ActiveSupport::TestCase
3
+ class MappingTest < ActiveSupport::TestCase
4
4
 
5
5
  test 'store options' do
6
6
  mapping = Devise.mappings[:user]
@@ -20,14 +20,6 @@ class RememberableTest < ActiveSupport::TestCase
20
20
  assert_not user.changed?
21
21
  end
22
22
 
23
- test 'remember_me should calculate expires_at based on remember_for setup' do
24
- user = create_user
25
- assert_not user.remember_created_at?
26
- user.remember_me!
27
- assert user.remember_created_at?
28
- assert_equal Date.today, user.remember_created_at.to_date
29
- end
30
-
31
23
  test 'forget_me should clear remember token and save the record without validating' do
32
24
  user = create_user
33
25
  user.remember_me!
@@ -38,7 +30,7 @@ class RememberableTest < ActiveSupport::TestCase
38
30
  assert_not user.changed?
39
31
  end
40
32
 
41
- test 'forget_me should clear remember_expires_at' do
33
+ test 'forget_me should clear remember_created_at' do
42
34
  user = create_user
43
35
  user.remember_me!
44
36
  assert user.remember_created_at?
@@ -33,4 +33,19 @@ class ActiveSupport::TestCase
33
33
  def create_user(attributes={})
34
34
  User.create!(valid_attributes(attributes))
35
35
  end
36
+
37
+ # Execute the block setting the given values and restoring old values after
38
+ # the block is executed.
39
+ def swap(object, new_values)
40
+ old_values = {}
41
+ new_values.each do |key, value|
42
+ old_values[key] = object.send key
43
+ object.send :"#{key}=", value
44
+ end
45
+ yield
46
+ ensure
47
+ old_values.each do |key, value|
48
+ object.send :"#{key}=", value
49
+ end
50
+ end
36
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Jos\xC3\xA9 Valim"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-10-30 00:00:00 -02:00
13
+ date: 2009-11-03 00:00:00 -02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -40,10 +40,10 @@ files:
40
40
  - app/controllers/confirmations_controller.rb
41
41
  - app/controllers/passwords_controller.rb
42
42
  - app/controllers/sessions_controller.rb
43
- - app/models/notifier.rb
43
+ - app/models/devise_mailer.rb
44
44
  - app/views/confirmations/new.html.erb
45
- - app/views/notifier/confirmation_instructions.html.erb
46
- - app/views/notifier/reset_password_instructions.html.erb
45
+ - app/views/devise_mailer/confirmation_instructions.html.erb
46
+ - app/views/devise_mailer/reset_password_instructions.html.erb
47
47
  - app/views/passwords/edit.html.erb
48
48
  - app/views/passwords/new.html.erb
49
49
  - app/views/sessions/new.html.erb
@@ -53,11 +53,13 @@ files:
53
53
  - generators/devise/templates/README
54
54
  - generators/devise/templates/migration.rb
55
55
  - generators/devise/templates/model.rb
56
+ - generators/devise_install/USAGE
57
+ - generators/devise_install/devise_install_generator.rb
58
+ - generators/devise_install/templates/devise.rb
56
59
  - generators/devise_views/USAGE
57
60
  - generators/devise_views/devise_views_generator.rb
58
61
  - init.rb
59
62
  - lib/devise.rb
60
- - lib/devise/active_record.rb
61
63
  - lib/devise/controllers/filters.rb
62
64
  - lib/devise/controllers/helpers.rb
63
65
  - lib/devise/controllers/url_helpers.rb
@@ -67,12 +69,15 @@ files:
67
69
  - lib/devise/locales/en.yml
68
70
  - lib/devise/mapping.rb
69
71
  - lib/devise/migrations.rb
72
+ - lib/devise/models.rb
70
73
  - lib/devise/models/authenticatable.rb
71
74
  - lib/devise/models/confirmable.rb
72
75
  - lib/devise/models/recoverable.rb
73
76
  - lib/devise/models/rememberable.rb
74
77
  - lib/devise/models/validatable.rb
75
- - lib/devise/routes.rb
78
+ - lib/devise/rails.rb
79
+ - lib/devise/rails/routes.rb
80
+ - lib/devise/rails/warden_compat.rb
76
81
  - lib/devise/strategies/authenticatable.rb
77
82
  - lib/devise/strategies/base.rb
78
83
  - lib/devise/strategies/rememberable.rb
@@ -127,6 +132,7 @@ test_files:
127
132
  - test/controllers/url_helpers_test.rb
128
133
  - test/controllers/helpers_test.rb
129
134
  - test/controllers/filters_test.rb
135
+ - test/models_test.rb
130
136
  - test/integration/authenticatable_test.rb
131
137
  - test/integration/rememberable_test.rb
132
138
  - test/integration/recoverable_test.rb
@@ -142,7 +148,7 @@ test_files:
142
148
  - test/support/model_tests_helper.rb
143
149
  - test/support/assertions_helper.rb
144
150
  - test/support/integration_tests_helper.rb
151
+ - test/devise_test.rb
145
152
  - test/routes_test.rb
146
153
  - test/test_helper.rb
147
154
  - test/mapping_test.rb
148
- - test/active_record_test.rb