devise 0.7.1 → 0.7.2

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,13 @@
1
+ == 0.7.2
2
+
3
+ * deprecation
4
+ * Renamed reset_confirmation! to resend_confirmation!
5
+ * Copying locale is part of the installation process
6
+
7
+ * bug fix
8
+ * Fixed render_with_scope to work with all controllers
9
+ * Allow sign in with two different users in Devise::TestHelpers
10
+
1
11
  == 0.7.1
2
12
 
3
13
  * enhancements
@@ -42,6 +42,10 @@ Configure warden and devise gems inside your app:
42
42
  config.gem 'warden'
43
43
  config.gem 'devise'
44
44
 
45
+ Run the generator:
46
+
47
+ ruby script/generate devise_install
48
+
45
49
  And you're ready to go.
46
50
 
47
51
  == Basic Usage
@@ -4,9 +4,6 @@ class DeviseGenerator < Rails::Generator::NamedBase
4
4
 
5
5
  def manifest
6
6
  record do |m|
7
- # Check for class naming collisions.
8
- m.class_collisions(class_name)
9
-
10
7
  # Model
11
8
  m.directory(File.join('app', 'models', class_path))
12
9
  m.template 'model.rb', File.join('app', 'models', "#{file_path}.rb")
@@ -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.authenticatable :encryptor => :sha1
4
+ t.authenticatable :encryptor => :sha1, :null => false
5
5
  t.confirmable
6
6
  t.recoverable
7
7
  t.rememberable
@@ -2,7 +2,11 @@ class DeviseInstallGenerator < Rails::Generator::Base
2
2
 
3
3
  def manifest
4
4
  record do |m|
5
- m.template "devise.rb", "config/initializers/devise.rb"
5
+ m.directory "config/initializers"
6
+ m.template "devise.rb", "config/initializers/devise.rb"
7
+
8
+ m.directory "config/locales"
9
+ m.file "../../../lib/devise/locales/en.yml", "config/locales/devise.en.yml"
6
10
  end
7
11
  end
8
12
 
@@ -15,9 +15,6 @@ class DeviseViewsGenerator < Rails::Generator::Base
15
15
  m.directory File.dirname(file)
16
16
  m.file file, file
17
17
  end
18
-
19
- m.directory "config/locales"
20
- m.file "lib/devise/locales/en.yml", "config/locales/devise.en.yml"
21
18
  end
22
19
  end
23
20
 
@@ -1,7 +1,28 @@
1
1
  module Devise
2
- autoload :Schema, 'devise/schema'
3
- autoload :Mapping, 'devise/mapping'
4
2
  autoload :FailureApp, 'devise/failure_app'
3
+ autoload :Mapping, 'devise/mapping'
4
+ autoload :Schema, 'devise/schema'
5
+ autoload :TestHelpers, 'devise/test_helpers'
6
+
7
+ module Controllers
8
+ autoload :Filters, 'devise/controllers/filters'
9
+ autoload :Helpers, 'devise/controllers/helpers'
10
+ autoload :UrlHelpers, 'devise/controllers/url_helpers'
11
+ end
12
+
13
+ module Encryptors
14
+ autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
15
+ autoload :AuthlogicSha1, 'devise/encryptors/authlogic_sha1'
16
+ autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
17
+ autoload :Sha512, 'devise/encryptors/sha512'
18
+ autoload :Sha1, 'devise/encryptors/sha1'
19
+ end
20
+
21
+ module Orm
22
+ autoload :ActiveRecord, 'devise/orm/active_record'
23
+ autoload :DataMapper, 'devise/orm/data_mapper'
24
+ autoload :MongoMapper, 'devise/orm/mongo_mapper'
25
+ end
5
26
 
6
27
  ALL = [:authenticatable, :confirmable, :recoverable, :rememberable,
7
28
  :timeoutable, :trackable, :validatable]
@@ -147,8 +168,4 @@ end
147
168
 
148
169
  # Set the default_scope to nil, so it's overwritten when the first route is declared.
149
170
  Warden::Manager.default_scope = nil
150
-
151
- require 'devise/controllers'
152
- require 'devise/encryptors'
153
- require 'devise/orm'
154
171
  require 'devise/rails'
@@ -100,7 +100,7 @@ module Devise
100
100
  def render_with_scope(action)
101
101
  if Devise.scoped_views
102
102
  begin
103
- render :template => "sessions/#{devise_mapping.as}/#{action}"
103
+ render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
104
104
  rescue ActionView::MissingTemplate
105
105
  render action
106
106
  end
@@ -27,15 +27,15 @@ module Devise
27
27
  # User.find(1).confirm! # returns true unless it's already confirmed
28
28
  # User.find(1).confirmed? # true/false
29
29
  # User.find(1).send_confirmation_instructions # manually send instructions
30
- # User.find(1).reset_confirmation! # reset confirmation status and send instructions
30
+ # User.find(1).resend_confirmation! # generates a new token and resent it
31
31
  module Confirmable
32
32
 
33
33
  def self.included(base)
34
34
  base.class_eval do
35
35
  extend ClassMethods
36
36
 
37
- before_create :generate_confirmation_token
38
- after_create :send_confirmation_instructions
37
+ before_create :generate_confirmation_token, :if => :confirmation_required?
38
+ after_create :send_confirmation_instructions, :if => :confirmation_required?
39
39
  end
40
40
  end
41
41
 
@@ -62,7 +62,7 @@ module Devise
62
62
  # Remove confirmation date and send confirmation instructions, to ensure
63
63
  # after sending these instructions the user won't be able to sign in without
64
64
  # confirming it's account
65
- def reset_confirmation!
65
+ def resend_confirmation!
66
66
  unless_confirmed do
67
67
  generate_confirmation_token
68
68
  save(false)
@@ -78,8 +78,20 @@ module Devise
78
78
  confirmed? || confirmation_period_valid?
79
79
  end
80
80
 
81
+ # If you don't want confirmation to be sent on create, neither a code
82
+ # to be generated, call skip_confirmation!
83
+ def skip_confirmation!
84
+ self.confirmed_at = Time.now
85
+ @skip_confirmation = true
86
+ end
87
+
81
88
  protected
82
89
 
90
+ # Callback to overwrite if confirmation is required or not.
91
+ def confirmation_required?
92
+ !@skip_confirmation
93
+ end
94
+
83
95
  # Checks if the confirmation for the user is within the limit time.
84
96
  # We do this by calculating if the difference between today and the
85
97
  # confirmation sent date does not exceed the confirm in time configured.
@@ -129,7 +141,7 @@ module Devise
129
141
  # Options must contain the user email
130
142
  def send_confirmation_instructions(attributes={})
131
143
  confirmable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
132
- confirmable.reset_confirmation! unless confirmable.new_record?
144
+ confirmable.resend_confirmation! unless confirmable.new_record?
133
145
  confirmable
134
146
  end
135
147
 
@@ -20,16 +20,11 @@ module Devise
20
20
  end
21
21
  end
22
22
 
23
- # Update password
24
- def reset_password(new_password, new_password_confirmation)
25
- self.password = new_password
26
- self.password_confirmation = new_password_confirmation
27
- end
28
-
29
23
  # Update password saving the record and clearing token. Returns true if
30
24
  # the passwords are valid and the record was saved, false otherwise.
31
25
  def reset_password!(new_password, new_password_confirmation)
32
- reset_password(new_password, new_password_confirmation)
26
+ self.password = new_password
27
+ self.password_confirmation = new_password_confirmation
33
28
  clear_reset_password_token if valid?
34
29
  save
35
30
  end
@@ -8,17 +8,11 @@ module Devise
8
8
  # == Options
9
9
  # * :null - When true, allow columns to be null.
10
10
  # * :encryptor - The encryptor going to be used, necessary for setting the proper encrypter password length.
11
- # * :skip_email - If you want to use another authentication key, you can skip e-mail creation.
12
- # If you are using an ORM where the devise declaration is in the same class as the schema,
13
- # as in Datamapper or Mongomapper, the email is skipped automatically if not included in
14
- # authentication_keys.
15
11
  def authenticatable(options={})
16
- null = options[:null] || false
12
+ null = options[:null] || false
17
13
  encryptor = options[:encryptor] || (respond_to?(:encryptor) ? self.encryptor : :sha1)
18
- have_email = respond_to?(:authentication_keys) ? self.authentication_keys.include?(:email) : true
19
- skip_email = options[:skip_email] || !have_email
20
14
 
21
- apply_schema :email, String, :null => null, :limit => 100 unless skip_email
15
+ apply_schema :email, String, :null => null, :limit => 100
22
16
  apply_schema :encrypted_password, String, :null => null, :limit => Devise::ENCRYPTORS_LENGTH[encryptor]
23
17
  apply_schema :password_salt, String, :null => null, :limit => 20
24
18
  end
@@ -78,6 +78,7 @@ module Devise
78
78
  #
79
79
  def sign_out(resource_or_scope)
80
80
  scope = Devise::Mapping.find_scope!(resource_or_scope)
81
+ @controller.instance_variable_set(:"@current_#{scope}", nil)
81
82
  warden.logout(scope)
82
83
  end
83
84
 
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "0.7.1".freeze
2
+ VERSION = "0.7.2".freeze
3
3
  end
@@ -15,7 +15,7 @@ class ConfirmableTest < ActiveSupport::TestCase
15
15
  user = create_user
16
16
  3.times do
17
17
  token = user.confirmation_token
18
- user.reset_confirmation!
18
+ user.resend_confirmation!
19
19
  assert_not_equal token, user.confirmation_token
20
20
  end
21
21
  end
@@ -108,6 +108,17 @@ class ConfirmableTest < ActiveSupport::TestCase
108
108
  end
109
109
  end
110
110
 
111
+ test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
112
+ user = new_user
113
+ user.skip_confirmation!
114
+
115
+ assert_email_not_sent do
116
+ user.save!
117
+ assert_nil user.confirmation_token
118
+ assert_not_nil user.confirmed_at
119
+ end
120
+ end
121
+
111
122
  test 'should find a user to send confirmation instructions' do
112
123
  user = create_user
113
124
  confirmation_user = User.send_confirmation_instructions(:email => user.email)
@@ -125,20 +136,13 @@ class ConfirmableTest < ActiveSupport::TestCase
125
136
  assert_equal 'not found', confirmation_user.errors[:email]
126
137
  end
127
138
 
128
- test 'should reset confirmation token before send the confirmation instructions email' do
139
+ test 'should generate a confirmation token before send the confirmation instructions email' do
129
140
  user = create_user
130
141
  token = user.confirmation_token
131
142
  confirmation_user = User.send_confirmation_instructions(:email => user.email)
132
143
  assert_not_equal token, user.reload.confirmation_token
133
144
  end
134
145
 
135
- test 'should reset confirmation status when sending the confirmation instructions' do
136
- user = create_user
137
- assert_not user.confirmed?
138
- confirmation_user = User.send_confirmation_instructions(:email => user.email)
139
- assert_not user.reload.confirmed?
140
- end
141
-
142
146
  test 'should send email instructions for the user confirm it\'s email' do
143
147
  user = create_user
144
148
  assert_email_sent do
@@ -168,7 +172,7 @@ class ConfirmableTest < ActiveSupport::TestCase
168
172
  test 'should not be able to send instructions if the user is already confirmed' do
169
173
  user = create_user
170
174
  user.confirm!
171
- assert_not user.reset_confirmation!
175
+ assert_not user.resend_confirmation!
172
176
  assert user.confirmed?
173
177
  assert_equal 'already confirmed', user.errors[:email]
174
178
  end
@@ -32,7 +32,7 @@ class RecoverableTest < ActiveSupport::TestCase
32
32
 
33
33
  test 'should reset password and password confirmation from params' do
34
34
  user = create_user
35
- user.reset_password('123456789', '987654321')
35
+ user.reset_password!('123456789', '987654321')
36
36
  assert_equal '123456789', user.password
37
37
  assert_equal '987654321', user.password_confirmation
38
38
  end
@@ -9,4 +9,8 @@ class UsersController < ApplicationController
9
9
  user_session['last_request_at'] = 31.minutes.ago.utc
10
10
  render :text => 'User will be expired on next request'
11
11
  end
12
+
13
+ def show
14
+ render :text => current_user.id.to_s
15
+ end
12
16
  end
@@ -5,14 +5,14 @@ class TestHelpersTest < ActionController::TestCase
5
5
  include Devise::TestHelpers
6
6
 
7
7
  test "redirects if attempting to access a page unauthenticated" do
8
- get :index
8
+ get :show
9
9
  assert_redirected_to "/users/sign_in?unauthenticated=true"
10
10
  end
11
11
 
12
12
  test "redirects if attempting to access a page with a unconfirmed account" do
13
13
  swap Devise, :confirm_within => 0 do
14
14
  sign_in create_user
15
- get :index
15
+ get :show
16
16
  assert_redirected_to "/users/sign_in?unconfirmed=true"
17
17
  end
18
18
  end
@@ -22,7 +22,7 @@ class TestHelpersTest < ActionController::TestCase
22
22
  user.confirm!
23
23
 
24
24
  sign_in user
25
- get :index
25
+ get :show
26
26
  assert_response :success
27
27
  end
28
28
 
@@ -31,14 +31,31 @@ class TestHelpersTest < ActionController::TestCase
31
31
  user.confirm!
32
32
 
33
33
  sign_in user
34
- get :index
34
+ get :show
35
35
 
36
36
  sign_out user
37
- get :index
37
+ get :show
38
38
  assert_redirected_to "/users/sign_in?unauthenticated=true"
39
39
  end
40
40
 
41
- def create_user
42
- User.create!(:email => "jose.valim@plataformatec.com", :password => "123456")
41
+ test "allows to sign in with different users" do
42
+ first_user = create_user(1)
43
+ first_user.confirm!
44
+
45
+ sign_in first_user
46
+ get :show
47
+ assert_equal first_user.id.to_s, @response.body
48
+ sign_out first_user
49
+
50
+ second_user = create_user(2)
51
+ second_user.confirm!
52
+
53
+ sign_in second_user
54
+ get :show
55
+ assert_equal second_user.id.to_s, @response.body
56
+ end
57
+
58
+ def create_user(i=nil)
59
+ User.create!(:email => "jose.valim#{i}@plataformatec.com", :password => "123456")
43
60
  end
44
61
  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.7.1
4
+ version: 0.7.2
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-12-09 00:00:00 -02:00
13
+ date: 2009-12-15 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -60,11 +60,9 @@ files:
60
60
  - generators/devise_views/devise_views_generator.rb
61
61
  - init.rb
62
62
  - lib/devise.rb
63
- - lib/devise/controllers.rb
64
63
  - lib/devise/controllers/filters.rb
65
64
  - lib/devise/controllers/helpers.rb
66
65
  - lib/devise/controllers/url_helpers.rb
67
- - lib/devise/encryptors.rb
68
66
  - lib/devise/encryptors/authlogic_sha512.rb
69
67
  - lib/devise/encryptors/clearance_sha1.rb
70
68
  - lib/devise/encryptors/restful_authentication_sha1.rb
@@ -84,7 +82,6 @@ files:
84
82
  - lib/devise/models/timeoutable.rb
85
83
  - lib/devise/models/trackable.rb
86
84
  - lib/devise/models/validatable.rb
87
- - lib/devise/orm.rb
88
85
  - lib/devise/orm/active_record.rb
89
86
  - lib/devise/orm/data_mapper.rb
90
87
  - lib/devise/orm/mongo_mapper.rb
@@ -1,7 +0,0 @@
1
- module Devise
2
- module Controllers
3
- autoload :Filters, 'devise/controllers/filters'
4
- autoload :Helpers, 'devise/controllers/helpers'
5
- autoload :UrlHelpers, 'devise/controllers/url_helpers'
6
- end
7
- end
@@ -1,9 +0,0 @@
1
- module Devise
2
- module Encryptors
3
- autoload :AuthlogicSha512, 'devise/encryptors/authlogic_sha512'
4
- autoload :AuthlogicSha1, 'devise/encryptors/authlogic_sha1'
5
- autoload :RestfulAuthenticationSha1, 'devise/encryptors/restful_authentication_sha1'
6
- autoload :Sha512, 'devise/encryptors/sha512'
7
- autoload :Sha1, 'devise/encryptors/sha1'
8
- end
9
- end
@@ -1,7 +0,0 @@
1
- module Devise
2
- module Orm
3
- autoload :ActiveRecord, 'devise/orm/active_record'
4
- autoload :DataMapper, 'devise/orm/data_mapper'
5
- autoload :MongoMapper, 'devise/orm/mongo_mapper'
6
- end
7
- end