devise 0.5.5 → 0.5.6

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,9 @@
1
+ == 0.5.6
2
+
3
+ * enhancements
4
+ * [#42] Do not send nil to build (DataMapper compatibility)
5
+ * [#44] Allow to have scoped views
6
+
1
7
  == 0.5.5
2
8
 
3
9
  * enhancements
@@ -224,6 +224,13 @@ sign_out method. Such methods have the same signature as in controllers:
224
224
  sign_out :user # sign_out(scope)
225
225
  sign_out @user # sign_out(resource)
226
226
 
227
+ You can include the Devise Test Helpers in all of your tests by adding the
228
+ following to the bottom of your test/test_helper.rb or spec/spec_helper.rb file:
229
+
230
+ class ActionController::TestCase
231
+ include Devise::TestHelpers
232
+ end
233
+
227
234
  == Migrating from other solutions
228
235
 
229
236
  Devise implements encryption strategies for Clearance, Authlogic and Restful-Authentication. To make use of it set the desired encryptor in the encryptor initializer config option. You might also need to rename your encrypted password and salt columns to match Devises's one (encrypted_password and password_salt).
@@ -4,6 +4,7 @@ class ConfirmationsController < ApplicationController
4
4
  # GET /resource/confirmation/new
5
5
  def new
6
6
  build_resource
7
+ render_with_scope :new
7
8
  end
8
9
 
9
10
  # POST /resource/confirmation
@@ -14,7 +15,7 @@ class ConfirmationsController < ApplicationController
14
15
  set_flash_message :success, :send_instructions
15
16
  redirect_to new_session_path(resource_name)
16
17
  else
17
- render :new
18
+ render_with_scope :new
18
19
  end
19
20
  end
20
21
 
@@ -26,7 +27,7 @@ class ConfirmationsController < ApplicationController
26
27
  set_flash_message :success, :confirmed
27
28
  sign_in_and_redirect(resource_name, resource)
28
29
  else
29
- render :new
30
+ render_with_scope :new
30
31
  end
31
32
  end
32
33
  end
@@ -6,6 +6,7 @@ class PasswordsController < ApplicationController
6
6
  # GET /resource/password/new
7
7
  def new
8
8
  build_resource
9
+ render_with_scope :new
9
10
  end
10
11
 
11
12
  # POST /resource/password
@@ -16,7 +17,7 @@ class PasswordsController < ApplicationController
16
17
  set_flash_message :success, :send_instructions
17
18
  redirect_to new_session_path(resource_name)
18
19
  else
19
- render :new
20
+ render_with_scope :new
20
21
  end
21
22
  end
22
23
 
@@ -24,6 +25,7 @@ class PasswordsController < ApplicationController
24
25
  def edit
25
26
  self.resource = resource_class.new
26
27
  resource.reset_password_token = params[:reset_password_token]
28
+ render_with_scope :edit
27
29
  end
28
30
 
29
31
  # PUT /resource/password
@@ -34,7 +36,7 @@ class PasswordsController < ApplicationController
34
36
  set_flash_message :success, :updated
35
37
  sign_in_and_redirect(resource_name, resource)
36
38
  else
37
- render :edit
39
+ render_with_scope :edit
38
40
  end
39
41
  end
40
42
  end
@@ -9,6 +9,7 @@ class SessionsController < ApplicationController
9
9
  set_now_flash_message :failure, message if params.try(:[], message) == "true"
10
10
  end
11
11
  build_resource
12
+ render_with_scope :new
12
13
  end
13
14
 
14
15
  # POST /resource/sign_in
@@ -19,7 +20,7 @@ class SessionsController < ApplicationController
19
20
  else
20
21
  set_now_flash_message :failure, warden.message || :invalid
21
22
  build_resource
22
- render :new
23
+ render_with_scope :new
23
24
  end
24
25
  end
25
26
 
@@ -40,6 +40,11 @@ Devise.setup do |config|
40
40
  # Configure the ORM. Supports :active_record and :mongo_mapper
41
41
  # config.orm = :active_record
42
42
 
43
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
44
+ # "sessions/users/new". It's turned off by default because it's slower if you
45
+ # are using only default views.
46
+ # config.scoped_views = true
47
+
43
48
  # If you want to use other strategies, that are not (yet) supported by Devise,
44
49
  # you can configure them inside the config.warden block. The example below
45
50
  # allows you to setup OAuth, using http://github.com/roman/warden_oauth
@@ -73,6 +73,11 @@ module Devise
73
73
  mattr_accessor :apply_schema
74
74
  @@apply_schema = true
75
75
 
76
+ # Scoped views. Since it relies on fallbacks to render default views, it's
77
+ # turned off by default.
78
+ mattr_accessor :scoped_views
79
+ @@scoped_views = false
80
+
76
81
  class << self
77
82
  # Default way to setup Devise. Run script/generate devise_install to create
78
83
  # a fresh initializer with all configuration values.
@@ -59,7 +59,7 @@ module Devise
59
59
  def build_resource
60
60
  self.resource ||= begin
61
61
  attributes = params[resource_name].try(:except, :password, :password_confirmation)
62
- resource_class.new(attributes)
62
+ resource_class.new(attributes || {})
63
63
  end
64
64
  end
65
65
 
@@ -96,6 +96,19 @@ module Devise
96
96
  set_flash_message(key, kind, true)
97
97
  end
98
98
 
99
+ # Render a view for the specified scope. Turned off by default.
100
+ def render_with_scope(action)
101
+ if Devise.scoped_views
102
+ begin
103
+ render :template => "sessions/#{devise_mapping.as}/#{action}"
104
+ rescue ActionView::MissingTemplate
105
+ render action
106
+ end
107
+ else
108
+ render action
109
+ end
110
+ end
111
+
99
112
  end
100
113
  end
101
114
  end
@@ -44,6 +44,7 @@ module ActionController::Routing
44
44
  # POST /users/confirmation(.:format) {:controller=>"confirmations", :action=>"create"}
45
45
  #
46
46
  # You can configure your routes with some options:
47
+ #
47
48
  # * :class_name => setup a different class to be looked up by devise, if it cannot be correctly find by the route name.
48
49
  #
49
50
  # map.devise_for :users, :class_name => 'Account'
@@ -1,3 +1,3 @@
1
1
  module Devise
2
- VERSION = "0.5.5".freeze
2
+ VERSION = "0.5.6".freeze
3
3
  end
@@ -191,7 +191,7 @@ class AuthenticationTest < ActionController::IntegrationTest
191
191
  visit 'users/index'
192
192
  assert_equal "Cart", @controller.user_session[:cart]
193
193
  end
194
-
194
+
195
195
  test 'destroyed account is logged out' do
196
196
  sign_in_as_user
197
197
  visit 'users/index'
@@ -199,4 +199,29 @@ class AuthenticationTest < ActionController::IntegrationTest
199
199
  visit 'users/index'
200
200
  assert_redirected_to '/users/sign_in?unauthenticated=true'
201
201
  end
202
+
203
+ test 'renders the scoped view if turned on and view is available' do
204
+ swap Devise, :scoped_views => true do
205
+ assert_raise Webrat::NotFoundError do
206
+ sign_in_as_user
207
+ end
208
+ assert_match /Special user view/, response.body
209
+ end
210
+ end
211
+
212
+ test 'does not render the scoped view if turned off' do
213
+ swap Devise, :scoped_views => false do
214
+ assert_nothing_raised do
215
+ sign_in_as_user
216
+ end
217
+ end
218
+ end
219
+
220
+ test 'does not render the scoped view if not available' do
221
+ swap Devise, :scoped_views => true do
222
+ assert_nothing_raised do
223
+ sign_in_as_admin
224
+ end
225
+ end
226
+ end
202
227
  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.5.5
4
+ version: 0.5.6
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-11-20 00:00:00 -02:00
13
+ date: 2009-11-21 00:00:00 -02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency