devise 0.7.2 → 0.7.3

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.3
2
+
3
+ * bug fix
4
+ * Give scope to the proper model validation
5
+
6
+ * enhancements
7
+ * Mail views are scoped as well
8
+ * Added update_with_password for authenticatable
9
+ * Allow render_with_scope to accept :controller option
10
+
1
11
  == 0.7.2
2
12
 
3
13
  * deprecation
data/TODO CHANGED
@@ -1,2 +1,3 @@
1
- * Create update_with_password
2
1
  * Make test run with different ORMs
2
+ * Add registerable support
3
+ * Add http authentication support
@@ -26,7 +26,7 @@ class DeviseMailer < ::ActionMailer::Base
26
26
 
27
27
  # Configure default email options
28
28
  def setup_mail(record, key)
29
- mapping = Devise.mappings.values.find { |m| m.to == record.class }
29
+ mapping = Devise::Mapping.find_by_class(record.class)
30
30
  raise "Invalid devise resource #{record}" unless mapping
31
31
 
32
32
  subject translate(mapping, key)
@@ -34,7 +34,19 @@ class DeviseMailer < ::ActionMailer::Base
34
34
  recipients record.email
35
35
  sent_on Time.now
36
36
  content_type 'text/html'
37
- body mapping.name => record, :resource => record
37
+ body render_with_scope(key, mapping, mapping.name => record, :resource => record)
38
+ end
39
+
40
+ def render_with_scope(key, mapping, assigns)
41
+ if Devise.scoped_views
42
+ begin
43
+ render :file => "devise_mailer/#{mapping.as}/#{key}", :body => assigns
44
+ rescue ActionView::MissingTemplate
45
+ render :file => "devise_mailer/#{key}", :body => assigns
46
+ end
47
+ else
48
+ render :file => "devise_mailer/#{key}", :body => assigns
49
+ end
38
50
  end
39
51
 
40
52
  # Setup subject namespaced by model. It means you're able to setup your
@@ -1,18 +1,20 @@
1
1
  <h2>Sign in</h2>
2
2
 
3
- <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
4
- <p><%= f.label :email %></p>
5
- <p><%= f.text_field :email %></p>
3
+ <%- if devise_mapping.authenticatable? %>
4
+ <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
5
+ <p><%= f.label :email %></p>
6
+ <p><%= f.text_field :email %></p>
6
7
 
7
- <p><%= f.label :password %></p>
8
- <p><%= f.password_field :password %></p>
8
+ <p><%= f.label :password %></p>
9
+ <p><%= f.password_field :password %></p>
9
10
 
10
- <% if devise_mapping.rememberable? -%>
11
- <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
12
- <% end -%>
11
+ <% if devise_mapping.rememberable? -%>
12
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
13
+ <% end -%>
13
14
 
14
- <p><%= f.submit "Sign in" %></p>
15
- <% end -%>
15
+ <p><%= f.submit "Sign in" %></p>
16
+ <% end -%>
17
+ <% end%>
16
18
 
17
19
  <%- if devise_mapping.recoverable? %>
18
20
  <%= link_to "Forgot password?", new_password_path(resource_name) %><br />
@@ -41,8 +41,9 @@ Devise.setup do |config|
41
41
  # Configure the e-mail address which will be shown in DeviseMailer.
42
42
  # config.mailer_sender = "foo.bar@yourapp.com"
43
43
 
44
- # Configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
45
- # config.orm = :active_record
44
+ # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
45
+ # require 'devise/orm/mongo_mapper'
46
+ # config.orm = :mongo_mapper
46
47
 
47
48
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
48
49
  # "sessions/users/new". It's turned off by default because it's slower if you
@@ -97,15 +97,17 @@ module Devise
97
97
  end
98
98
 
99
99
  # Render a view for the specified scope. Turned off by default.
100
- def render_with_scope(action)
100
+ # Accepts just :controller as option.
101
+ def render_with_scope(action, options={})
102
+  controller_name = options.delete(:controller) || self.controller_name
101
103
  if Devise.scoped_views
102
104
  begin
103
105
  render :template => "#{controller_name}/#{devise_mapping.as}/#{action}"
104
106
  rescue ActionView::MissingTemplate
105
- render action
107
+ render action, :controller => controller_name
106
108
  end
107
109
  else
108
- render action
110
+ render action, :controller => controller_name
109
111
  end
110
112
  end
111
113
 
@@ -47,7 +47,7 @@ module Devise
47
47
  extend ClassMethods
48
48
  extend SessionSerializer
49
49
 
50
- attr_reader :password
50
+ attr_reader :password, :old_password
51
51
  attr_accessor :password_confirmation
52
52
  end
53
53
  end
@@ -62,11 +62,22 @@ module Devise
62
62
  end
63
63
  end
64
64
 
65
- # Verifies whether an incoming_password (ie from login) is the user password.
65
+ # Verifies whether an incoming_password (ie from sign in) is the user password.
66
66
  def valid_password?(incoming_password)
67
67
  password_digest(incoming_password) == encrypted_password
68
68
  end
69
69
 
70
+ # Update record attributes when :old_password matches, otherwise returns
71
+ # error on :old_password.
72
+ def update_with_password(params={})
73
+ if valid_password?(params[:old_password])
74
+ update_attributes(params)
75
+ else
76
+ errors.add(:old_password, :invalid)
77
+ false
78
+ end
79
+ end
80
+
70
81
  protected
71
82
 
72
83
  # Digests the password using the configured encryptor.
@@ -19,9 +19,8 @@ module Devise
19
19
 
20
20
  base.class_eval do
21
21
  validates_presence_of :email
22
- validates_uniqueness_of :email, :allow_blank => true
23
- validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true,
24
- :scope => authentication_keys[1..-1]
22
+ validates_uniqueness_of :email, :scope => authentication_keys[1..-1], :allow_blank => true
23
+ validates_format_of :email, :with => EMAIL_REGEX, :allow_blank => true
25
24
 
26
25
  with_options :if => :password_required? do |v|
27
26
  v.validates_presence_of :password
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "0.7.2".freeze
2
+ VERSION = "0.7.3".freeze
3
3
  end
@@ -56,4 +56,10 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
56
56
  confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
57
57
  assert_match confirmation_url_regexp, mail.body
58
58
  end
59
+
60
+ test 'renders a scoped if scoped_views is set to true' do
61
+ swap Devise, :scoped_views => true do
62
+ assert_equal user.email, mail.body
63
+ end
64
+ end
59
65
  end
@@ -152,4 +152,30 @@ class AuthenticatableTest < ActiveSupport::TestCase
152
152
  User.serialize_from_session([Admin, user.id])
153
153
  end
154
154
  end
155
+
156
+ test 'should respond to old password' do
157
+ assert new_user.respond_to?(:old_password)
158
+ end
159
+
160
+ test 'should update password with valid old password' do
161
+ user = create_user
162
+ assert user.update_with_password(:old_password => '123456',
163
+ :password => 'pass321', :password_confirmation => 'pass321')
164
+ assert user.reload.valid_password?('pass321')
165
+ end
166
+
167
+ test 'should add an error to old password when it is invalid' do
168
+ user = create_user
169
+ assert_not user.update_with_password(:old_password => 'other',
170
+ :password => 'pass321', :password_confirmation => 'pass321')
171
+ assert_equal 'is invalid', user.errors[:old_password]
172
+ assert user.reload.valid_password?('123456')
173
+ end
174
+
175
+ test 'should not update password with invalid confirmation' do
176
+ user = create_user
177
+ assert_not user.update_with_password(:old_password => '123456',
178
+ :password => 'pass321', :password_confirmation => 'other')
179
+ assert user.reload.valid_password?('123456')
180
+ end
155
181
  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.2
4
+ version: 0.7.3
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-15 00:00:00 +01:00
13
+ date: 2009-12-16 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency