devise_invitable 1.3.5 → 1.3.6

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

Potentially problematic release.


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

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- metadata.gz: 47b3e5072420f492fdb25c04d955860feae08b9cc8f58b06f67d2cfc00405f46b101f7111c1d7bd40231bf3d5d8db398f9ee4f05d9498014b49be2bea9138c6b
4
- data.tar.gz: ee0e6d336eb94aa339bf1396017c599940749826c97482f552a3b43cc83c7aad55394d739f1925b7dbd0759f3f5ac664695d87f35deb15e5ea370812b316ab24
5
2
  SHA1:
6
- metadata.gz: c94dba7594aa55c76ed2b4790ebe224c4d63c0c5
7
- data.tar.gz: 6938c9b1a965c2937762d70606998a6a9cb60a04
3
+ data.tar.gz: 9282d045f4e6fc42c754615dbcc9a95fac696ede
4
+ metadata.gz: 8579c7e08fb78e773bcbfe81d3623c83e7828987
5
+ SHA512:
6
+ data.tar.gz: 5042ceb001b324f6ff4e0651bd504e076c67dabd535cae0735fbe1037823da44c30754a1a09b720625f2593c81b976c44376558f83b7664f864814fb8139342f
7
+ metadata.gz: 30ec1b5af69268d5480d919726b4c6a154a120efa076c47e792fd6c2fbc688486eb740c7a7776da56955ebf3cf1c4284df6985dc418ccf21e31dd7679f9ef9ae
@@ -114,7 +114,8 @@ module Devise
114
114
  def self.confirmation_required?; false; end
115
115
  end
116
116
 
117
- generate_invitation_token if self.invitation_token.nil? || (!@skip_invitation && @raw_invitation_token.nil?)
117
+ yield self if block_given?
118
+ generate_invitation_token if self.invitation_token.nil? || (!@skip_invitation || @raw_invitation_token.nil?)
118
119
  self.invitation_created_at = Time.now.utc
119
120
  self.invitation_sent_at = self.invitation_created_at unless @skip_invitation
120
121
  self.invited_by = invited_by if invited_by
@@ -174,7 +175,7 @@ module Devise
174
175
  !@skip_password && super
175
176
  end
176
177
 
177
-
178
+
178
179
  # Checks if the invitation for the user is within the limit time.
179
180
  # We do this by calculating if the difference between today and the
180
181
  # invitation sent date does not exceed the invite for time configured.
@@ -7,12 +7,14 @@ module DeviseInvitable
7
7
 
8
8
  # We use to_prepare instead of after_initialize here because Devise is a Rails engine; its
9
9
  # mailer is reloaded like the rest of the user's app. Got to make sure that our mailer methods
10
- # are included each time Devise::Mailer is (re)loaded.
10
+ # are included each time Devise.mailer is (re)loaded.
11
11
  config.to_prepare do
12
- require 'devise/mailer'
13
- Devise::Mailer.send :include, DeviseInvitable::Mailer
12
+ Devise.mailer.send :include, DeviseInvitable::Mailer
13
+ unless Devise.mailer.ancestors.include?(Devise::Mailers::Helpers)
14
+ Devise.mailer.send :include, Devise::Mailers::Helpers
15
+ end
14
16
  end
15
- # extend mapping with after_initialize becuase is not reloaded
17
+ # extend mapping with after_initialize because it's not reloaded
16
18
  config.after_initialize do
17
19
  Devise::Mapping.send :include, DeviseInvitable::Mapping
18
20
  Devise::ParameterSanitizer.send :include, DeviseInvitable::ParameterSanitizer
@@ -1,3 +1,3 @@
1
1
  module DeviseInvitable
2
- VERSION = '1.3.5'
2
+ VERSION = '1.3.6'
3
3
  end
@@ -25,7 +25,7 @@ class DeviseInvitableAddTo<%= table_name.camelize %> < ActiveRecord::Migration
25
25
  t.remove_references :invited_by, :polymorphic => true
26
26
  t.remove :invitations_count, :invitation_limit, :invitation_sent_at, :invitation_accepted_at, :invitation_token, :invitation_created_at
27
27
  end
28
- change_column_null :users, :encrypted_password, false
28
+ change_column_null :<%= table_name %>, :encrypted_password, false
29
29
  <% if class_name.constantize.columns_hash['password_salt'] -%>
30
30
  change_column_null :<%= table_name %>, :password_salt,false
31
31
  <% end -%>
@@ -25,7 +25,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
25
25
  sign_out @issuer
26
26
 
27
27
  @invitee = User.where(:email => invitee_email).first
28
- assert_blank @invitee.encrypted_password, "the password should be unset"
28
+ assert @invitee.encrypted_password.blank?, "the password should be unset"
29
29
 
30
30
  # sign_up the invitee
31
31
  assert_difference('ActionMailer::Base.deliveries.size') do
@@ -42,13 +42,13 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
42
42
  @invitee.save!
43
43
  end
44
44
 
45
- assert_present @invitee.encrypted_password
45
+ assert @invitee.encrypted_password.present?
46
46
  assert_not_nil @invitee.invitation_accepted_at
47
47
  assert_nil @invitee.invitation_token
48
- assert_present @invitee.invited_by_id
49
- assert_present @invitee.invited_by_type
48
+ assert @invitee.invited_by_id.present?
49
+ assert @invitee.invited_by_type.present?
50
50
  assert !@invitee.confirmed?
51
- assert_present @invitee.confirmation_token
51
+ assert @invitee.confirmation_token.present?
52
52
  end
53
53
 
54
54
  test "not invitable resources can register" do
@@ -58,7 +58,7 @@ class DeviseInvitable::RegistrationsControllerTest < ActionController::TestCase
58
58
  post :create, :admin => {:email => invitee_email, :password => "1password"}
59
59
 
60
60
  @invitee = Admin.where(:email => invitee_email).first
61
- assert_present @invitee.encrypted_password
61
+ assert @invitee.encrypted_password.present?
62
62
  end
63
63
 
64
64
  test "missing params on a create should not cause an error" do
@@ -17,18 +17,18 @@ class GeneratorsTest < ActiveSupport::TestCase
17
17
 
18
18
  test "rails g devise_invitable:install" do
19
19
  @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable:install -p`
20
- assert @output.match(%r{(inject|insert).+ config/initializers/devise\.rb\n})
21
- assert @output.match(%r|create.+ config/locales/devise_invitable\.en\.yml\n|)
20
+ assert @output.match(%r{(inject|insert).* config/initializers/devise\.rb\n})
21
+ assert @output.match(%r|create.* config/locales/devise_invitable\.en\.yml\n|)
22
22
  end
23
23
 
24
24
  test "rails g devise_invitable Octopussy" do
25
25
  @output = `cd #{RAILS_APP_PATH} && rails g devise_invitable Octopussy -p`
26
- assert @output.match(%r{(inject|insert).+ app/models/octopussy\.rb\n})
27
- assert @output.match(%r|invoke.+ #{DEVISE_ORM}\n|)
26
+ assert @output.match(%r{(inject|insert).* app/models/octopussy\.rb\n})
27
+ assert @output.match(%r|invoke.* #{DEVISE_ORM}\n|)
28
28
  if DEVISE_ORM == :active_record
29
- assert @output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
29
+ assert @output.match(%r|create.* db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
30
30
  elsif DEVISE_ORM == :mongoid
31
- assert !@output.match(%r|create.+ db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
31
+ assert !@output.match(%r|create.* db/migrate/\d{14}_devise_invitable_add_to_octopussies\.rb\n|)
32
32
  end
33
33
  end
34
34
  end
@@ -80,7 +80,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
80
80
  end
81
81
  assert_equal user_invitation_path, current_path
82
82
  assert page.has_css?('#error_explanation li', :text => /Password .*doesn\'t match/)
83
- assert_blank user.encrypted_password
83
+ assert user.encrypted_password.blank?
84
84
  end
85
85
 
86
86
  test 'not authenticated user with valid data should be able to change his password' do
@@ -99,7 +99,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
99
99
  end
100
100
  assert_equal user_invitation_path, current_path
101
101
  assert page.has_css?('#error_explanation')
102
- assert_blank user.encrypted_password
102
+ assert user.encrypted_password.blank?
103
103
 
104
104
  set_password :visit => false
105
105
  assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
@@ -1,9 +1,9 @@
1
- class ActionController::IntegrationTest
1
+ class ActionDispatch::IntegrationTest
2
2
 
3
3
  def warden
4
4
  request.env['warden']
5
5
  end
6
-
6
+
7
7
  def create_full_user
8
8
  @user ||= begin
9
9
  user = User.create!(
@@ -28,14 +28,40 @@ class InvitableTest < ActiveSupport::TestCase
28
28
  test 'should regenerate invitation token each time' do
29
29
  user = new_user
30
30
  user.invite!
31
- token = user.invitation_token
31
+
32
32
  assert_not_nil user.invitation_token
33
+ assert_not_nil user.raw_invitation_token
33
34
  assert_not_nil user.invitation_created_at
35
+
34
36
  3.times do
35
37
  user = User.find(user.id)
36
- user.invite!
37
- assert_not_equal token, user.invitation_token
38
- token = user.invitation_token
38
+
39
+ assert_not_same user.invitation_token, lambda {
40
+ user.invite!
41
+ user.invitation_token
42
+ }.call
43
+ assert_not_nil user.raw_invitation_token
44
+ end
45
+ end
46
+
47
+ test 'should regenerate invitation token each time even if "skip_invitation" was true' do
48
+ user = new_user
49
+ user.skip_invitation = true
50
+ user.invite!
51
+
52
+ assert_not_nil user.invitation_token
53
+ assert_not_nil user.invitation_created_at
54
+
55
+ 3.times do
56
+ user = User.find(user.id)
57
+ user.skip_invitation = true
58
+
59
+ assert_not_same user.invitation_token, lambda {
60
+ user.invite!
61
+ user.invitation_token
62
+ }.call
63
+ assert_not_nil user.invitation_token
64
+ assert_not_nil user.raw_invitation_token
39
65
  end
40
66
  end
41
67
 
@@ -157,21 +183,21 @@ class InvitableTest < ActiveSupport::TestCase
157
183
 
158
184
  test 'should clear invitation token and set invitation_accepted_at while accepting the password' do
159
185
  user = User.invite!(:email => "valid@email.com")
160
- assert_present user.invitation_token
186
+ assert user.invitation_token.present?
161
187
  assert_nil user.invitation_accepted_at
162
188
  user.accept_invitation!
163
189
  user.reload
164
190
  assert_nil user.invitation_token
165
- assert_present user.invitation_accepted_at
191
+ assert user.invitation_accepted_at.present?
166
192
  end
167
193
 
168
194
  test 'should not clear invitation token or set accepted_at if record is invalid' do
169
195
  user = User.invite!(:email => "valid@email.com")
170
- assert_present user.invitation_token
196
+ assert user.invitation_token.present?
171
197
  assert_nil user.invitation_accepted_at
172
198
  User.accept_invitation!(:invitation_token => user.invitation_token, :password => '123456789', :password_confirmation => '987654321')
173
199
  user.reload
174
- assert_present user.invitation_token
200
+ assert user.invitation_token.present?
175
201
  assert_nil user.invitation_accepted_at
176
202
  end
177
203
 
@@ -182,8 +208,8 @@ class InvitableTest < ActiveSupport::TestCase
182
208
  user.reset_password_sent_at = Time.now.utc
183
209
  user.save
184
210
 
185
- assert_present user.reset_password_token
186
- assert_present user.invitation_token
211
+ assert user.reset_password_token.present?
212
+ assert user.invitation_token.present?
187
213
  User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
188
214
  assert_nil user.reload.reset_password_token
189
215
  assert_nil user.reload.invitation_token
@@ -197,11 +223,11 @@ class InvitableTest < ActiveSupport::TestCase
197
223
  user.reset_password_sent_at = Time.now.utc
198
224
  user.save
199
225
 
200
- assert_present user.reset_password_token
201
- assert_present user.invitation_token
226
+ assert user.reset_password_token.present?
227
+ assert user.invitation_token.present?
202
228
  User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '12345678')
203
- assert_present user.reload.reset_password_token
204
- assert_present user.reload.invitation_token
229
+ assert user.reload.reset_password_token.present?
230
+ assert user.reload.invitation_token.present?
205
231
  assert user.invited_to_sign_up?
206
232
  end
207
233
 
@@ -212,7 +238,7 @@ class InvitableTest < ActiveSupport::TestCase
212
238
  user.reset_password_sent_at = Time.now.utc
213
239
  user.save
214
240
 
215
- assert_present user.reset_password_token
241
+ assert user.reset_password_token.present?
216
242
  assert_nil user.invitation_token
217
243
  User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
218
244
  assert_nil user.reload.invitation_token
@@ -231,7 +257,7 @@ class InvitableTest < ActiveSupport::TestCase
231
257
  test 'should return a record with invitation token and no errors to send invitation by email' do
232
258
  invited_user = User.invite!(:email => "valid@email.com")
233
259
  assert invited_user.errors.blank?
234
- assert_present invited_user.invitation_token
260
+ assert invited_user.invitation_token.present?
235
261
  assert_equal 'valid@email.com', invited_user.email
236
262
  assert invited_user.persisted?
237
263
  end
@@ -472,7 +498,18 @@ class InvitableTest < ActiveSupport::TestCase
472
498
  assert_no_difference('ActionMailer::Base.deliveries.size') do
473
499
  user.invite!
474
500
  end
475
- assert_present user.invitation_created_at
501
+ assert user.invitation_created_at.present?
502
+ assert_nil user.invitation_sent_at
503
+ end
504
+
505
+ test 'user.invite! should not send an invitation if we want to skip the invitation with block' do
506
+ user = new_user
507
+ assert_no_difference('ActionMailer::Base.deliveries.size') do
508
+ user.invite! do |u|
509
+ u.skip_invitation = true
510
+ end
511
+ end
512
+ assert user.invitation_created_at.present?
476
513
  assert_nil user.invitation_sent_at
477
514
  end
478
515
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_invitable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Cambra
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-05-09 00:00:00 Z
12
+ date: 2014-07-21 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler