devise 0.7.3 → 0.7.4

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.

Files changed (52) hide show
  1. data/CHANGELOG.rdoc +4 -0
  2. data/README.rdoc +1 -0
  3. data/Rakefile +11 -3
  4. data/TODO +6 -3
  5. data/generators/devise_install/templates/devise.rb +7 -3
  6. data/lib/devise.rb +12 -7
  7. data/lib/devise/controllers/helpers.rb +1 -1
  8. data/lib/devise/hooks/{confirmable.rb → activatable.rb} +5 -4
  9. data/lib/devise/locales/en.yml +2 -0
  10. data/lib/devise/models.rb +20 -7
  11. data/lib/devise/models/activatable.rb +16 -0
  12. data/lib/devise/models/authenticatable.rb +14 -22
  13. data/lib/devise/models/confirmable.rb +12 -6
  14. data/lib/devise/models/cookie_serializer.rb +21 -0
  15. data/lib/devise/models/rememberable.rb +2 -20
  16. data/lib/devise/models/session_serializer.rb +19 -0
  17. data/lib/devise/models/validatable.rb +0 -4
  18. data/lib/devise/serializers/base.rb +2 -9
  19. data/lib/devise/serializers/cookie.rb +43 -0
  20. data/lib/devise/serializers/session.rb +22 -0
  21. data/lib/devise/version.rb +1 -1
  22. data/test/integration/confirmable_test.rb +3 -2
  23. data/test/integration/recoverable_test.rb +1 -1
  24. data/test/mapping_test.rb +9 -9
  25. data/test/models/authenticatable_test.rb +1 -1
  26. data/test/models/confirmable_test.rb +7 -5
  27. data/test/models/recoverable_test.rb +3 -3
  28. data/test/models/rememberable_test.rb +11 -5
  29. data/test/models/validatable_test.rb +1 -0
  30. data/test/models_test.rb +10 -10
  31. data/test/orm/active_record.rb +29 -0
  32. data/test/orm/mongo_mapper.rb +21 -0
  33. data/test/rails_app/app/{models → active_record}/account.rb +0 -0
  34. data/test/rails_app/app/{models → active_record}/admin.rb +1 -1
  35. data/test/rails_app/app/{models → active_record}/user.rb +1 -1
  36. data/test/rails_app/app/mongo_mapper/account.rb +9 -0
  37. data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
  38. data/test/rails_app/app/mongo_mapper/user.rb +6 -0
  39. data/test/rails_app/config/environment.rb +3 -3
  40. data/test/rails_app/config/initializers/devise.rb +76 -0
  41. data/test/rails_app/config/routes.rb +2 -5
  42. data/test/routes_test.rb +4 -16
  43. data/test/support/assertions_helper.rb +15 -0
  44. data/test/support/integration_tests_helper.rb +1 -1
  45. data/test/support/model_tests_helper.rb +0 -15
  46. data/test/support/test_silencer.rb +5 -0
  47. data/test/test_helper.rb +7 -30
  48. data/test/test_helpers_test.rb +2 -6
  49. metadata +18 -9
  50. data/lib/devise/serializers/authenticatable.rb +0 -11
  51. data/lib/devise/serializers/rememberable.rb +0 -30
  52. data/test/rails_app/app/models/organizer.rb +0 -3
@@ -0,0 +1,9 @@
1
+ class Admin
2
+ include MongoMapper::Document
3
+
4
+ devise :all, :timeoutable, :except => [:recoverable, :confirmable, :rememberable, :validatable, :trackable]
5
+
6
+ def self.find_for_authentication(conditions)
7
+ last(:conditions => conditions, :order => "email")
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class User
2
+ include MongoMapper::Document
3
+ key :created_at, DateTime
4
+ devise :all, :timeoutable
5
+ # attr_accessible :username, :email, :password, :password_confirmation
6
+ end
@@ -1,7 +1,7 @@
1
1
  # Be sure to restart your server when you modify this file
2
2
 
3
3
  # Specifies gem version of Rails to use when vendor/rails is not present
4
- RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
4
+ RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
5
5
 
6
6
  # Bootstrap the Rails environment, frameworks, and default configuration
7
7
  require File.join(File.dirname(__FILE__), 'boot')
@@ -12,7 +12,7 @@ Rails::Initializer.run do |config|
12
12
  # -- all .rb files in that directory are automatically loaded.
13
13
 
14
14
  # Add additional load paths for your own custom dirs
15
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
15
+ config.load_paths += [ "#{RAILS_ROOT}/app/#{DEVISE_ORM}/" ]
16
16
 
17
17
  # Specify gems that this application depends on and have them installed with rake gems:install
18
18
  # config.gem "bj"
@@ -26,7 +26,7 @@ Rails::Initializer.run do |config|
26
26
 
27
27
  # Skip frameworks you're not going to use. To use Rails without a database,
28
28
  # you must remove the Active Record framework.
29
- # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
29
+ config.frameworks -= [ :active_record ] unless DEVISE_ORM == :active_record
30
30
 
31
31
  # Activate observers that should always be running
32
32
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
@@ -0,0 +1,76 @@
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
+ # Configure Devise modules used by default. You should always set this value
5
+ # because if Devise adds a new strategy, it won't be added to your application
6
+ # by default, unless you configure it here.
7
+ #
8
+ # Remember that Devise includes other modules on its own (like :activatable
9
+ # and :timeoutable) which are not included here and also plugins. So be sure
10
+ # to check the docs for a complete set.
11
+ config.all = [:authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable]
12
+
13
+ # Invoke `rake secret` and use the printed value to setup a pepper to generate
14
+ # the encrypted password. By default no pepper is used.
15
+ # config.pepper = "rake secret output"
16
+
17
+ # Configure how many times you want the password is reencrypted. Default is 10.
18
+ # config.stretches = 10
19
+
20
+ # Define which will be the encryption algorithm. Supported algorithms are :sha1
21
+ # (default) and :sha512. Devise also supports encryptors from others authentication
22
+ # frameworks as :clearance_sha1, :authlogic_sha512 (then you should set stretches
23
+ # above to 20 for default behavior) and :restful_authentication_sha1 (then you
24
+ # should set stretches to 10, and copy REST_AUTH_SITE_KEY to pepper)
25
+ # config.encryptor = :sha1
26
+
27
+ # Configure which keys are used when authenticating an user. By default is
28
+ # just :email. You can configure it to use [:username, :subdomain], so for
29
+ # authenticating an user, both parameters are required. Remember that those
30
+ # parameters are used only when authenticating and not when retrieving from
31
+ # session. If you need permissions, you should implement that in a before filter.
32
+ # config.authentication_keys = [ :email ]
33
+
34
+ # The time you want give to your user to confirm his account. During this time
35
+ # he will be able to access your application without confirming. Default is nil.
36
+ # config.confirm_within = 2.days
37
+
38
+ # The time the user will be remembered without asking for credentials again.
39
+ # config.remember_for = 2.weeks
40
+
41
+ # The time you want to timeout the user session without activity. After this
42
+ # time the user will be asked for credentials again.
43
+ # config.timeout_in = 10.minutes
44
+
45
+ # Configure the e-mail address which will be shown in DeviseMailer.
46
+ # config.mailer_sender = "foo.bar@yourapp.com"
47
+
48
+ # Load and configure the ORM. Supports :active_record, :data_mapper and :mongo_mapper.
49
+ require "devise/orm/#{DEVISE_ORM}"
50
+ config.orm = DEVISE_ORM
51
+
52
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
53
+ # "sessions/users/new". It's turned off by default because it's slower if you
54
+ # are using only default views.
55
+ # config.scoped_views = true
56
+
57
+ # If you want to use other strategies, that are not (yet) supported by Devise,
58
+ # you can configure them inside the config.warden block. The example below
59
+ # allows you to setup OAuth, using http://github.com/roman/warden_oauth
60
+ #
61
+ # config.warden do |manager|
62
+ # manager.oauth(:twitter) do |twitter|
63
+ # twitter.consumer_secret = <YOUR CONSUMER SECRET>
64
+ # twitter.consumer_key = <YOUR CONSUMER KEY>
65
+ # twitter.options :site => 'http://twitter.com'
66
+ # end
67
+ # manager.default_strategies.unshift :twitter_oauth
68
+ # end
69
+
70
+ # Configure default_url_options if you are using dynamic segments in :path_prefix
71
+ # for devise_for.
72
+ #
73
+ # config.default_url_options do
74
+ # { :locale => I18n.locale }
75
+ # end
76
+ end
@@ -1,12 +1,9 @@
1
1
  ActionController::Routing::Routes.draw do |map|
2
2
  map.devise_for :users
3
3
  map.devise_for :admin, :as => 'admin_area'
4
- map.devise_for :account, :path_names => {
4
+ map.devise_for :accounts, :path_names => {
5
5
  :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification'
6
- }
7
- map.devise_for :organizers, :scope => 'manager',
8
- :path_prefix => '/:locale',
9
- :requirements => { :extra => 'value' }
6
+ }, :scope => 'manager', :path_prefix => '/:locale', :requirements => { :extra => 'value' }
10
7
 
11
8
  map.resources :users, :only => [:index], :member => { :expire => :get }
12
9
  map.resources :admins, :only => :index
@@ -53,30 +53,18 @@ class MapRoutingTest < ActionController::TestCase
53
53
  end
54
54
 
55
55
  test 'map account with custom path name for session sign in' do
56
- assert_recognizes({:controller => 'sessions', :action => 'new'}, 'account/login')
56
+ assert_recognizes({:controller => 'sessions', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/login')
57
57
  end
58
58
 
59
59
  test 'map account with custom path name for session sign out' do
60
- assert_recognizes({:controller => 'sessions', :action => 'destroy'}, 'account/logout')
60
+ assert_recognizes({:controller => 'sessions', :action => 'destroy', :locale => 'en', :extra => 'value'}, '/en/accounts/logout')
61
61
  end
62
62
 
63
63
  test 'map account with custom path name for password' do
64
- assert_recognizes({:controller => 'passwords', :action => 'new'}, 'account/secret/new')
64
+ assert_recognizes({:controller => 'passwords', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/secret/new')
65
65
  end
66
66
 
67
67
  test 'map account with custom path name for confirmation' do
68
- assert_recognizes({:controller => 'confirmations', :action => 'new'}, 'account/verification/new')
69
- end
70
-
71
- test 'map organizer with custom singular name' do
72
- assert_recognizes({:controller => 'passwords', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/password/new')
73
- end
74
-
75
- test 'map organizer with path prefix' do
76
- assert_recognizes({:controller => 'sessions', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/sign_in')
77
- end
78
-
79
- test 'map organizer with additional route options' do
80
- assert_recognizes({:controller => 'passwords', :action => 'new', :locale => "en", :extra => 'value'}, '/en/organizers/password/new')
68
+ assert_recognizes({:controller => 'confirmations', :action => 'new', :locale => 'en', :extra => 'value'}, '/en/accounts/verification/new')
81
69
  end
82
70
  end
@@ -19,4 +19,19 @@ class ActiveSupport::TestCase
19
19
  def assert_email_not_sent(&block)
20
20
  assert_no_difference('ActionMailer::Base.deliveries.size') { yield }
21
21
  end
22
+
23
+ # Execute the block setting the given values and restoring old values after
24
+ # the block is executed.
25
+ def swap(object, new_values)
26
+ old_values = {}
27
+ new_values.each do |key, value|
28
+ old_values[key] = object.send key
29
+ object.send :"#{key}=", value
30
+ end
31
+ yield
32
+ ensure
33
+ old_values.each do |key, value|
34
+ object.send :"#{key}=", value
35
+ end
36
+ end
22
37
  end
@@ -7,7 +7,7 @@ class ActionController::IntegrationTest
7
7
  def create_user(options={})
8
8
  @user ||= begin
9
9
  user = User.create!(
10
- :email => 'user@test.com', :password => '123456', :password_confirmation => '123456'
10
+ :email => 'user@test.com', :password => '123456', :password_confirmation => '123456', :created_at => Time.now.utc
11
11
  )
12
12
  user.confirm! unless options[:confirm] == false
13
13
  user
@@ -33,19 +33,4 @@ 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
51
36
  end
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module TestSilencer
3
+ def test(*args, &block); end
4
+ end
5
+ end
@@ -1,7 +1,11 @@
1
+ require 'rubygems'
2
+
1
3
  ENV["RAILS_ENV"] = "test"
2
- require File.join(File.dirname(__FILE__), 'rails_app', 'config', 'environment')
4
+ DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
5
+
6
+ puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
7
+ require File.join(File.dirname(__FILE__), 'orm', DEVISE_ORM.to_s)
3
8
 
4
- require 'test_help'
5
9
  require 'webrat'
6
10
  require 'mocha'
7
11
 
@@ -11,34 +15,7 @@ ActionMailer::Base.delivery_method = :test
11
15
  ActionMailer::Base.perform_deliveries = true
12
16
  ActionMailer::Base.default_url_options[:host] = 'test.com'
13
17
 
14
- ActiveRecord::Migration.verbose = false
15
- ActiveRecord::Base.logger = Logger.new(nil)
16
- ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
17
-
18
- ActiveRecord::Schema.define(:version => 1) do
19
- [:users, :admins, :accounts].each do |table|
20
- create_table table do |t|
21
- t.authenticatable :null => table == :admins
22
-
23
- if table != :admin
24
- t.string :username
25
- t.confirmable
26
- t.recoverable
27
- t.rememberable
28
- t.trackable
29
- end
30
-
31
- t.timestamps
32
- end
33
- end
34
- end
35
-
36
18
  Webrat.configure do |config|
37
19
  config.mode = :rails
38
20
  config.open_error_files = false
39
- end
40
-
41
- class ActiveSupport::TestCase
42
- self.use_transactional_fixtures = true
43
- self.use_instantiated_fixtures = false
44
- end
21
+ end
@@ -39,7 +39,7 @@ class TestHelpersTest < ActionController::TestCase
39
39
  end
40
40
 
41
41
  test "allows to sign in with different users" do
42
- first_user = create_user(1)
42
+ first_user = create_user
43
43
  first_user.confirm!
44
44
 
45
45
  sign_in first_user
@@ -47,15 +47,11 @@ class TestHelpersTest < ActionController::TestCase
47
47
  assert_equal first_user.id.to_s, @response.body
48
48
  sign_out first_user
49
49
 
50
- second_user = create_user(2)
50
+ second_user = create_user
51
51
  second_user.confirm!
52
52
 
53
53
  sign_in second_user
54
54
  get :show
55
55
  assert_equal second_user.id.to_s, @response.body
56
56
  end
57
-
58
- def create_user(i=nil)
59
- User.create!(:email => "jose.valim#{i}@plataformatec.com", :password => "123456")
60
- end
61
57
  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.3
4
+ version: 0.7.4
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-16 00:00:00 +01:00
13
+ date: 2009-12-22 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -69,16 +69,19 @@ files:
69
69
  - lib/devise/encryptors/sha1.rb
70
70
  - lib/devise/encryptors/sha512.rb
71
71
  - lib/devise/failure_app.rb
72
- - lib/devise/hooks/confirmable.rb
72
+ - lib/devise/hooks/activatable.rb
73
73
  - lib/devise/hooks/timeoutable.rb
74
74
  - lib/devise/hooks/trackable.rb
75
75
  - lib/devise/locales/en.yml
76
76
  - lib/devise/mapping.rb
77
77
  - lib/devise/models.rb
78
+ - lib/devise/models/activatable.rb
78
79
  - lib/devise/models/authenticatable.rb
79
80
  - lib/devise/models/confirmable.rb
81
+ - lib/devise/models/cookie_serializer.rb
80
82
  - lib/devise/models/recoverable.rb
81
83
  - lib/devise/models/rememberable.rb
84
+ - lib/devise/models/session_serializer.rb
82
85
  - lib/devise/models/timeoutable.rb
83
86
  - lib/devise/models/trackable.rb
84
87
  - lib/devise/models/validatable.rb
@@ -89,9 +92,9 @@ files:
89
92
  - lib/devise/rails/routes.rb
90
93
  - lib/devise/rails/warden_compat.rb
91
94
  - lib/devise/schema.rb
92
- - lib/devise/serializers/authenticatable.rb
93
95
  - lib/devise/serializers/base.rb
94
- - lib/devise/serializers/rememberable.rb
96
+ - lib/devise/serializers/cookie.rb
97
+ - lib/devise/serializers/session.rb
95
98
  - lib/devise/strategies/authenticatable.rb
96
99
  - lib/devise/strategies/base.rb
97
100
  - lib/devise/test_helpers.rb
@@ -148,20 +151,25 @@ test_files:
148
151
  - test/models/trackable_test.rb
149
152
  - test/models/validatable_test.rb
150
153
  - test/models_test.rb
154
+ - test/orm/active_record.rb
155
+ - test/orm/mongo_mapper.rb
156
+ - test/rails_app/app/active_record/account.rb
157
+ - test/rails_app/app/active_record/admin.rb
158
+ - test/rails_app/app/active_record/user.rb
151
159
  - test/rails_app/app/controllers/admins_controller.rb
152
160
  - test/rails_app/app/controllers/application_controller.rb
153
161
  - test/rails_app/app/controllers/home_controller.rb
154
162
  - test/rails_app/app/controllers/users_controller.rb
155
163
  - test/rails_app/app/helpers/application_helper.rb
156
- - test/rails_app/app/models/account.rb
157
- - test/rails_app/app/models/admin.rb
158
- - test/rails_app/app/models/organizer.rb
159
- - test/rails_app/app/models/user.rb
164
+ - test/rails_app/app/mongo_mapper/account.rb
165
+ - test/rails_app/app/mongo_mapper/admin.rb
166
+ - test/rails_app/app/mongo_mapper/user.rb
160
167
  - test/rails_app/config/boot.rb
161
168
  - test/rails_app/config/environment.rb
162
169
  - test/rails_app/config/environments/development.rb
163
170
  - test/rails_app/config/environments/production.rb
164
171
  - test/rails_app/config/environments/test.rb
172
+ - test/rails_app/config/initializers/devise.rb
165
173
  - test/rails_app/config/initializers/inflections.rb
166
174
  - test/rails_app/config/initializers/new_rails_defaults.rb
167
175
  - test/rails_app/config/initializers/session_store.rb
@@ -170,5 +178,6 @@ test_files:
170
178
  - test/support/assertions_helper.rb
171
179
  - test/support/integration_tests_helper.rb
172
180
  - test/support/model_tests_helper.rb
181
+ - test/support/test_silencer.rb
173
182
  - test/test_helper.rb
174
183
  - test/test_helpers_test.rb
@@ -1,11 +0,0 @@
1
- require 'devise/serializers/base'
2
-
3
- module Devise
4
- module Serializers
5
- class Authenticatable < Warden::Serializers::Session
6
- include Devise::Serializers::Base
7
- end
8
- end
9
- end
10
-
11
- Warden::Serializers.add(:authenticatable, Devise::Serializers::Authenticatable)
@@ -1,30 +0,0 @@
1
- require 'devise/serializers/base'
2
-
3
- module Devise
4
- module Serializers
5
- class Rememberable < Warden::Serializers::Cookie
6
- include Devise::Serializers::Base
7
-
8
- def store(record, scope)
9
- remember_me = params[scope].try(:fetch, :remember_me, nil)
10
- if Devise::TRUE_VALUES.include?(remember_me) && record.respond_to?(:remember_me!)
11
- record.remember_me!
12
- super
13
- end
14
- end
15
-
16
- def default_options(record)
17
- super.merge!(:expires => record.remember_expires_at)
18
- end
19
-
20
- def delete(scope, record=nil)
21
- if record && record.respond_to?(:forget_me!)
22
- record.forget_me!
23
- super
24
- end
25
- end
26
- end
27
- end
28
- end
29
-
30
- Warden::Serializers.add(:rememberable, Devise::Serializers::Rememberable)
@@ -1,3 +0,0 @@
1
- class Organizer < ActiveRecord::Base
2
- devise :all
3
- end