devise 1.3.0 → 1.3.1
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/.travis.yml +0 -1
- data/CHANGELOG.rdoc +9 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +2 -2
- data/app/controllers/devise/registrations_controller.rb +2 -2
- data/app/controllers/devise/sessions_controller.rb +12 -14
- data/lib/devise.rb +1 -0
- data/lib/devise/controllers/internal_helpers.rb +1 -22
- data/lib/devise/controllers/shared_helpers.rb +26 -0
- data/lib/devise/failure_app.rb +9 -6
- data/lib/devise/models/authenticatable.rb +13 -0
- data/lib/devise/models/database_authenticatable.rb +1 -1
- data/lib/devise/models/recoverable.rb +1 -0
- data/lib/devise/test_helpers.rb +33 -43
- data/lib/devise/version.rb +1 -1
- data/lib/generators/templates/devise.rb +1 -1
- data/test/controllers/sessions_controller_test.rb +7 -8
- data/test/failure_app_test.rb +12 -0
- data/test/integration/authenticatable_test.rb +18 -3
- data/test/integration/registerable_test.rb +18 -4
- data/test/models/confirmable_test.rb +2 -2
- data/test/models/database_authenticatable_test.rb +2 -2
- data/test/models/lockable_test.rb +2 -2
- data/test/models/recoverable_test.rb +9 -1
- data/test/rails_app/lib/shared_user.rb +2 -0
- data/test/support/helpers.rb +2 -2
- metadata +5 -4
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 1.3.1
|
2
|
+
|
3
|
+
* enhancements
|
4
|
+
* Improve failure_app responses (by github.com/indirect)
|
5
|
+
* sessions/new and registrations/new also respond to xml and json now
|
6
|
+
|
7
|
+
* bug fix
|
8
|
+
* Fix a regression that occurred if reset_password_sent_at is not present (by github.com/stevehodgkiss)
|
9
|
+
|
1
10
|
== 1.3.0
|
2
11
|
|
3
12
|
* enhancements
|
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -86,7 +86,7 @@ The generator will install an initializer which describes ALL Devise's configura
|
|
86
86
|
|
87
87
|
rails generate devise MODEL
|
88
88
|
|
89
|
-
Replace MODEL by the class name
|
89
|
+
Replace MODEL by the class name used for the applications users, it's frequently 'User' but could also be 'Admin'. This will create a model (if one does not exist) and configure it with default Devise modules. Next, you'll usually run db:migrate as the generator will have created a migration file (if your ORM supports them). This generator also configures your config/routes.rb file, continue reading this file to understand exactly what the generator produces and how to use it.
|
90
90
|
|
91
91
|
Support for Rails 2.3.x can be found by installing Devise 1.0.x from the v1.0 branch.
|
92
92
|
|
@@ -259,7 +259,7 @@ Feel free to choose the one you prefer!
|
|
259
259
|
|
260
260
|
=== I18n
|
261
261
|
|
262
|
-
Devise uses flash messages with I18n with the flash keys :
|
262
|
+
Devise uses flash messages with I18n with the flash keys :notice and :alert. To customize your app, you can set up your locale file:
|
263
263
|
|
264
264
|
en:
|
265
265
|
devise:
|
@@ -5,8 +5,8 @@ class Devise::RegistrationsController < ApplicationController
|
|
5
5
|
|
6
6
|
# GET /resource/sign_up
|
7
7
|
def new
|
8
|
-
build_resource({})
|
9
|
-
render_with_scope :new
|
8
|
+
resource = build_resource({})
|
9
|
+
respond_with_navigational(resource){ render_with_scope :new }
|
10
10
|
end
|
11
11
|
|
12
12
|
# POST /resource
|
@@ -4,24 +4,14 @@ class Devise::SessionsController < ApplicationController
|
|
4
4
|
|
5
5
|
# GET /resource/sign_in
|
6
6
|
def new
|
7
|
-
|
8
|
-
|
7
|
+
resource = build_resource
|
8
|
+
clean_up_passwords(resource)
|
9
|
+
respond_with_navigational(resource, stub_options(resource)){ render_with_scope :new }
|
9
10
|
end
|
10
11
|
|
11
12
|
# POST /resource/sign_in
|
12
13
|
def create
|
13
14
|
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
|
14
|
-
|
15
|
-
# In the running app, the previous line would actually cause this method to
|
16
|
-
# exit by throwing `:warden` if the authentication failed. Unfortunately,
|
17
|
-
# this doesn't happen in the Rails test environment if you have included the
|
18
|
-
# Devise::TestHelpers (see `Devise::TestHelpers::TestWarden#authenticate!`),
|
19
|
-
# which makes it difficult to unit test extensions to this controller. Since
|
20
|
-
# the resource is nil if authentication fails, just short-circuit the method
|
21
|
-
# in that case. This should not affect the running app.
|
22
|
-
|
23
|
-
return if resource.nil?
|
24
|
-
|
25
15
|
set_flash_message(:notice, :signed_in) if is_navigational_format?
|
26
16
|
sign_in(resource_name, resource)
|
27
17
|
respond_with resource, :location => redirect_location(resource_name, resource)
|
@@ -44,4 +34,12 @@ class Devise::SessionsController < ApplicationController
|
|
44
34
|
end
|
45
35
|
end
|
46
36
|
end
|
47
|
-
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def stub_options(resource)
|
41
|
+
array = resource_class.authentication_keys.dup
|
42
|
+
array << :password if resource.respond_to?(:password)
|
43
|
+
{ :methods => array, :only => [:password] }
|
44
|
+
end
|
45
|
+
end
|
data/lib/devise.rb
CHANGED
@@ -16,6 +16,7 @@ module Devise
|
|
16
16
|
autoload :InternalHelpers, 'devise/controllers/internal_helpers'
|
17
17
|
autoload :Rememberable, 'devise/controllers/rememberable'
|
18
18
|
autoload :ScopedViews, 'devise/controllers/scoped_views'
|
19
|
+
autoload :SharedHelpers, 'devise/controllers/shared_helpers'
|
19
20
|
autoload :UrlHelpers, 'devise/controllers/url_helpers'
|
20
21
|
end
|
21
22
|
|
@@ -6,19 +6,7 @@ module Devise
|
|
6
6
|
module InternalHelpers #:nodoc:
|
7
7
|
extend ActiveSupport::Concern
|
8
8
|
include Devise::Controllers::ScopedViews
|
9
|
-
|
10
|
-
MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
|
11
|
-
|
12
|
-
# Helper used by FailureApp and Devise controllers to retrieve proper formats.
|
13
|
-
def self.request_format(request)
|
14
|
-
if request.format.respond_to?(:ref)
|
15
|
-
request.format.ref
|
16
|
-
elsif MIME_REFERENCES
|
17
|
-
request.format
|
18
|
-
elsif request.format # Rails < 3.0.4
|
19
|
-
request.format.to_sym
|
20
|
-
end
|
21
|
-
end
|
9
|
+
include Devise::Controllers::SharedHelpers
|
22
10
|
|
23
11
|
included do
|
24
12
|
helper DeviseHelper
|
@@ -65,10 +53,6 @@ module Devise
|
|
65
53
|
|
66
54
|
protected
|
67
55
|
|
68
|
-
def request_format
|
69
|
-
@request_format ||= Devise::Controllers::InternalHelpers.request_format(request)
|
70
|
-
end
|
71
|
-
|
72
56
|
# Checks whether it's a devise mapped resource or not.
|
73
57
|
def is_devise_resource? #:nodoc:
|
74
58
|
unknown_action! <<-MESSAGE unless devise_mapping
|
@@ -81,11 +65,6 @@ Maybe you forgot to wrap your route inside the scope block? For example:
|
|
81
65
|
MESSAGE
|
82
66
|
end
|
83
67
|
|
84
|
-
# Check whether it's navigational format, such as :html or :iphone, or not.
|
85
|
-
def is_navigational_format?
|
86
|
-
Devise.navigational_formats.include?(request_format)
|
87
|
-
end
|
88
|
-
|
89
68
|
# Returns real navigational formats which are supported by Rails
|
90
69
|
def navigational_formats
|
91
70
|
@navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] }
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Devise
|
2
|
+
module Controllers
|
3
|
+
# Helpers used in both FailureApp and Devise controllers.
|
4
|
+
module SharedHelpers
|
5
|
+
MIME_REFERENCES = Mime::HTML.respond_to?(:ref)
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
# Helper used by FailureApp and Devise controllers to retrieve proper formats.
|
10
|
+
def request_format
|
11
|
+
@request_format ||= if request.format.respond_to?(:ref)
|
12
|
+
request.format.ref
|
13
|
+
elsif MIME_REFERENCES
|
14
|
+
request.format
|
15
|
+
elsif request.format # Rails < 3.0.4
|
16
|
+
request.format.to_sym
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Check whether it's navigational format, such as :html or :iphone, or not.
|
21
|
+
def is_navigational_format?
|
22
|
+
Devise.navigational_formats.include?(request_format)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/devise/failure_app.rb
CHANGED
@@ -10,6 +10,7 @@ module Devise
|
|
10
10
|
include ActionController::UrlFor
|
11
11
|
include ActionController::Redirecting
|
12
12
|
include Rails.application.routes.url_helpers
|
13
|
+
include Devise::Controllers::SharedHelpers
|
13
14
|
|
14
15
|
delegate :flash, :to => :request
|
15
16
|
|
@@ -83,7 +84,7 @@ module Devise
|
|
83
84
|
if request.xhr?
|
84
85
|
Devise.http_authenticatable_on_xhr
|
85
86
|
else
|
86
|
-
!(request_format &&
|
87
|
+
!(request_format && is_navigational_format?)
|
87
88
|
end
|
88
89
|
end
|
89
90
|
|
@@ -96,7 +97,13 @@ module Devise
|
|
96
97
|
def http_auth_body
|
97
98
|
return i18n_message unless request_format
|
98
99
|
method = "to_#{request_format}"
|
99
|
-
|
100
|
+
if method == "to_xml"
|
101
|
+
{ :error => i18n_message }.to_xml(:root => "errors")
|
102
|
+
elsif {}.respond_to?(method)
|
103
|
+
{ :error => i18n_message }.send(method)
|
104
|
+
else
|
105
|
+
i18n_message
|
106
|
+
end
|
100
107
|
end
|
101
108
|
|
102
109
|
def recall_app(app)
|
@@ -129,9 +136,5 @@ module Devise
|
|
129
136
|
def store_location!
|
130
137
|
session["#{scope}_return_to"] = attempted_path if request.get? && !http_auth?
|
131
138
|
end
|
132
|
-
|
133
|
-
def request_format
|
134
|
-
@request_format ||= Devise::Controllers::InternalHelpers.request_format(request)
|
135
|
-
end
|
136
139
|
end
|
137
140
|
end
|
@@ -76,6 +76,19 @@ module Devise
|
|
76
76
|
def authenticatable_salt
|
77
77
|
end
|
78
78
|
|
79
|
+
%w(to_xml to_json).each do |method|
|
80
|
+
class_eval <<-RUBY, __FILE__, __LINE__
|
81
|
+
def #{method}(options={})
|
82
|
+
if self.class.respond_to?(:accessible_attributes)
|
83
|
+
options = { :only => self.class.accessible_attributes.to_a }.merge(options || {})
|
84
|
+
super(options)
|
85
|
+
else
|
86
|
+
super
|
87
|
+
end
|
88
|
+
end
|
89
|
+
RUBY
|
90
|
+
end
|
91
|
+
|
79
92
|
module ClassMethods
|
80
93
|
Devise::Models.config(self, :authentication_keys, :request_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
|
81
94
|
|
@@ -41,7 +41,7 @@ module Devise
|
|
41
41
|
|
42
42
|
# Set password and password confirmation to nil
|
43
43
|
def clean_up_passwords
|
44
|
-
self.password = self.password_confirmation =
|
44
|
+
self.password = self.password_confirmation = ""
|
45
45
|
end
|
46
46
|
|
47
47
|
# Update record attributes when :current_password matches, otherwise returns
|
@@ -73,6 +73,7 @@ module Devise
|
|
73
73
|
def generate_reset_password_token
|
74
74
|
self.reset_password_token = self.class.reset_password_token
|
75
75
|
self.reset_password_sent_at = Time.now.utc if respond_to?(:reset_password_sent_at=)
|
76
|
+
self.reset_password_token
|
76
77
|
end
|
77
78
|
|
78
79
|
# Resets the reset password token with and save the record without
|
data/lib/devise/test_helpers.rb
CHANGED
@@ -13,48 +13,11 @@ module Devise
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def initialize(controller)
|
23
|
-
@controller = controller
|
24
|
-
manager = Warden::Manager.new(nil) do |config|
|
25
|
-
config.merge! Devise.warden_config
|
26
|
-
end
|
27
|
-
super(controller.request.env, manager)
|
28
|
-
end
|
29
|
-
|
30
|
-
def authenticate!(*args)
|
31
|
-
catch_with_redirect { super }
|
32
|
-
end
|
33
|
-
|
34
|
-
def user(*args)
|
35
|
-
catch_with_redirect { super }
|
36
|
-
end
|
37
|
-
|
38
|
-
def catch_with_redirect(&block)
|
39
|
-
result = catch(:warden, &block)
|
40
|
-
|
41
|
-
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
|
42
|
-
result[:action] ||= :unauthenticated
|
43
|
-
|
44
|
-
env = @controller.request.env
|
45
|
-
env["PATH_INFO"] = "/#{result[:action]}"
|
46
|
-
env["warden.options"] = result
|
47
|
-
Warden::Manager._run_callbacks(:before_failure, env, result)
|
48
|
-
|
49
|
-
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
|
50
|
-
@controller.send :render, :status => status, :text => body,
|
51
|
-
:content_type => headers["Content-Type"], :location => headers["Location"]
|
52
|
-
|
53
|
-
nil
|
54
|
-
else
|
55
|
-
result
|
56
|
-
end
|
57
|
-
end
|
16
|
+
# Override process to consider warden.
|
17
|
+
def process(*)
|
18
|
+
result = nil
|
19
|
+
_catch_warden { result = super }
|
20
|
+
result
|
58
21
|
end
|
59
22
|
|
60
23
|
# We need to setup the environment variables and the response in the controller.
|
@@ -64,7 +27,12 @@ module Devise
|
|
64
27
|
|
65
28
|
# Quick access to Warden::Proxy.
|
66
29
|
def warden #:nodoc:
|
67
|
-
@warden ||=
|
30
|
+
@warden ||= begin
|
31
|
+
manager = Warden::Manager.new(nil) do |config|
|
32
|
+
config.merge! Devise.warden_config
|
33
|
+
end
|
34
|
+
@request.env['warden'] = Warden::Proxy.new(@request.env, manager)
|
35
|
+
end
|
68
36
|
end
|
69
37
|
|
70
38
|
# sign_in a given resource by storing its keys in the session.
|
@@ -96,5 +64,27 @@ module Devise
|
|
96
64
|
warden.session_serializer.delete(scope, user)
|
97
65
|
end
|
98
66
|
|
67
|
+
protected
|
68
|
+
|
69
|
+
def _catch_warden(&block)
|
70
|
+
result = catch(:warden, &block)
|
71
|
+
|
72
|
+
if result.is_a?(Hash) && !warden.custom_failure? && !@controller.send(:performed?)
|
73
|
+
result[:action] ||= :unauthenticated
|
74
|
+
|
75
|
+
env = @controller.request.env
|
76
|
+
env["PATH_INFO"] = "/#{result[:action]}"
|
77
|
+
env["warden.options"] = result
|
78
|
+
Warden::Manager._run_callbacks(:before_failure, env, result)
|
79
|
+
|
80
|
+
status, headers, body = Devise.warden_config[:failure_app].call(env).to_a
|
81
|
+
@controller.send :render, :status => status, :text => body,
|
82
|
+
:content_type => headers["Content-Type"], :location => headers["Location"]
|
83
|
+
|
84
|
+
nil
|
85
|
+
else
|
86
|
+
result
|
87
|
+
end
|
88
|
+
end
|
99
89
|
end
|
100
90
|
end
|
data/lib/devise/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Devise.setup do |config|
|
4
4
|
# ==> Mailer Configuration
|
5
5
|
# Configure the e-mail address which will be shown in DeviseMailer.
|
6
|
-
config.mailer_sender = "please-change-me
|
6
|
+
config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
|
7
7
|
|
8
8
|
# Configure the class responsible to send e-mails.
|
9
9
|
# config.mailer = "Devise::Mailer"
|
@@ -4,14 +4,13 @@ class SessionsControllerTest < ActionController::TestCase
|
|
4
4
|
tests Devise::SessionsController
|
5
5
|
include Devise::TestHelpers
|
6
6
|
|
7
|
-
test "#create doesn't raise exception after Warden authentication fails "
|
8
|
-
+ "when TestHelpers included" do
|
7
|
+
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
9
8
|
request.env["devise.mapping"] = Devise.mappings[:user]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
9
|
+
post :create, :user => {
|
10
|
+
:email => "nosuchuser@example.com",
|
11
|
+
:password => "wevdude"
|
12
|
+
}
|
13
|
+
assert_equal 200, @response.status
|
14
|
+
assert_template "devise/sessions/new"
|
16
15
|
end
|
17
16
|
end
|
data/test/failure_app_test.rb
CHANGED
@@ -84,6 +84,18 @@ class FailureTest < ActiveSupport::TestCase
|
|
84
84
|
assert_equal 401, @response.first
|
85
85
|
end
|
86
86
|
|
87
|
+
test 'return appropriate body for xml' do
|
88
|
+
call_failure('formats' => :xml)
|
89
|
+
result = %(<?xml version="1.0" encoding="UTF-8"?>\n<errors>\n <error>You need to sign in or sign up before continuing.</error>\n</errors>\n)
|
90
|
+
assert_equal result, @response.last.body
|
91
|
+
end
|
92
|
+
|
93
|
+
test 'return appropriate body for json' do
|
94
|
+
call_failure('formats' => :json)
|
95
|
+
result = %({"error":"You need to sign in or sign up before continuing."})
|
96
|
+
assert_equal result, @response.last.body
|
97
|
+
end
|
98
|
+
|
87
99
|
test 'return 401 status for unknown formats' do
|
88
100
|
call_failure 'formats' => []
|
89
101
|
assert_equal 401, @response.first
|
@@ -336,9 +336,24 @@ class AuthenticationOthersTest < ActionController::IntegrationTest
|
|
336
336
|
end
|
337
337
|
end
|
338
338
|
|
339
|
-
test '
|
340
|
-
|
341
|
-
|
339
|
+
test 'sign in stub in xml format' do
|
340
|
+
get new_user_session_path(:format => 'xml')
|
341
|
+
assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>\n <email></email>\n <password></password>\n</user>\n", response.body
|
342
|
+
end
|
343
|
+
|
344
|
+
test 'sign in stub in json format' do
|
345
|
+
get new_user_session_path(:format => 'json')
|
346
|
+
assert_match '{"user":{', response.body
|
347
|
+
assert_match '"email":""', response.body
|
348
|
+
assert_match '"password":""', response.body
|
349
|
+
end
|
350
|
+
|
351
|
+
test 'sign in stub in json with non attribute key' do
|
352
|
+
swap Devise, :authentication_keys => [:other_key] do
|
353
|
+
get new_user_session_path(:format => 'json')
|
354
|
+
assert_match '{"user":{', response.body
|
355
|
+
assert_match '"other_key":null', response.body
|
356
|
+
assert_match '"password":""', response.body
|
342
357
|
end
|
343
358
|
end
|
344
359
|
|
@@ -118,14 +118,14 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
118
118
|
sign_in_as_user
|
119
119
|
get edit_user_registration_path
|
120
120
|
|
121
|
-
fill_in 'email', :with => 'user.new@
|
121
|
+
fill_in 'email', :with => 'user.new@example.com'
|
122
122
|
fill_in 'current password', :with => '123456'
|
123
123
|
click_button 'Update'
|
124
124
|
|
125
125
|
assert_current_url '/'
|
126
126
|
assert_contain 'You updated your account successfully.'
|
127
127
|
|
128
|
-
assert_equal "user.new@
|
128
|
+
assert_equal "user.new@example.com", User.first.email
|
129
129
|
end
|
130
130
|
|
131
131
|
test 'a signed in user should still be able to use the website after changing his password' do
|
@@ -146,13 +146,13 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
146
146
|
sign_in_as_user
|
147
147
|
get edit_user_registration_path
|
148
148
|
|
149
|
-
fill_in 'email', :with => 'user.new@
|
149
|
+
fill_in 'email', :with => 'user.new@example.com'
|
150
150
|
fill_in 'current password', :with => 'invalid'
|
151
151
|
click_button 'Update'
|
152
152
|
|
153
153
|
assert_template 'registrations/edit'
|
154
154
|
assert_contain 'user@test.com'
|
155
|
-
assert_have_selector 'form input[value="user.new@
|
155
|
+
assert_have_selector 'form input[value="user.new@example.com"]'
|
156
156
|
|
157
157
|
assert_equal "user@test.com", User.first.email
|
158
158
|
end
|
@@ -207,6 +207,20 @@ class RegistrationTest < ActionController::IntegrationTest
|
|
207
207
|
assert_redirected_to new_user_registration_path
|
208
208
|
end
|
209
209
|
|
210
|
+
test 'a user with XML sign up stub' do
|
211
|
+
get new_user_registration_path(:format => 'xml')
|
212
|
+
assert_response :success
|
213
|
+
assert_match %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<user>), response.body
|
214
|
+
assert_no_match(/<confirmation_token>/, response.body) if DEVISE_ORM == :active_record
|
215
|
+
end
|
216
|
+
|
217
|
+
test 'a user with JSON sign up stub' do
|
218
|
+
get new_user_registration_path(:format => 'json')
|
219
|
+
assert_response :success
|
220
|
+
assert_match %({"user":), response.body
|
221
|
+
assert_no_match(/"confirmation_token"/, response.body) if DEVISE_ORM == :active_record
|
222
|
+
end
|
223
|
+
|
210
224
|
test 'an admin sign up with valid information in XML format should return valid response' do
|
211
225
|
post admin_registration_path(:format => 'xml'), :admin => { :email => 'new_user@test.com', :password => 'new_user123', :password_confirmation => 'new_user123' }
|
212
226
|
assert_response :success
|
@@ -111,12 +111,12 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|
111
111
|
end
|
112
112
|
|
113
113
|
test 'should return a new user if no email was found' do
|
114
|
-
confirmation_user = User.send_confirmation_instructions(:email => "invalid@
|
114
|
+
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
115
115
|
assert_not confirmation_user.persisted?
|
116
116
|
end
|
117
117
|
|
118
118
|
test 'should add error to new user email if no email was found' do
|
119
|
-
confirmation_user = User.send_confirmation_instructions(:email => "invalid@
|
119
|
+
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
120
120
|
assert confirmation_user.errors[:email]
|
121
121
|
assert_equal "not found", confirmation_user.errors[:email].join
|
122
122
|
end
|
@@ -89,8 +89,8 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|
89
89
|
|
90
90
|
test 'should ignore password and its confirmation if they are blank' do
|
91
91
|
user = create_user
|
92
|
-
assert user.update_with_password(:current_password => '123456', :email => "new@
|
93
|
-
assert_equal "new@
|
92
|
+
assert user.update_with_password(:current_password => '123456', :email => "new@example.com")
|
93
|
+
assert_equal "new@example.com", user.email
|
94
94
|
end
|
95
95
|
|
96
96
|
test 'should not update password with invalid confirmation' do
|
@@ -163,12 +163,12 @@ class LockableTest < ActiveSupport::TestCase
|
|
163
163
|
end
|
164
164
|
|
165
165
|
test 'should return a new user if no email was found' do
|
166
|
-
unlock_user = User.send_unlock_instructions(:email => "invalid@
|
166
|
+
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
|
167
167
|
assert_not unlock_user.persisted?
|
168
168
|
end
|
169
169
|
|
170
170
|
test 'should add error to new user email if no email was found' do
|
171
|
-
unlock_user = User.send_unlock_instructions(:email => "invalid@
|
171
|
+
unlock_user = User.send_unlock_instructions(:email => "invalid@example.com")
|
172
172
|
assert_equal 'not found', unlock_user.errors[:email].join
|
173
173
|
end
|
174
174
|
|
@@ -72,7 +72,7 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
72
72
|
end
|
73
73
|
|
74
74
|
test 'should return a new record with errors if user was not found by e-mail' do
|
75
|
-
reset_password_user = User.send_reset_password_instructions(:email => "invalid@
|
75
|
+
reset_password_user = User.send_reset_password_instructions(:email => "invalid@example.com")
|
76
76
|
assert_not reset_password_user.persisted?
|
77
77
|
assert_equal "not found", reset_password_user.errors[:email].join
|
78
78
|
end
|
@@ -196,4 +196,12 @@ class RecoverableTest < ActiveSupport::TestCase
|
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
+
test 'should save the model when the reset_password_sent_at doesnt exist' do
|
200
|
+
user = create_user
|
201
|
+
user.stubs(:respond_to?).with(:reset_password_sent_at=).returns(false)
|
202
|
+
user.stubs(:respond_to?).with(:headers_for).returns(false)
|
203
|
+
user.send_reset_password_instructions
|
204
|
+
user.reload
|
205
|
+
assert_not_nil user.reset_password_token
|
206
|
+
end
|
199
207
|
end
|
data/test/support/helpers.rb
CHANGED
@@ -19,7 +19,7 @@ class ActiveSupport::TestCase
|
|
19
19
|
def generate_unique_email
|
20
20
|
@@email_count ||= 0
|
21
21
|
@@email_count += 1
|
22
|
-
"test#{@@email_count}@
|
22
|
+
"test#{@@email_count}@example.com"
|
23
23
|
end
|
24
24
|
|
25
25
|
def valid_attributes(attributes={})
|
@@ -57,4 +57,4 @@ class ActiveSupport::TestCase
|
|
57
57
|
object.send :"#{key}=", value
|
58
58
|
end
|
59
59
|
end
|
60
|
-
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 1
|
10
|
+
version: 1.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Jos\xC3\xA9 Valim"
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-04-
|
19
|
+
date: 2011-04-19 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- lib/devise/controllers/internal_helpers.rb
|
111
111
|
- lib/devise/controllers/rememberable.rb
|
112
112
|
- lib/devise/controllers/scoped_views.rb
|
113
|
+
- lib/devise/controllers/shared_helpers.rb
|
113
114
|
- lib/devise/controllers/url_helpers.rb
|
114
115
|
- lib/devise/encryptors/authlogic_sha512.rb
|
115
116
|
- lib/devise/encryptors/base.rb
|