devise_invitable 1.5.2 → 1.5.3

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21840c71f560017345f75d9152e44b295ccb8043
4
- data.tar.gz: 8470539a88ef73abb3ef396a4c043e9405eecd57
3
+ metadata.gz: 34b7a909db3f99e89240bf2b81107b5981e656cb
4
+ data.tar.gz: 47f3c423acd3c430232c028e130174c23720081e
5
5
  SHA512:
6
- metadata.gz: 451e491d4a3a8135bc4d1447d1b9035624f2be5757f03544fe1bf8925e0b08df1317a57ec93cb20f293e5dc77397e3c1ba6a6e854f1b8a7646804ce6b43258fc
7
- data.tar.gz: ee5f07eb0c08aca5310d36b42eb7fa20fee2bbc657a101a79981c5072e6da3593a813ca79bb08ef05d3494db65e228017f692dc96645c1e62b9ff3c4f189e4f8
6
+ metadata.gz: fb028f99d4fc760cdecc7f747b3070fa7c2373d3e5655cdb51c2526245a546f1c8b4b84175810b9b8c1df33f054a0b5b1c4190f2280eda5d31f6f7377e7cffbf
7
+ data.tar.gz: e04a795483022a82a601790ad24d682934322e45348026bd6a3b387b8284b41ca8403e55afddaf57b51d630961cb2650e8fbcea15d9144c07d3e1fde8f23976f
@@ -15,8 +15,8 @@ Install DeviseInvitable gem, it will also install dependencies (such as devise a
15
15
 
16
16
  Add DeviseInvitable to your Gemfile (and Devise if you weren't using them):
17
17
 
18
- gem 'devise', '>= 2.0.0'
19
- gem 'devise_invitable', '~> 1.3.4'
18
+ gem 'devise', '~> 3.5.2'
19
+ gem 'devise_invitable', '~> 1.5.2'
20
20
 
21
21
  === Automatic installation
22
22
 
@@ -5,10 +5,12 @@ class DeviseInvitable::RegistrationsController < Devise::RegistrationsController
5
5
  hash ||= resource_params || {}
6
6
  if hash[:email]
7
7
  self.resource = resource_class.where(:email => hash[:email]).first
8
- if self.resource and self.resource.invited_to_sign_up?
8
+ if self.resource && self.resource.respond_to?(:invited_to_sign_up?) && self.resource.invited_to_sign_up?
9
9
  self.resource.attributes = hash
10
10
  self.resource.send_confirmation_instructions if self.resource.confirmation_required_for_invited?
11
11
  self.resource.accept_invitation
12
+ else
13
+ self.resource = nil
12
14
  end
13
15
  end
14
16
  self.resource ||= super
@@ -73,7 +73,7 @@ module Devise
73
73
  @@invited_by_counter_cache = nil
74
74
 
75
75
  # Public: Auto-login after the user accepts the invite. If this is false,
76
- # the user will need to manually log in after accepting the invite (default: false).
76
+ # the user will need to manually log in after accepting the invite (default: true).
77
77
  mattr_accessor :allow_insecure_sign_in_after_accept
78
78
  @@allow_insecure_sign_in_after_accept = true
79
79
  end
@@ -254,7 +254,7 @@ module Devise
254
254
  invitable = find_or_initialize_with_errors(invite_key_array, attributes_hash)
255
255
  invitable.assign_attributes(attributes)
256
256
  invitable.invited_by = invited_by
257
- unless invitable.password
257
+ unless invitable.password || invitable.encrypted_password.present?
258
258
  invitable.password = Devise.friendly_token[0, 20]
259
259
  end
260
260
 
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '1.5.2'
2
+ VERSION = '1.5.3'
3
3
  end
@@ -53,16 +53,61 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
53
53
  assert !@invitee.confirmed?
54
54
  end
55
55
 
56
+ test "non-invited users may still sign up directly by themselves" do
57
+ register_email = "invitee@example.org"
58
+ # sign_up the invitee
59
+ assert_difference('ActionMailer::Base.deliveries.size') do
60
+ post :create, :user => {:email => register_email, :password => "1password", :bio => '.'}
61
+ end
62
+ assert_nil @controller.current_user
63
+
64
+ @user = User.where(:email => register_email).first
65
+
66
+ # do not send emails on model changes
67
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
68
+ @user.bio = "I am a robot"
69
+ @user.save!
70
+ @user.bio = "I am a human"
71
+ @user.save!
72
+ end
73
+
74
+ assert @user.encrypted_password.present?
75
+ assert_nil @user.invitation_accepted_at
76
+ assert_nil @user.invitation_token
77
+ assert_nil @user.invited_by
78
+ assert @user.confirmation_token.present?
79
+ assert !@user.confirmed?
80
+ end
81
+
56
82
  test "not invitable resources can register" do
57
83
  @request.env["devise.mapping"] = Devise.mappings[:admin]
58
84
  invitee_email = "invitee@example.org"
59
85
 
86
+ assert_nil Admin.where(:email => invitee_email).first
87
+
60
88
  post :create, :admin => {:email => invitee_email, :password => "1password"}
61
89
 
62
90
  @invitee = Admin.where(:email => invitee_email).first
63
91
  assert @invitee.encrypted_password.present?
64
92
  end
65
93
 
94
+ test "not invitable resources are not logged in after sign up again" do
95
+ @request.env["devise.mapping"] = Devise.mappings[:admin]
96
+ invitee_email = "invitee@example.org"
97
+
98
+ post :create, :admin => {:email => invitee_email, :password => "1password"}
99
+ assert_response 302
100
+
101
+ @invitee = Admin.where(:email => invitee_email).first
102
+ assert @invitee.encrypted_password.present?
103
+
104
+ sign_out @invitee
105
+ post :create, :admin => {:email => invitee_email, :password => "2password"}
106
+ assert_response 200
107
+ assert_equal @invitee.encrypted_password, Admin.where(:email => invitee_email).first.encrypted_password
108
+ assert @controller.send(:resource).errors.present?
109
+ end
110
+
66
111
  test "missing params on a create should not cause an error" do
67
112
 
68
113
  assert_nothing_raised { post :create }
@@ -200,8 +200,10 @@ class InvitableTest < ActiveSupport::TestCase
200
200
  user = User.invite!(:email => "valid@email.com")
201
201
  assert user.invitation_token.present?
202
202
  assert_nil user.invitation_accepted_at
203
+ old_encrypted_password = user.encrypted_password
203
204
  User.accept_invitation!(:invitation_token => user.invitation_token, :password => '123456789', :password_confirmation => '987654321')
204
205
  user.reload
206
+ assert_equal old_encrypted_password, user.encrypted_password
205
207
  assert user.invitation_token.present?
206
208
  assert_nil user.invitation_accepted_at
207
209
  end
@@ -436,11 +438,11 @@ class InvitableTest < ActiveSupport::TestCase
436
438
  user.reload
437
439
  assert !user.valid_password?('new_password')
438
440
  end
439
-
441
+
440
442
  test 'should check if created by invitation' do
441
443
  user = User.invite!(:email => "valid@email.com")
442
444
  assert user.created_by_invite?
443
-
445
+
444
446
  invited_user = User.accept_invitation!(
445
447
  :invitation_token => Thread.current[:token],
446
448
  :password => 'new_password',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-23 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler