sorcery 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -272
  6. data/Rakefile +2 -2
  7. data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
  8. data/lib/generators/sorcery/helpers.rb +4 -4
  9. data/lib/generators/sorcery/install_generator.rb +25 -19
  10. data/lib/generators/sorcery/templates/initializer.rb +27 -52
  11. data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
  12. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/core.rb +3 -3
  14. data/lib/generators/sorcery/templates/migration/external.rb +2 -2
  15. data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
  16. data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
  17. data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
  18. data/lib/sorcery.rb +0 -28
  19. data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
  20. data/lib/sorcery/controller.rb +19 -21
  21. data/lib/sorcery/controller/config.rb +20 -18
  22. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  23. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  24. data/lib/sorcery/controller/submodules/external.rb +22 -14
  25. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  26. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  27. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  28. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  29. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  30. data/lib/sorcery/crypto_providers/common.rb +1 -1
  31. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  33. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  34. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  35. data/lib/sorcery/engine.rb +3 -8
  36. data/lib/sorcery/model.rb +24 -32
  37. data/lib/sorcery/model/config.rb +64 -49
  38. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  39. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  40. data/lib/sorcery/model/submodules/external.rb +3 -7
  41. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  42. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  43. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  44. data/lib/sorcery/model/temporary_token.rb +2 -2
  45. data/lib/sorcery/protocols/oauth.rb +3 -9
  46. data/lib/sorcery/protocols/oauth2.rb +0 -2
  47. data/lib/sorcery/providers/base.rb +4 -4
  48. data/lib/sorcery/providers/facebook.rb +5 -8
  49. data/lib/sorcery/providers/github.rb +5 -7
  50. data/lib/sorcery/providers/google.rb +3 -5
  51. data/lib/sorcery/providers/heroku.rb +6 -8
  52. data/lib/sorcery/providers/jira.rb +12 -17
  53. data/lib/sorcery/providers/linkedin.rb +6 -8
  54. data/lib/sorcery/providers/liveid.rb +4 -7
  55. data/lib/sorcery/providers/paypal.rb +60 -0
  56. data/lib/sorcery/providers/salesforce.rb +3 -5
  57. data/lib/sorcery/providers/slack.rb +45 -0
  58. data/lib/sorcery/providers/twitter.rb +4 -6
  59. data/lib/sorcery/providers/vk.rb +3 -5
  60. data/lib/sorcery/providers/wechat.rb +79 -0
  61. data/lib/sorcery/providers/xing.rb +7 -10
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  64. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  65. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  66. data/lib/sorcery/version.rb +1 -1
  67. data/sorcery.gemspec +25 -27
  68. data/spec/active_record/user_activation_spec.rb +2 -3
  69. data/spec/active_record/user_activity_logging_spec.rb +2 -4
  70. data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
  71. data/spec/active_record/user_oauth_spec.rb +3 -4
  72. data/spec/active_record/user_remember_me_spec.rb +3 -4
  73. data/spec/active_record/user_reset_password_spec.rb +2 -3
  74. data/spec/active_record/user_spec.rb +7 -7
  75. data/spec/controllers/controller_activity_logging_spec.rb +13 -24
  76. data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
  77. data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
  78. data/spec/controllers/controller_oauth2_spec.rb +125 -100
  79. data/spec/controllers/controller_oauth_spec.rb +86 -66
  80. data/spec/controllers/controller_remember_me_spec.rb +35 -30
  81. data/spec/controllers/controller_session_timeout_spec.rb +14 -15
  82. data/spec/controllers/controller_spec.rb +77 -111
  83. data/spec/orm/active_record.rb +1 -1
  84. data/spec/rails_app/app/active_record/authentication.rb +1 -1
  85. data/spec/rails_app/app/active_record/user.rb +2 -2
  86. data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
  87. data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
  88. data/spec/rails_app/config.ru +1 -1
  89. data/spec/rails_app/config/application.rb +7 -7
  90. data/spec/rails_app/config/boot.rb +1 -1
  91. data/spec/rails_app/config/environments/test.rb +1 -1
  92. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  93. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  94. data/spec/rails_app/config/routes.rb +11 -1
  95. data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
  96. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
  97. data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
  98. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
  99. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
  100. data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
  101. data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
  102. data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
  103. data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
  104. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
  105. data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
  106. data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
  107. data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
  108. data/spec/shared_examples/user_shared_examples.rb +215 -118
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -83
  112. data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
  113. data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
  114. data/gemfiles/mongoid-rails41.gemfile +0 -9
  115. data/gemfiles/mongoid3-rails32.gemfile +0 -9
  116. data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
  117. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
  118. data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
  119. data/lib/sorcery/railties/tasks.rake +0 -6
  120. data/spec/data_mapper/user_activation_spec.rb +0 -10
  121. data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
  122. data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
  123. data/spec/data_mapper/user_oauth_spec.rb +0 -9
  124. data/spec/data_mapper/user_remember_me_spec.rb +0 -8
  125. data/spec/data_mapper/user_reset_password_spec.rb +0 -8
  126. data/spec/data_mapper/user_spec.rb +0 -27
  127. data/spec/mongo_mapper/user_activation_spec.rb +0 -9
  128. data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
  129. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
  130. data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
  131. data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
  132. data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
  133. data/spec/mongo_mapper/user_spec.rb +0 -37
  134. data/spec/mongoid/user_activation_spec.rb +0 -9
  135. data/spec/mongoid/user_activity_logging_spec.rb +0 -8
  136. data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
  137. data/spec/mongoid/user_oauth_spec.rb +0 -8
  138. data/spec/mongoid/user_remember_me_spec.rb +0 -8
  139. data/spec/mongoid/user_reset_password_spec.rb +0 -8
  140. data/spec/mongoid/user_spec.rb +0 -51
  141. data/spec/orm/data_mapper.rb +0 -48
  142. data/spec/orm/mongo_mapper.rb +0 -10
  143. data/spec/orm/mongoid.rb +0 -22
  144. data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
  145. data/spec/rails_app/app/data_mapper/user.rb +0 -7
  146. data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
  147. data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
  148. data/spec/rails_app/app/mongoid/authentication.rb +0 -7
  149. data/spec/rails_app/app/mongoid/user.rb +0 -7
@@ -1,32 +1,31 @@
1
1
  class SorceryMailer < ActionMailer::Base
2
-
3
- default :from => "notifications@example.com"
4
-
2
+ default from: 'notifications@example.com'
3
+
5
4
  def activation_needed_email(user)
6
5
  @user = user
7
- @url = "http://example.com/login"
8
- mail(:to => user.email,
9
- :subject => "Welcome to My Awesome Site")
6
+ @url = 'http://example.com/login'
7
+ mail(to: user.email,
8
+ subject: 'Welcome to My Awesome Site')
10
9
  end
11
-
10
+
12
11
  def activation_success_email(user)
13
12
  @user = user
14
- @url = "http://example.com/login"
15
- mail(:to => user.email,
16
- :subject => "Your account is now activated")
13
+ @url = 'http://example.com/login'
14
+ mail(to: user.email,
15
+ subject: 'Your account is now activated')
17
16
  end
18
-
17
+
19
18
  def reset_password_email(user)
20
19
  @user = user
21
- @url = "http://example.com/login"
22
- mail(:to => user.email,
23
- :subject => "Your password has been reset")
20
+ @url = 'http://example.com/login'
21
+ mail(to: user.email,
22
+ subject: 'Your password has been reset')
24
23
  end
25
24
 
26
25
  def send_unlock_token_email(user)
27
26
  @user = user
28
27
  @url = "http://example.com/unlock/#{user.unlock_token}"
29
- mail(:to => user.email,
30
- :subject => "Your account has been locked due to many wrong logins")
28
+ mail(to: user.email,
29
+ subject: 'Your account has been locked due to many wrong logins')
31
30
  end
32
- end
31
+ end
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
4
  run RailsApp::Application
@@ -1,8 +1,8 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require "action_controller/railtie"
4
- require "action_mailer/railtie"
5
- require "rails/test_unit/railtie"
3
+ require 'action_controller/railtie'
4
+ require 'action_mailer/railtie'
5
+ require 'rails/test_unit/railtie'
6
6
 
7
7
  Bundler.require :default, SORCERY_ORM
8
8
 
@@ -11,12 +11,12 @@ begin
11
11
  rescue LoadError
12
12
  end
13
13
 
14
- require "sorcery"
14
+ require 'sorcery'
15
15
 
16
16
  module AppRoot
17
17
  class Application < Rails::Application
18
- config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers mailers views).include?($1) }
19
- config.autoload_paths += [ "#{config.root}/app/#{SORCERY_ORM}" ]
18
+ config.autoload_paths.reject! { |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers mailers views).include?(Regexp.last_match(1)) }
19
+ config.autoload_paths += ["#{config.root}/app/#{SORCERY_ORM}"]
20
20
 
21
21
  # Settings in config/environments/* take precedence over those specified here.
22
22
  # Application configuration should go into files in config/initializers
@@ -44,7 +44,7 @@ module AppRoot
44
44
  # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
45
45
 
46
46
  # Configure the default encoding used in templates for Ruby 1.9.
47
- config.encoding = "utf-8"
47
+ config.encoding = 'utf-8'
48
48
 
49
49
  # Configure sensitive parameters which will be filtered from the log file.
50
50
  config.filter_parameters += [:password]
@@ -1,4 +1,4 @@
1
1
  # Set up gems listed in the Gemfile.
2
2
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
3
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
@@ -18,7 +18,7 @@ AppRoot::Application.configure do
18
18
  config.action_dispatch.show_exceptions = false
19
19
 
20
20
  # Disable request forgery protection in test environment
21
- config.action_controller.allow_forgery_protection = false
21
+ config.action_controller.allow_forgery_protection = false
22
22
 
23
23
  # Tell Action Mailer not to deliver emails to the real world.
24
24
  # The :test delivery method accumulates sent emails in the
@@ -0,0 +1,11 @@
1
+ module ActiveRecord
2
+ module CompatibleLegacyMigration
3
+ def self.migration_class
4
+ if Rails::VERSION::MAJOR >= 5
5
+ ActiveRecord::Migration::Current
6
+ else
7
+ ActiveRecord::Migration
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,6 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
- AppRoot::Application.config.session_store :cookie_store, :key => '_app_root_session'
3
+ AppRoot::Application.config.session_store :cookie_store, key: '_app_root_session'
4
4
 
5
5
  # Use the database for sessions instead of the cookie-based default,
6
6
  # which shouldn't be used to store highly confidential information
@@ -8,5 +8,5 @@ AppRoot::Application.config.session_store :cookie_store, :key => '_app_root_sess
8
8
  # AppRoot::Application.config.session_store :active_record_store
9
9
 
10
10
  if AppRoot::Application.config.respond_to?(:secret_key_base=)
11
- AppRoot::Application.config.secret_key_base = "foobar"
12
- end
11
+ AppRoot::Application.config.secret_key_base = 'foobar'
12
+ end
@@ -1,5 +1,5 @@
1
1
  AppRoot::Application.routes.draw do
2
- root :to => "application#index"
2
+ root to: 'application#index'
3
3
 
4
4
  controller :sorcery do
5
5
  get :test_login
@@ -11,6 +11,7 @@ AppRoot::Application.routes.draw do
11
11
  get :test_login_from_cookie
12
12
  get :test_login_from
13
13
  get :test_logout_with_remember
14
+ get :test_logout_with_force_forget_me
14
15
  get :test_should_be_logged_in
15
16
  get :test_create_from_provider
16
17
  get :test_add_second_provider
@@ -19,29 +20,38 @@ AppRoot::Application.routes.draw do
19
20
  get :test_login_from_twitter
20
21
  get :test_login_from_facebook
21
22
  get :test_login_from_github
23
+ get :test_login_from_paypal
24
+ get :test_login_from_wechat
22
25
  get :test_login_from_google
23
26
  get :test_login_from_liveid
24
27
  get :test_login_from_vk
25
28
  get :test_login_from_jira
26
29
  get :test_login_from_salesforce
30
+ get :test_login_from_slack
27
31
  get :login_at_test
28
32
  get :login_at_test_twitter
29
33
  get :login_at_test_facebook
30
34
  get :login_at_test_github
35
+ get :login_at_test_paypal
36
+ get :login_at_test_wechat
31
37
  get :login_at_test_google
32
38
  get :login_at_test_liveid
33
39
  get :login_at_test_vk
34
40
  get :login_at_test_jira
35
41
  get :login_at_test_salesforce
42
+ get :login_at_test_slack
36
43
  get :test_return_to_with_external
37
44
  get :test_return_to_with_external_twitter
38
45
  get :test_return_to_with_external_facebook
39
46
  get :test_return_to_with_external_github
47
+ get :test_return_to_with_external_paypal
48
+ get :test_return_to_with_external_wechat
40
49
  get :test_return_to_with_external_google
41
50
  get :test_return_to_with_external_liveid
42
51
  get :test_return_to_with_external_vk
43
52
  get :test_return_to_with_external_jira
44
53
  get :test_return_to_with_external_salesforce
54
+ get :test_return_to_with_external_slack
45
55
  get :test_http_basic_auth
46
56
  get :some_action_making_a_non_persisted_change_to_the_user
47
57
  post :test_login_with_remember
@@ -1,8 +1,8 @@
1
- class AddActivationToUsers < ActiveRecord::Migration
1
+ class AddActivationToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
- add_column :users, :activation_state, :string, :default => nil
4
- add_column :users, :activation_token, :string, :default => nil
5
- add_column :users, :activation_token_expires_at, :datetime, :default => nil
3
+ add_column :users, :activation_state, :string, default: nil
4
+ add_column :users, :activation_token, :string, default: nil
5
+ add_column :users, :activation_token_expires_at, :datetime, default: nil
6
6
 
7
7
  add_index :users, :activation_token
8
8
  end
@@ -1,19 +1,19 @@
1
- class AddActivityLoggingToUsers < ActiveRecord::Migration
1
+ class AddActivityLoggingToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
- add_column :users, :last_login_at, :datetime, :default => nil
4
- add_column :users, :last_logout_at, :datetime, :default => nil
5
- add_column :users, :last_activity_at, :datetime, :default => nil
6
- add_column :users, :last_login_from_ip_address, :string, :default => nil
7
-
3
+ add_column :users, :last_login_at, :datetime, default: nil
4
+ add_column :users, :last_logout_at, :datetime, default: nil
5
+ add_column :users, :last_activity_at, :datetime, default: nil
6
+ add_column :users, :last_login_from_ip_address, :string, default: nil
7
+
8
8
  add_index :users, [:last_logout_at, :last_activity_at]
9
9
  end
10
10
 
11
11
  def self.down
12
12
  remove_index :users, [:last_logout_at, :last_activity_at]
13
-
13
+
14
14
  remove_column :users, :last_activity_at
15
15
  remove_column :users, :last_logout_at
16
16
  remove_column :users, :last_login_at
17
17
  remove_column :users, :last_login_from_ip_address
18
18
  end
19
- end
19
+ end
@@ -1,8 +1,8 @@
1
- class AddBruteForceProtectionToUsers < ActiveRecord::Migration
1
+ class AddBruteForceProtectionToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
- add_column :users, :failed_logins_count, :integer, :default => 0
4
- add_column :users, :lock_expires_at, :datetime, :default => nil
5
- add_column :users, :unlock_token, :string, :default => nil
3
+ add_column :users, :failed_logins_count, :integer, default: 0
4
+ add_column :users, :lock_expires_at, :datetime, default: nil
5
+ add_column :users, :unlock_token, :string, default: nil
6
6
  end
7
7
 
8
8
  def self.down
@@ -10,4 +10,4 @@ class AddBruteForceProtectionToUsers < ActiveRecord::Migration
10
10
  remove_column :users, :lock_expires_at
11
11
  remove_column :users, :failed_logins_count
12
12
  end
13
- end
13
+ end
@@ -1,16 +1,16 @@
1
- class CreateUsers < ActiveRecord::Migration
1
+ class CreateUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
3
  create_table :users do |t|
4
- t.string :username, :null => false
5
- t.string :email, :default => nil
4
+ t.string :username, null: false
5
+ t.string :email, default: nil
6
6
  t.string :crypted_password
7
7
  t.string :salt
8
8
 
9
- t.timestamps
9
+ t.timestamps null: false
10
10
  end
11
11
  end
12
12
 
13
13
  def self.down
14
14
  drop_table :users
15
15
  end
16
- end
16
+ end
@@ -1,17 +1,17 @@
1
- class CreateAuthenticationsAndUserProviders < ActiveRecord::Migration
1
+ class CreateAuthenticationsAndUserProviders < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
3
  create_table :authentications do |t|
4
4
  t.integer :user_id, null: false
5
5
  t.string :provider, :uid, null: false
6
6
 
7
- t.timestamps
7
+ t.timestamps null: false
8
8
  end
9
9
 
10
10
  create_table :user_providers do |t|
11
11
  t.integer :user_id, null: false
12
12
  t.string :provider, :uid, null: false
13
13
 
14
- t.timestamps
14
+ t.timestamps null: false
15
15
  end
16
16
  end
17
17
 
@@ -1,15 +1,15 @@
1
- class AddRememberMeTokenToUsers < ActiveRecord::Migration
1
+ class AddRememberMeTokenToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
- add_column :users, :remember_me_token, :string, :default => nil
4
- add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
5
-
3
+ add_column :users, :remember_me_token, :string, default: nil
4
+ add_column :users, :remember_me_token_expires_at, :datetime, default: nil
5
+
6
6
  add_index :users, :remember_me_token
7
7
  end
8
8
 
9
9
  def self.down
10
10
  remove_index :users, :remember_me_token
11
-
11
+
12
12
  remove_column :users, :remember_me_token_expires_at
13
13
  remove_column :users, :remember_me_token
14
14
  end
15
- end
15
+ end
@@ -1,8 +1,8 @@
1
- class AddResetPasswordToUsers < ActiveRecord::Migration
1
+ class AddResetPasswordToUsers < ActiveRecord::CompatibleLegacyMigration.migration_class
2
2
  def self.up
3
- add_column :users, :reset_password_token, :string, :default => nil
4
- add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
5
- add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
3
+ add_column :users, :reset_password_token, :string, default: nil
4
+ add_column :users, :reset_password_token_expires_at, :datetime, default: nil
5
+ add_column :users, :reset_password_email_sent_at, :datetime, default: nil
6
6
  end
7
7
 
8
8
  def self.down
@@ -10,4 +10,4 @@ class AddResetPasswordToUsers < ActiveRecord::Migration
10
10
  remove_column :users, :reset_password_token_expires_at
11
11
  remove_column :users, :reset_password_token
12
12
  end
13
- end
13
+ end
@@ -1,15 +1,15 @@
1
- shared_examples_for "rails_3_activation_model" do
1
+ shared_examples_for 'rails_3_activation_model' do
2
2
  let(:user) { create_new_user }
3
3
  let(:new_user) { build_new_user }
4
4
 
5
- context "loaded plugin configuration" do
5
+ context 'loaded plugin configuration' do
6
6
  before(:all) do
7
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
7
+ sorcery_reload!([:user_activation], user_activation_mailer: ::SorceryMailer)
8
8
  end
9
9
 
10
10
  after(:each) do
11
11
  User.sorcery_config.reset!
12
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
12
+ sorcery_reload!([:user_activation], user_activation_mailer: ::SorceryMailer)
13
13
  end
14
14
 
15
15
  it "enables configuration option 'activation_state_attribute_name'" do
@@ -48,23 +48,22 @@ shared_examples_for "rails_3_activation_model" do
48
48
  expect(User.sorcery_config.activation_mailer_disabled).to eq :my_activation_mailer_disabled
49
49
  end
50
50
 
51
- it "if mailer is nil and mailer is enabled, throw exception!" do
52
- expect{sorcery_reload!([:user_activation], :activation_mailer_disabled => false)}.to raise_error(ArgumentError)
51
+ it 'if mailer is nil and mailer is enabled, throw exception!' do
52
+ expect { sorcery_reload!([:user_activation], activation_mailer_disabled: false) }.to raise_error(ArgumentError)
53
53
  end
54
54
 
55
- it "if mailer is disabled and mailer is nil, do NOT throw exception" do
56
- expect{sorcery_reload!([:user_activation], :activation_mailer_disabled => true)}.to_not raise_error
55
+ it 'if mailer is disabled and mailer is nil, do NOT throw exception' do
56
+ expect { sorcery_reload!([:user_activation], activation_mailer_disabled: true) }.to_not raise_error
57
57
  end
58
58
  end
59
59
 
60
-
61
- context "activation process" do
60
+ context 'activation process' do
62
61
  before(:all) do
63
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
62
+ sorcery_reload!([:user_activation], user_activation_mailer: ::SorceryMailer)
64
63
  end
65
64
 
66
65
  it "initializes user state to 'pending'" do
67
- expect(user.activation_state).to eq "pending"
66
+ expect(user.activation_state).to eq 'pending'
68
67
  end
69
68
 
70
69
  specify { expect(user).to respond_to :activate! }
@@ -75,35 +74,34 @@ shared_examples_for "rails_3_activation_model" do
75
74
  user2 = User.sorcery_adapter.find(user.id) # go to db to make sure it was saved and not just in memory
76
75
 
77
76
  expect(user2.activation_token).to be_nil
78
- expect(user2.activation_state).to eq "active"
79
- expect(User.sorcery_adapter.find_by_activation_token activation_token).to be_nil
77
+ expect(user2.activation_state).to eq 'active'
78
+ expect(User.sorcery_adapter.find_by_activation_token(activation_token)).to be_nil
80
79
  end
81
80
 
82
-
83
- context "mailer is enabled" do
84
- it "sends the user an activation email" do
81
+ context 'mailer is enabled' do
82
+ it 'sends the user an activation email' do
85
83
  old_size = ActionMailer::Base.deliveries.size
86
84
  create_new_user
87
85
 
88
86
  expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
89
87
  end
90
88
 
91
- it "calls send_activation_needed_email! method of user" do
89
+ it 'calls send_activation_needed_email! method of user' do
92
90
  expect(new_user).to receive(:send_activation_needed_email!).once
93
91
 
94
- new_user.sorcery_adapter.save(:raise_on_failure => true)
92
+ new_user.sorcery_adapter.save(raise_on_failure: true)
95
93
  end
96
94
 
97
- it "subsequent saves do not send activation email" do
95
+ it 'subsequent saves do not send activation email' do
98
96
  user
99
97
  old_size = ActionMailer::Base.deliveries.size
100
- user.email = "Shauli"
101
- user.sorcery_adapter.save(:raise_on_failure => true)
98
+ user.email = 'Shauli'
99
+ user.sorcery_adapter.save(raise_on_failure: true)
102
100
 
103
101
  expect(ActionMailer::Base.deliveries.size).to eq old_size
104
102
  end
105
103
 
106
- it "sends the user an activation success email on successful activation" do
104
+ it 'sends the user an activation success email on successful activation' do
107
105
  user
108
106
  old_size = ActionMailer::Base.deliveries.size
109
107
  user.activate!
@@ -111,64 +109,107 @@ shared_examples_for "rails_3_activation_model" do
111
109
  expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
112
110
  end
113
111
 
114
- it "calls send_activation_success_email! method of user on activation" do
112
+ it 'calls send_activation_success_email! method of user on activation' do
115
113
  expect(user).to receive(:send_activation_success_email!).once
116
114
 
117
115
  user.activate!
118
116
  end
119
117
 
120
- it "subsequent saves do not send activation success email" do
118
+ it 'subsequent saves do not send activation success email' do
121
119
  user.activate!
122
120
  old_size = ActionMailer::Base.deliveries.size
123
- user.email = "Shauli"
124
- user.sorcery_adapter.save(:raise_on_failure => true)
121
+ user.email = 'Shauli'
122
+ user.sorcery_adapter.save(raise_on_failure: true)
125
123
 
126
124
  expect(ActionMailer::Base.deliveries.size).to eq old_size
127
125
  end
128
126
 
129
- it "activation needed email is optional" do
127
+ it 'activation needed email is optional' do
130
128
  sorcery_model_property_set(:activation_needed_email_method_name, nil)
131
129
  old_size = ActionMailer::Base.deliveries.size
132
130
 
133
131
  expect(ActionMailer::Base.deliveries.size).to eq old_size
134
132
  end
135
133
 
136
- it "activation success email is optional" do
134
+ it 'activation success email is optional' do
137
135
  sorcery_model_property_set(:activation_success_email_method_name, nil)
138
136
  old_size = ActionMailer::Base.deliveries.size
139
137
  user.activate!
140
138
 
141
139
  expect(ActionMailer::Base.deliveries.size).to eq old_size
142
140
  end
141
+
142
+ context 'activation_needed_email is skipped' do
143
+ before(:each) do
144
+ @user = build_new_user
145
+ @user.skip_activation_needed_email = true
146
+ end
147
+
148
+ it 'does not send the user an activation email' do
149
+ old_size = ActionMailer::Base.deliveries.size
150
+
151
+ @user.sorcery_adapter.save(raise_on_failure: true)
152
+
153
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
154
+ end
155
+
156
+ it 'does not call send_activation_needed_email! method of user' do
157
+ expect(@user).to receive(:send_activation_needed_email!).never
158
+
159
+ @user.sorcery_adapter.save(raise_on_failure: true)
160
+ end
161
+
162
+ it 'calls send_activation_success_email! method of user on activation' do
163
+ expect(@user).to receive(:send_activation_success_email!).never
164
+
165
+ @user.activate!
166
+ end
167
+ end
168
+
169
+ context 'activation_success_email is skipped' do
170
+ before(:each) do
171
+ @user = build_new_user
172
+ @user.skip_activation_success_email = true
173
+ end
174
+
175
+ it 'does not send the user an activation success email on successful activation' do
176
+ old_size = ActionMailer::Base.deliveries.size
177
+
178
+ @user.activate!
179
+
180
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
181
+ end
182
+ end
143
183
  end
144
184
 
145
- context "mailer has been disabled" do
185
+ context 'mailer has been disabled' do
146
186
  before(:each) do
147
- sorcery_reload!([:user_activation], :activation_mailer_disabled => true, :user_activation_mailer => ::SorceryMailer)
187
+ sorcery_reload!([:user_activation], activation_mailer_disabled: true, user_activation_mailer: ::SorceryMailer)
148
188
  end
149
189
 
150
- it "does not send the user an activation email" do
190
+ it 'does not send the user an activation email' do
151
191
  old_size = ActionMailer::Base.deliveries.size
192
+ create_new_user
152
193
 
153
194
  expect(ActionMailer::Base.deliveries.size).to eq old_size
154
195
  end
155
196
 
156
- it "does not call send_activation_needed_email! method of user" do
197
+ it 'does not call send_activation_needed_email! method of user' do
157
198
  user = build_new_user
158
199
 
159
200
  expect(user).to receive(:send_activation_needed_email!).never
160
201
 
161
- user.sorcery_adapter.save(:raise_on_failure => true)
202
+ user.sorcery_adapter.save(raise_on_failure: true)
162
203
  end
163
204
 
164
- it "does not send the user an activation success email on successful activation" do
205
+ it 'does not send the user an activation success email on successful activation' do
165
206
  old_size = ActionMailer::Base.deliveries.size
166
207
  user.activate!
167
208
 
168
209
  expect(ActionMailer::Base.deliveries.size).to eq old_size
169
210
  end
170
211
 
171
- it "calls send_activation_success_email! method of user on activation" do
212
+ it 'calls send_activation_success_email! method of user on activation' do
172
213
  expect(user).to receive(:send_activation_success_email!).never
173
214
 
174
215
  user.activate!
@@ -176,67 +217,67 @@ shared_examples_for "rails_3_activation_model" do
176
217
  end
177
218
  end
178
219
 
179
- describe "prevent non-active login feature" do
220
+ describe 'prevent non-active login feature' do
180
221
  before(:all) do
181
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
222
+ sorcery_reload!([:user_activation], user_activation_mailer: ::SorceryMailer)
182
223
  end
183
224
 
184
225
  before(:each) do
185
226
  User.sorcery_adapter.delete_all
186
227
  end
187
228
 
188
- it "does not allow a non-active user to authenticate" do
189
- expect(User.authenticate user.email, 'secret').to be_falsy
229
+ it 'does not allow a non-active user to authenticate' do
230
+ expect(User.authenticate(user.email, 'secret')).to be_falsy
190
231
  end
191
232
 
192
- it "allows a non-active user to authenticate if configured so" do
233
+ it 'allows a non-active user to authenticate if configured so' do
193
234
  sorcery_model_property_set(:prevent_non_active_users_to_login, false)
194
235
 
195
- expect(User.authenticate user.email, 'secret').to be_truthy
236
+ expect(User.authenticate(user.email, 'secret')).to be_truthy
196
237
  end
197
238
  end
198
239
 
199
- describe "load_from_activation_token" do
240
+ describe 'load_from_activation_token' do
200
241
  before(:all) do
201
- sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
242
+ sorcery_reload!([:user_activation], user_activation_mailer: ::SorceryMailer)
202
243
  end
203
244
 
204
245
  after(:each) do
205
246
  Timecop.return
206
247
  end
207
248
 
208
- it "load_from_activation_token returns user when token is found" do
209
- expect(User.load_from_activation_token user.activation_token).to eq user
249
+ it 'load_from_activation_token returns user when token is found' do
250
+ expect(User.load_from_activation_token(user.activation_token)).to eq user
210
251
  end
211
252
 
212
- it "load_from_activation_token does NOT return user when token is NOT found" do
213
- expect(User.load_from_activation_token "a").to be_nil
253
+ it 'load_from_activation_token does NOT return user when token is NOT found' do
254
+ expect(User.load_from_activation_token('a')).to be_nil
214
255
  end
215
256
 
216
- it "load_from_activation_token returas user when token is found and not expired" do
257
+ it 'load_from_activation_token returas user when token is found and not expired' do
217
258
  sorcery_model_property_set(:activation_token_expiration_period, 500)
218
259
 
219
- expect(User.load_from_activation_token user.activation_token).to eq user
260
+ expect(User.load_from_activation_token(user.activation_token)).to eq user
220
261
  end
221
262
 
222
- it "load_from_activation_token does NOT return user when token is found and expired" do
263
+ it 'load_from_activation_token does NOT return user when token is found and expired' do
223
264
  sorcery_model_property_set(:activation_token_expiration_period, 0.1)
224
265
  user
225
266
 
226
- Timecop.travel(Time.now.in_time_zone+0.5)
267
+ Timecop.travel(Time.now.in_time_zone + 0.5)
227
268
 
228
- expect(User.load_from_activation_token user.activation_token).to be_nil
269
+ expect(User.load_from_activation_token(user.activation_token)).to be_nil
229
270
  end
230
271
 
231
- it "load_from_activation_token returns nil if token is blank" do
232
- expect(User.load_from_activation_token nil).to be_nil
233
- expect(User.load_from_activation_token "").to be_nil
272
+ it 'load_from_activation_token returns nil if token is blank' do
273
+ expect(User.load_from_activation_token(nil)).to be_nil
274
+ expect(User.load_from_activation_token('')).to be_nil
234
275
  end
235
276
 
236
- it "load_from_activation_token is always valid if expiration period is nil" do
277
+ it 'load_from_activation_token is always valid if expiration period is nil' do
237
278
  sorcery_model_property_set(:activation_token_expiration_period, nil)
238
279
 
239
- expect(User.load_from_activation_token user.activation_token).to eq user
280
+ expect(User.load_from_activation_token(user.activation_token)).to eq user
240
281
  end
241
282
  end
242
283
  end