sorcery 0.8.5 → 0.8.6

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. data/lib/sorcery/test_helpers.rb +0 -5
@@ -1,6 +1,5 @@
1
1
  shared_examples_for "rails_3_activity_logging_model" do
2
- # ----------------- PLUGIN CONFIGURATION -----------------------
3
- describe User, "loaded plugin configuration" do
2
+ context "loaded plugin configuration" do
4
3
  before(:all) do
5
4
  sorcery_reload!([:activity_logging])
6
5
  end
@@ -9,24 +8,25 @@ shared_examples_for "rails_3_activity_logging_model" do
9
8
  User.sorcery_config.reset!
10
9
  end
11
10
 
12
- it "should allow configuration option 'last_login_at_attribute_name'" do
11
+ it "allows configuration option 'last_login_at_attribute_name'" do
13
12
  sorcery_model_property_set(:last_login_at_attribute_name, :login_time)
14
- User.sorcery_config.last_login_at_attribute_name.should equal(:login_time)
13
+
14
+ expect(User.sorcery_config.last_login_at_attribute_name).to eq :login_time
15
15
  end
16
16
 
17
- it "should allow configuration option 'last_logout_at_attribute_name'" do
17
+ it "allows configuration option 'last_logout_at_attribute_name'" do
18
18
  sorcery_model_property_set(:last_logout_at_attribute_name, :logout_time)
19
- User.sorcery_config.last_logout_at_attribute_name.should equal(:logout_time)
19
+ expect(User.sorcery_config.last_logout_at_attribute_name).to eq :logout_time
20
20
  end
21
21
 
22
- it "should allow configuration option 'last_activity_at_attribute_name'" do
22
+ it "allows configuration option 'last_activity_at_attribute_name'" do
23
23
  sorcery_model_property_set(:last_activity_at_attribute_name, :activity_time)
24
- User.sorcery_config.last_activity_at_attribute_name.should equal(:activity_time)
24
+ expect(User.sorcery_config.last_activity_at_attribute_name).to eq :activity_time
25
25
  end
26
26
 
27
- it "should allow configuration option 'last_login_from_ip_adress'" do
27
+ it "allows configuration option 'last_login_from_ip_adress'" do
28
28
  sorcery_model_property_set(:last_login_from_ip_address_name, :ip_address)
29
- User.sorcery_config.last_login_from_ip_address_name.should equal(:ip_address)
29
+ expect(User.sorcery_config.last_login_from_ip_address_name).to eq :ip_address
30
30
  end
31
31
  end
32
32
  end
@@ -1,37 +1,38 @@
1
1
  shared_examples_for "rails_3_brute_force_protection_model" do
2
- # ----------------- PLUGIN CONFIGURATION -----------------------
3
- describe User, "loaded plugin configuration" do
2
+ context "loaded plugin configuration" do
3
+
4
+ let(:config) { User.sorcery_config }
5
+ let(:user) { create_new_user }
4
6
 
5
7
  before(:all) do
6
8
  sorcery_reload!([:brute_force_protection])
7
- create_new_user
8
9
  end
9
10
 
10
11
  after(:each) do
11
12
  User.sorcery_config.reset!
12
13
  end
13
14
 
14
- specify { @user.should respond_to(:failed_logins_count) }
15
- specify { @user.should respond_to(:lock_expires_at) }
15
+ specify { expect(user).to respond_to(:failed_logins_count) }
16
+ specify { expect(user).to respond_to(:lock_expires_at) }
16
17
 
17
- it "should enable configuration option 'failed_logins_count_attribute_name'" do
18
+ it "enables configuration option 'failed_logins_count_attribute_name'" do
18
19
  sorcery_model_property_set(:failed_logins_count_attribute_name, :my_count)
19
- User.sorcery_config.failed_logins_count_attribute_name.should equal(:my_count)
20
+ expect(config.failed_logins_count_attribute_name).to eq :my_count
20
21
  end
21
22
 
22
- it "should enable configuration option 'lock_expires_at_attribute_name'" do
23
+ it "enables configuration option 'lock_expires_at_attribute_name'" do
23
24
  sorcery_model_property_set(:lock_expires_at_attribute_name, :expires)
24
- User.sorcery_config.lock_expires_at_attribute_name.should equal(:expires)
25
+ expect(config.lock_expires_at_attribute_name).to eq :expires
25
26
  end
26
27
 
27
- it "should enable configuration option 'consecutive_login_retries_amount_allowed'" do
28
+ it "enables configuration option 'consecutive_login_retries_amount_allowed'" do
28
29
  sorcery_model_property_set(:consecutive_login_retries_amount_limit, 34)
29
- User.sorcery_config.consecutive_login_retries_amount_limit.should equal(34)
30
+ expect(config.consecutive_login_retries_amount_limit).to eq 34
30
31
  end
31
32
 
32
- it "should enable configuration option 'login_lock_time_period'" do
33
+ it "enables configuration option 'login_lock_time_period'" do
33
34
  sorcery_model_property_set(:login_lock_time_period, 2.hours)
34
- User.sorcery_config.login_lock_time_period.should == 2.hours
35
+ expect(config.login_lock_time_period).to eq 2.hours
35
36
  end
36
37
  end
37
38
  end
@@ -1,31 +1,39 @@
1
1
  shared_examples_for "rails_3_oauth_model" do
2
2
  # ----------------- PLUGIN CONFIGURATION -----------------------
3
- describe User, "loaded plugin configuration" do
4
-
3
+
4
+ let(:external_user) { create_new_external_user :twitter }
5
+
6
+ describe "loaded plugin configuration" do
7
+
5
8
  before(:all) do
9
+ if defined?(DataMapper) && User.ancestors.include?(DataMapper::Resource)
10
+ Authentication.all.destroy
11
+ else
12
+ Authentication.delete_all
13
+ end
6
14
  User.delete_all
7
- Authentication.delete_all
8
15
  sorcery_reload!([:external])
9
16
  sorcery_controller_property_set(:external_providers, [:twitter])
10
17
  sorcery_model_property_set(:authentications_class, Authentication)
11
18
  sorcery_controller_external_property_set(:twitter, :key, "eYVNBjBDi33aa9GkA3w")
12
19
  sorcery_controller_external_property_set(:twitter, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
13
20
  sorcery_controller_external_property_set(:twitter, :callback_url, "http://blabla.com")
14
- create_new_external_user(:twitter)
15
21
  end
16
22
 
17
- it "should respond to 'load_from_provider'" do
18
- User.should respond_to(:load_from_provider)
23
+ it "responds to 'load_from_provider'" do
24
+ expect(User).to respond_to(:load_from_provider)
19
25
  end
20
-
21
- it "'load_from_provider' should load user if exists" do
22
- User.load_from_provider(:twitter,123).should == @user
26
+
27
+ it "'load_from_provider' loads user if exists" do
28
+ external_user
29
+ expect(User.load_from_provider :twitter, 123).to eq external_user
23
30
  end
24
-
25
- it "'load_from_provider' should return nil if user doesn't exist" do
26
- User.load_from_provider(:twitter,980342).should be_nil
31
+
32
+ it "'load_from_provider' returns nil if user doesn't exist" do
33
+ external_user
34
+ expect(User.load_from_provider :twitter, 980342).to be_nil
27
35
  end
28
-
36
+
29
37
  end
30
-
31
- end
38
+
39
+ end
@@ -1,48 +1,57 @@
1
1
  shared_examples_for "rails_3_remember_me_model" do
2
- # ----------------- PLUGIN CONFIGURATION -----------------------
3
- describe User, "loaded plugin configuration" do
2
+ let(:user) { create_new_user }
3
+
4
+ describe "loaded plugin configuration" do
5
+
4
6
  before(:all) do
5
7
  sorcery_reload!([:remember_me])
6
- create_new_user
7
8
  end
8
9
 
9
10
  after(:each) do
10
11
  User.sorcery_config.reset!
11
12
  end
12
13
 
13
- it "should allow configuration option 'remember_me_token_attribute_name'" do
14
+ it "allows configuration option 'remember_me_token_attribute_name'" do
14
15
  sorcery_model_property_set(:remember_me_token_attribute_name, :my_token)
15
- User.sorcery_config.remember_me_token_attribute_name.should equal(:my_token)
16
+
17
+ expect(User.sorcery_config.remember_me_token_attribute_name).to eq :my_token
16
18
  end
17
19
 
18
- it "should allow configuration option 'remember_me_token_expires_at_attribute_name'" do
20
+ it "allows configuration option 'remember_me_token_expires_at_attribute_name'" do
19
21
  sorcery_model_property_set(:remember_me_token_expires_at_attribute_name, :my_expires)
20
- User.sorcery_config.remember_me_token_expires_at_attribute_name.should equal(:my_expires)
22
+
23
+ expect(User.sorcery_config.remember_me_token_expires_at_attribute_name).to eq :my_expires
21
24
  end
22
25
 
23
- specify { @user.should respond_to(:remember_me!) }
24
-
25
- specify { @user.should respond_to(:forget_me!) }
26
+ specify { expect(user).to respond_to :remember_me! }
27
+
28
+ specify { expect(user).to respond_to :forget_me! }
26
29
 
27
- it "should generate a new token on 'remember_me!'" do
28
- @user.remember_me_token.should be_nil
29
- @user.remember_me!
30
- @user.remember_me_token.should_not be_nil
30
+ it "generates a new token on 'remember_me!'" do
31
+ expect(user.remember_me_token).to be_nil
32
+
33
+ user.remember_me!
34
+
35
+ expect(user.remember_me_token).not_to be_nil
31
36
  end
32
37
 
33
38
  # FIXME: assert on line 37 sometimes fails by a second
34
- it "should set an expiration based on 'remember_me_for' attribute" do
39
+ it "sets an expiration based on 'remember_me_for' attribute" do
35
40
  sorcery_model_property_set(:remember_me_for, 2 * 60 * 60 * 24)
36
- @user.remember_me!
37
- @user.remember_me_token_expires_at.utc.to_s.should == (Time.now.in_time_zone + 2 * 60 * 60 * 24).utc.to_s
41
+ user.remember_me!
42
+
43
+ expect(user.remember_me_token_expires_at.utc.to_s).to eq (Time.now.in_time_zone + 2 * 60 * 60 * 24).utc.to_s
38
44
  end
39
45
 
40
- it "should delete the token and expiration on 'forget_me!'" do
41
- @user.remember_me!
42
- @user.remember_me_token.should_not be_nil
43
- @user.forget_me!
44
- @user.remember_me_token.should be_nil
45
- @user.remember_me_token_expires_at.should be_nil
46
+ it "deletes the token and expiration on 'forget_me!'" do
47
+ user.remember_me!
48
+
49
+ expect(user.remember_me_token).not_to be_nil
50
+
51
+ user.forget_me!
52
+
53
+ expect(user.remember_me_token).to be_nil
54
+ expect(user.remember_me_token_expires_at).to be_nil
46
55
  end
47
56
  end
48
57
  end
@@ -1,6 +1,8 @@
1
1
  shared_examples_for "rails_3_reset_password_model" do
2
2
  # ----------------- PLUGIN CONFIGURATION -----------------------
3
- describe User, "loaded plugin configuration" do
3
+ let(:user) { create_new_user }
4
+
5
+ describe "loaded plugin configuration" do
4
6
 
5
7
  before(:all) do
6
8
  sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
@@ -11,32 +13,32 @@ shared_examples_for "rails_3_reset_password_model" do
11
13
  end
12
14
 
13
15
  context "API" do
14
- before(:all) do
15
- create_new_user
16
- end
17
16
 
18
- specify { @user.should respond_to(:deliver_reset_password_instructions!) }
17
+ specify { expect(user).to respond_to :deliver_reset_password_instructions! }
19
18
 
20
- specify { @user.should respond_to(:change_password!) }
19
+ specify { expect(user).to respond_to :change_password! }
21
20
 
22
- it "should respond to .load_from_reset_password_token" do
23
- User.should respond_to(:load_from_reset_password_token)
21
+ it "responds to .load_from_reset_password_token" do
22
+ expect(User).to respond_to :load_from_reset_password_token
24
23
  end
25
24
  end
26
25
 
27
- it "should allow configuration option 'reset_password_token_attribute_name'" do
26
+ it "allows configuration option 'reset_password_token_attribute_name'" do
28
27
  sorcery_model_property_set(:reset_password_token_attribute_name, :my_code)
29
- User.sorcery_config.reset_password_token_attribute_name.should equal(:my_code)
28
+
29
+ expect(User.sorcery_config.reset_password_token_attribute_name).to eq :my_code
30
30
  end
31
31
 
32
- it "should allow configuration option 'reset_password_mailer'" do
32
+ it "allows configuration option 'reset_password_mailer'" do
33
33
  sorcery_model_property_set(:reset_password_mailer, TestUser)
34
- User.sorcery_config.reset_password_mailer.should equal(TestUser)
34
+
35
+ expect(User.sorcery_config.reset_password_mailer).to eq TestUser
35
36
  end
36
37
 
37
- it "should enable configuration option 'reset_password_mailer_disabled'" do
38
+ it "enables configuration option 'reset_password_mailer_disabled'" do
38
39
  sorcery_model_property_set(:reset_password_mailer_disabled, :my_reset_password_mailer_disabled)
39
- User.sorcery_config.reset_password_mailer_disabled.should equal(:my_reset_password_mailer_disabled)
40
+
41
+ expect(User.sorcery_config.reset_password_mailer_disabled).to eq :my_reset_password_mailer_disabled
40
42
  end
41
43
 
42
44
  it "if mailer is nil and mailer is enabled, throw exception!" do
@@ -47,29 +49,33 @@ shared_examples_for "rails_3_reset_password_model" do
47
49
  expect{sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true)}.to_not raise_error
48
50
  end
49
51
 
50
- it "should allow configuration option 'reset_password_email_method_name'" do
52
+ it "allows configuration option 'reset_password_email_method_name'" do
51
53
  sorcery_model_property_set(:reset_password_email_method_name, :my_mailer_method)
52
- User.sorcery_config.reset_password_email_method_name.should equal(:my_mailer_method)
54
+
55
+ expect(User.sorcery_config.reset_password_email_method_name).to eq :my_mailer_method
53
56
  end
54
57
 
55
- it "should allow configuration option 'reset_password_expiration_period'" do
58
+ it "allows configuration option 'reset_password_expiration_period'" do
56
59
  sorcery_model_property_set(:reset_password_expiration_period, 16)
57
- User.sorcery_config.reset_password_expiration_period.should equal(16)
60
+
61
+ expect(User.sorcery_config.reset_password_expiration_period).to eq 16
58
62
  end
59
63
 
60
- it "should allow configuration option 'reset_password_email_sent_at_attribute_name'" do
64
+ it "allows configuration option 'reset_password_email_sent_at_attribute_name'" do
61
65
  sorcery_model_property_set(:reset_password_email_sent_at_attribute_name, :blabla)
62
- User.sorcery_config.reset_password_email_sent_at_attribute_name.should equal(:blabla)
66
+
67
+ expect(User.sorcery_config.reset_password_email_sent_at_attribute_name).to eq :blabla
63
68
  end
64
69
 
65
- it "should allow configuration option 'reset_password_time_between_emails'" do
70
+ it "allows configuration option 'reset_password_time_between_emails'" do
66
71
  sorcery_model_property_set(:reset_password_time_between_emails, 16)
67
- User.sorcery_config.reset_password_time_between_emails.should equal(16)
72
+
73
+ expect(User.sorcery_config.reset_password_time_between_emails).to eq 16
68
74
  end
69
75
  end
70
76
 
71
- # ----------------- PLUGIN ACTIVATED -----------------------
72
- describe User, "when activated with sorcery" do
77
+
78
+ describe "when activated with sorcery" do
73
79
 
74
80
  before(:all) do
75
81
  sorcery_reload!([:reset_password], :reset_password_mailer => ::SorceryMailer)
@@ -77,100 +83,109 @@ shared_examples_for "rails_3_reset_password_model" do
77
83
 
78
84
  before(:each) do
79
85
  User.delete_all
86
+ user
80
87
  end
81
88
 
82
89
  after(:each) do
83
90
  Timecop.return
84
91
  end
85
92
 
86
- it "load_from_reset_password_token should return user when token is found" do
87
- create_new_user
88
- @user.deliver_reset_password_instructions!
89
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
93
+ it "load_from_reset_password_token returns user when token is found" do
94
+ user.deliver_reset_password_instructions!
95
+ updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
96
+
97
+ expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
90
98
  end
91
99
 
92
- it "load_from_reset_password_token should NOT return user when token is NOT found" do
93
- create_new_user
94
- @user.deliver_reset_password_instructions!
95
- User.load_from_reset_password_token("a").should == nil
100
+ it "load_from_reset_password_token does NOT return user when token is NOT found" do
101
+ user.deliver_reset_password_instructions!
102
+
103
+ expect(User.load_from_reset_password_token "a").to be_nil
96
104
  end
97
105
 
98
- it "load_from_reset_password_token should return user when token is found and not expired" do
99
- create_new_user
106
+ it "load_from_reset_password_token returns user when token is found and not expired" do
100
107
  sorcery_model_property_set(:reset_password_expiration_period, 500)
101
- @user.deliver_reset_password_instructions!
102
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
108
+ user.deliver_reset_password_instructions!
109
+ updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
110
+
111
+ expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
103
112
  end
104
113
 
105
- it "load_from_reset_password_token should NOT return user when token is found and expired" do
106
- create_new_user
114
+ it "load_from_reset_password_token does NOT return user when token is found and expired" do
107
115
  sorcery_model_property_set(:reset_password_expiration_period, 0.1)
108
- @user.deliver_reset_password_instructions!
116
+ user.deliver_reset_password_instructions!
109
117
  Timecop.travel(Time.now.in_time_zone+0.5)
110
- User.load_from_reset_password_token(@user.reset_password_token).should == nil
118
+
119
+ expect(User.load_from_reset_password_token user.reset_password_token).to be_nil
111
120
  end
112
121
 
113
- it "load_from_reset_password_token should always be valid if expiration period is nil" do
114
- create_new_user
122
+ it "load_from_reset_password_token is always valid if expiration period is nil" do
115
123
  sorcery_model_property_set(:reset_password_expiration_period, nil)
116
- @user.deliver_reset_password_instructions!
117
- User.load_from_reset_password_token(@user.reset_password_token).should == @user
124
+ user.deliver_reset_password_instructions!
125
+ updated_user = defined?(DataMapper) && user.class.ancestors.include?(DataMapper::Resource) ? User.find(user.id) : user
126
+
127
+ expect(User.load_from_reset_password_token user.reset_password_token).to eq updated_user
118
128
  end
119
129
 
120
- it "load_from_reset_password_token should return nil if token is blank" do
121
- User.load_from_reset_password_token(nil).should == nil
122
- User.load_from_reset_password_token("").should == nil
130
+ it "load_from_reset_password_token returns nil if token is blank" do
131
+ expect(User.load_from_reset_password_token nil).to be_nil
132
+ expect(User.load_from_reset_password_token "").to be_nil
123
133
  end
124
134
 
125
- it "'deliver_reset_password_instructions!' should generate a reset_password_token" do
126
- create_new_user
127
- @user.reset_password_token.should be_nil
128
- @user.deliver_reset_password_instructions!
129
- @user.reset_password_token.should_not be_nil
135
+ it "'deliver_reset_password_instructions!' generates a reset_password_token" do
136
+ expect(user.reset_password_token).to be_nil
137
+
138
+ user.deliver_reset_password_instructions!
139
+
140
+ expect(user.reset_password_token).not_to be_nil
130
141
  end
131
142
 
132
- it "the reset_password_token should be random" do
133
- create_new_user
143
+ it "the reset_password_token is random" do
134
144
  sorcery_model_property_set(:reset_password_time_between_emails, 0)
135
- @user.deliver_reset_password_instructions!
136
- old_password_code = @user.reset_password_token
137
- @user.deliver_reset_password_instructions!
138
- @user.reset_password_token.should_not == old_password_code
145
+ user.deliver_reset_password_instructions!
146
+ old_password_code = user.reset_password_token
147
+ user.deliver_reset_password_instructions!
148
+
149
+ expect(user.reset_password_token).not_to eq old_password_code
139
150
  end
140
151
 
141
152
  context "mailer is enabled" do
142
- it "should send an email on reset" do
143
- create_new_user
153
+ it "sends an email on reset" do
144
154
  old_size = ActionMailer::Base.deliveries.size
145
- @user.deliver_reset_password_instructions!
146
- ActionMailer::Base.deliveries.size.should == old_size + 1
155
+ user.deliver_reset_password_instructions!
156
+
157
+ expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
147
158
  end
148
159
 
149
- it "should call send_reset_password_email! on reset" do
150
- create_new_user
151
- @user.should_receive(:send_reset_password_email!).once
152
- @user.deliver_reset_password_instructions!
160
+ it "calls send_reset_password_email! on reset" do
161
+ expect(user).to receive(:send_reset_password_email!).once
162
+
163
+ user.deliver_reset_password_instructions!
153
164
  end
154
165
 
155
- it "should not send an email if time between emails has not passed since last email" do
156
- create_new_user
166
+ it "does not send an email if time between emails has not passed since last email" do
157
167
  sorcery_model_property_set(:reset_password_time_between_emails, 10000)
158
168
  old_size = ActionMailer::Base.deliveries.size
159
- @user.deliver_reset_password_instructions!
160
- ActionMailer::Base.deliveries.size.should == old_size + 1
161
- @user.deliver_reset_password_instructions!
162
- ActionMailer::Base.deliveries.size.should == old_size + 1
169
+ user.deliver_reset_password_instructions!
170
+
171
+ expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
172
+
173
+ user.deliver_reset_password_instructions!
174
+
175
+ expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
163
176
  end
164
177
 
165
- it "should send an email if time between emails has passed since last email" do
166
- create_new_user
178
+ it "sends an email if time between emails has passed since last email" do
167
179
  sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
168
180
  old_size = ActionMailer::Base.deliveries.size
169
- @user.deliver_reset_password_instructions!
170
- ActionMailer::Base.deliveries.size.should == old_size + 1
181
+ user.deliver_reset_password_instructions!
182
+
183
+ expect(ActionMailer::Base.deliveries.size).to eq old_size + 1
184
+
171
185
  Timecop.travel(Time.now.in_time_zone+0.5)
172
- @user.deliver_reset_password_instructions!
173
- ActionMailer::Base.deliveries.size.should == old_size + 2
186
+ user.deliver_reset_password_instructions!
187
+
188
+ expect(ActionMailer::Base.deliveries.size).to eq old_size + 2
174
189
  end
175
190
  end
176
191
 
@@ -180,62 +195,68 @@ shared_examples_for "rails_3_reset_password_model" do
180
195
  sorcery_reload!([:reset_password], :reset_password_mailer_disabled => true, :reset_password_mailer => ::SorceryMailer)
181
196
  end
182
197
 
183
- it "should send an email on reset" do
184
- create_new_user
198
+ it "sends an email on reset" do
185
199
  old_size = ActionMailer::Base.deliveries.size
186
- @user.deliver_reset_password_instructions!
187
- ActionMailer::Base.deliveries.size.should == old_size
200
+ user.deliver_reset_password_instructions!
201
+
202
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
188
203
  end
189
-
190
- it "should not call send_reset_password_email! on reset" do
191
- create_new_user
192
- @user.should_receive(:send_reset_password_email!).never
193
- @user.deliver_reset_password_instructions!
204
+
205
+ it "does not call send_reset_password_email! on reset" do
206
+ expect(user).to receive(:send_reset_password_email!).never
207
+
208
+ user.deliver_reset_password_instructions!
194
209
  end
195
210
 
196
- it "should not send an email if time between emails has not passed since last email" do
197
- create_new_user
211
+ it "does not send an email if time between emails has not passed since last email" do
198
212
  sorcery_model_property_set(:reset_password_time_between_emails, 10000)
199
213
  old_size = ActionMailer::Base.deliveries.size
200
- @user.deliver_reset_password_instructions!
201
- ActionMailer::Base.deliveries.size.should == old_size
202
- @user.deliver_reset_password_instructions!
203
- ActionMailer::Base.deliveries.size.should == old_size
214
+ user.deliver_reset_password_instructions!
215
+
216
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
217
+
218
+ user.deliver_reset_password_instructions!
219
+
220
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
204
221
  end
205
222
 
206
- it "should send an email if time between emails has passed since last email" do
207
- create_new_user
223
+ it "sends an email if time between emails has passed since last email" do
208
224
  sorcery_model_property_set(:reset_password_time_between_emails, 0.5)
209
225
  old_size = ActionMailer::Base.deliveries.size
210
- @user.deliver_reset_password_instructions!
211
- ActionMailer::Base.deliveries.size.should == old_size
226
+ user.deliver_reset_password_instructions!
227
+
228
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
229
+
212
230
  Timecop.travel(Time.now.in_time_zone+0.5)
213
- @user.deliver_reset_password_instructions!
214
- ActionMailer::Base.deliveries.size.should == old_size
231
+ user.deliver_reset_password_instructions!
232
+
233
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
215
234
  end
216
235
  end
217
236
 
218
- it "when change_password! is called, should delete reset_password_token" do
219
- create_new_user
220
- @user.deliver_reset_password_instructions!
221
- @user.reset_password_token.should_not be_nil
222
- @user.change_password!("blabulsdf")
223
- @user.save!
224
- @user.reset_password_token.should be_nil
237
+ it "when change_password! is called, deletes reset_password_token" do
238
+ user.deliver_reset_password_instructions!
239
+
240
+ expect(user.reset_password_token).not_to be_nil
241
+
242
+ user.change_password!("blabulsdf")
243
+ user.save!
244
+
245
+ expect(user.reset_password_token).to be_nil
225
246
  end
226
247
 
227
- it "should return false if time between emails has not passed since last email" do
228
- create_new_user
248
+ it "returns false if time between emails has not passed since last email" do
229
249
  sorcery_model_property_set(:reset_password_time_between_emails, 10000)
230
- @user.deliver_reset_password_instructions!
231
- @user.deliver_reset_password_instructions!.should == false
250
+ user.deliver_reset_password_instructions!
251
+
252
+ expect(user.deliver_reset_password_instructions!).to be false
232
253
  end
233
254
 
234
- it "should encrypt properly on reset" do
235
- create_new_user
236
- @user.deliver_reset_password_instructions!
237
- @user.change_password!("blagu")
238
- Sorcery::CryptoProviders::BCrypt.matches?(@user.crypted_password,"blagu",@user.salt).should be_true
255
+ it "encrypts properly on reset" do
256
+ user.deliver_reset_password_instructions!
257
+ user.change_password!("blagu")
258
+
259
+ expect(Sorcery::CryptoProviders::BCrypt.matches? user.crypted_password, "blagu", user.salt).to be true
239
260
  end
240
261
 
241
262
  end