devise_invitable 1.3.4 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +4 -0
- data/README.rdoc +20 -2
- data/app/controllers/devise/invitations_controller.rb +15 -13
- data/app/views/devise/mailer/invitation_instructions.html.erb +4 -5
- data/config/locales/en.yml +6 -0
- data/lib/devise_invitable/model.rb +10 -9
- data/lib/devise_invitable/rails.rb +6 -4
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/generators/active_record/devise_invitable_generator.rb +1 -1
- data/lib/generators/active_record/templates/migration.rb +4 -0
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +1 -1
- data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +1 -1
- data/test/functional/registrations_controller_test.rb +6 -6
- data/test/generators_test.rb +6 -6
- data/test/integration/invitation_test.rb +2 -2
- data/test/integration_tests_helper.rb +3 -3
- data/test/models/invitable_test.rb +54 -17
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49059f27df2618f9c0491fd1b7578b33619f2ef5
|
|
4
|
+
data.tar.gz: da0b1ff3962cba2784b8c082c013fb483ee0517e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56e5cc31bd011a67887ea3338ee66682dc398008f4a18f094fec9084b0635efc8684d5251aca72a9d7daecf228ea06aeec84bca49a8dd24bd3750c063f7b2e56
|
|
7
|
+
data.tar.gz: 162bc6c70f81f0b65ca73233a5ebb5ac53895b5e6c57f4085d522807592feccb29ce93c113e1d67d974fa95ebf026054d137a6a5c01c1af3913bf84df14d2f7a
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
= 1.4.0
|
|
2
|
+
Override active_for_authentication? and inactive_message instead of valid_password?
|
|
3
|
+
To use counter_cache, invited_by_counter_cache must be set, no more checking of invitations_count to enable counter cache
|
|
4
|
+
|
|
1
5
|
= 1.3.0
|
|
2
6
|
Now devise 3.1 compatible, @token must be used instead of @resource.invitation_token in mail views
|
|
3
7
|
|
data/README.rdoc
CHANGED
|
@@ -16,7 +16,7 @@ Install DeviseInvitable gem, it will also install dependencies (such as devise a
|
|
|
16
16
|
Add DeviseInvitable to your Gemfile (and Devise if you weren't using them):
|
|
17
17
|
|
|
18
18
|
gem 'devise', '>= 2.0.0'
|
|
19
|
-
gem 'devise_invitable', '~> 1.
|
|
19
|
+
gem 'devise_invitable', '~> 1.3.4'
|
|
20
20
|
|
|
21
21
|
=== Automatic installation
|
|
22
22
|
|
|
@@ -233,11 +233,16 @@ To send an invitation to a user, use the <tt>invite!</tt> class method. <tt>:ema
|
|
|
233
233
|
|
|
234
234
|
If you want to create the invitation but not send it, you can set <tt>skip_invitation</tt> to true.
|
|
235
235
|
|
|
236
|
-
User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
|
|
236
|
+
user = User.invite!(:email => "new_user@example.com", :name => "John Doe") do |u|
|
|
237
237
|
u.skip_invitation = true
|
|
238
238
|
end
|
|
239
239
|
# => the record will be created, but the invitation email will not be sent
|
|
240
240
|
|
|
241
|
+
When generating the <tt>accept_user_invitation_url</tt> yourself, you must use the <tt>raw_invitation_token</tt>
|
|
242
|
+
the value is temporarily available when you invite a user and will be decrypted when recieved.
|
|
243
|
+
|
|
244
|
+
accept_user_invitation_url(:invitation_token => user.raw_invitation_token)
|
|
245
|
+
|
|
241
246
|
When skip_invitation is used, you must also then set the invitation_sent_at field when the user is sent their
|
|
242
247
|
token. Failure to do so will yield "Invalid invitation token" errors when the user attempts to accept the invite.
|
|
243
248
|
You can set it like so:
|
|
@@ -252,6 +257,11 @@ You can add :skip_invitation to attributes hash if skip_invitation is added to a
|
|
|
252
257
|
Skip_invitation skips sending the email, but sets invitation_token, so invited_to_sign_up? on the
|
|
253
258
|
resulting user returns true.
|
|
254
259
|
|
|
260
|
+
**Warning**
|
|
261
|
+
|
|
262
|
+
When using skip_invitation you must send the email with the user object instance that generated the tokens, as
|
|
263
|
+
user.raw_invitation_token is available only to the instance and is not persisted in the database.
|
|
264
|
+
|
|
255
265
|
You can send an invitation to an existing user if your workflow creates them separately:
|
|
256
266
|
|
|
257
267
|
user = User.find(42)
|
|
@@ -261,6 +271,8 @@ You can also set <tt>invited_by</tt> when using the <tt>invite!</tt> class metho
|
|
|
261
271
|
|
|
262
272
|
User.invite!({:email => "new_user@example.com"}, current_user) # current_user will be set as invited_by
|
|
263
273
|
|
|
274
|
+
|
|
275
|
+
|
|
264
276
|
=== Accept an invitation
|
|
265
277
|
|
|
266
278
|
To accept an invitation with a token use the <tt>accept_invitation!</tt> class method. <tt>:invitation_token</tt> must be present in the parameters hash. You can also include other attributes in the hash.
|
|
@@ -369,6 +381,12 @@ Take a look at the generated locale file (in <tt>config/locales/devise_invitable
|
|
|
369
381
|
|
|
370
382
|
DeviseInvitable supports ActiveRecord and Mongoid, like Devise.
|
|
371
383
|
|
|
384
|
+
== Wiki
|
|
385
|
+
|
|
386
|
+
It's possible to find additional information about DeviseInvitable on the Wiki:
|
|
387
|
+
|
|
388
|
+
https://github.com/scambra/devise_invitable/wiki
|
|
389
|
+
|
|
372
390
|
== Testing
|
|
373
391
|
|
|
374
392
|
To test DeviseInvitable for the ActiveRecord ORM with RVM, Ruby 1.9.2, and Rubygems 1.8.17:
|
|
@@ -18,7 +18,9 @@ class Devise::InvitationsController < DeviseController
|
|
|
18
18
|
|
|
19
19
|
if resource.errors.empty?
|
|
20
20
|
yield resource if block_given?
|
|
21
|
-
|
|
21
|
+
if is_flashing_format? && self.resource.invitation_sent_at
|
|
22
|
+
set_flash_message :notice, :send_instructions, :email => self.resource.email
|
|
23
|
+
end
|
|
22
24
|
respond_with resource, :location => after_invite_path_for(resource)
|
|
23
25
|
else
|
|
24
26
|
respond_with_navigational(resource) { render :new }
|
|
@@ -37,47 +39,47 @@ class Devise::InvitationsController < DeviseController
|
|
|
37
39
|
|
|
38
40
|
if resource.errors.empty?
|
|
39
41
|
yield resource if block_given?
|
|
40
|
-
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
|
41
|
-
set_flash_message :notice, flash_message
|
|
42
|
+
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
|
|
43
|
+
set_flash_message :notice, flash_message if is_flashing_format?
|
|
42
44
|
sign_in(resource_name, resource)
|
|
43
45
|
respond_with resource, :location => after_accept_path_for(resource)
|
|
44
46
|
else
|
|
45
47
|
respond_with_navigational(resource){ render :edit }
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
|
-
|
|
50
|
+
|
|
49
51
|
# GET /resource/invitation/remove?invitation_token=abcdef
|
|
50
52
|
def destroy
|
|
51
53
|
resource.destroy
|
|
52
|
-
set_flash_message :notice, :invitation_removed
|
|
54
|
+
set_flash_message :notice, :invitation_removed if is_flashing_format?
|
|
53
55
|
redirect_to after_sign_out_path_for(resource_name)
|
|
54
56
|
end
|
|
55
57
|
|
|
56
58
|
protected
|
|
57
59
|
|
|
58
|
-
def invite_resource
|
|
59
|
-
resource_class.invite!(invite_params, current_inviter)
|
|
60
|
+
def invite_resource(&block)
|
|
61
|
+
resource_class.invite!(invite_params, current_inviter, &block)
|
|
60
62
|
end
|
|
61
|
-
|
|
63
|
+
|
|
62
64
|
def accept_resource
|
|
63
65
|
resource_class.accept_invitation!(update_resource_params)
|
|
64
66
|
end
|
|
65
67
|
|
|
66
68
|
def current_inviter
|
|
67
|
-
|
|
69
|
+
authenticate_inviter!
|
|
68
70
|
end
|
|
69
71
|
|
|
70
72
|
def has_invitations_left?
|
|
71
73
|
unless current_inviter.nil? || current_inviter.has_invitations_left?
|
|
72
74
|
self.resource = resource_class.new
|
|
73
|
-
set_flash_message :alert, :no_invitations_remaining
|
|
75
|
+
set_flash_message :alert, :no_invitations_remaining if is_flashing_format?
|
|
74
76
|
respond_with_navigational(resource) { render :new }
|
|
75
77
|
end
|
|
76
78
|
end
|
|
77
|
-
|
|
79
|
+
|
|
78
80
|
def resource_from_invitation_token
|
|
79
81
|
unless params[:invitation_token] && self.resource = resource_class.find_by_invitation_token(params[:invitation_token], true)
|
|
80
|
-
set_flash_message(:alert, :invitation_token_invalid)
|
|
82
|
+
set_flash_message(:alert, :invitation_token_invalid) if is_flashing_format?
|
|
81
83
|
redirect_to after_sign_out_path_for(resource_name)
|
|
82
84
|
end
|
|
83
85
|
end
|
|
@@ -89,6 +91,6 @@ class Devise::InvitationsController < DeviseController
|
|
|
89
91
|
def update_resource_params
|
|
90
92
|
devise_parameter_sanitizer.sanitize(:accept_invitation)
|
|
91
93
|
end
|
|
92
|
-
|
|
94
|
+
|
|
93
95
|
end
|
|
94
96
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
<p
|
|
1
|
+
<p><%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p>
|
|
2
2
|
|
|
3
|
-
<p
|
|
3
|
+
<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p>
|
|
4
4
|
|
|
5
|
-
<p><%= link_to
|
|
5
|
+
<p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, :invitation_token => @token) %></p>
|
|
6
6
|
|
|
7
|
-
<p
|
|
8
|
-
Your account won't be created until you access the link above and set your password.</p>
|
|
7
|
+
<p><%= t("devise.mailer.invitation_instructions.ignore").html_safe %></p>
|
data/config/locales/en.yml
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
en:
|
|
2
2
|
devise:
|
|
3
|
+
failure:
|
|
4
|
+
invited: 'You have a pending invitation, accept it to finish creating your account.'
|
|
3
5
|
invitations:
|
|
4
6
|
send_instructions: 'An invitation email has been sent to %{email}.'
|
|
5
7
|
invitation_token_invalid: 'The invitation token provided is not valid!'
|
|
@@ -15,3 +17,7 @@ en:
|
|
|
15
17
|
mailer:
|
|
16
18
|
invitation_instructions:
|
|
17
19
|
subject: 'Invitation instructions'
|
|
20
|
+
hello: 'Hello %{email}'
|
|
21
|
+
someone_invited_you: 'Someone has invited you to %{url}, you can accept it through the link below.'
|
|
22
|
+
accept: 'Accept invitation'
|
|
23
|
+
ignore: "If you don't want to accept the invitation, please ignore this email.<br />Your account won't be created until you access the link above and set your password."
|
|
@@ -34,12 +34,8 @@ module Devise
|
|
|
34
34
|
else
|
|
35
35
|
{:polymorphic => true}
|
|
36
36
|
end
|
|
37
|
-
if defined?(ActiveRecord) && self < ActiveRecord::Base
|
|
37
|
+
if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && self < ActiveRecord::Base
|
|
38
38
|
counter_cache = Devise.invited_by_counter_cache
|
|
39
|
-
if !counter_cache && Devise.invited_by_class_name
|
|
40
|
-
klass = Devise.invited_by_class_name.constantize
|
|
41
|
-
counter_cache = klass.table_exists? && klass.columns_hash['invitations_count'].try('name')
|
|
42
|
-
end
|
|
43
39
|
belongs_to_options.merge! :counter_cache => counter_cache if counter_cache
|
|
44
40
|
end
|
|
45
41
|
belongs_to :invited_by, belongs_to_options
|
|
@@ -49,7 +45,7 @@ module Devise
|
|
|
49
45
|
|
|
50
46
|
attr_writer :skip_password
|
|
51
47
|
|
|
52
|
-
scope :
|
|
48
|
+
scope :no_active_invitation, lambda { where(:invitation_token => nil) }
|
|
53
49
|
if defined?(Mongoid) && defined?(Mongoid::Document) && self < Mongoid::Document
|
|
54
50
|
scope :invitation_not_accepted, lambda { where(:invitation_accepted_at => nil, :invitation_token.ne => nil) }
|
|
55
51
|
scope :invitation_accepted, lambda { where(:invitation_accepted_at.ne => nil) }
|
|
@@ -114,7 +110,8 @@ module Devise
|
|
|
114
110
|
def self.confirmation_required?; false; end
|
|
115
111
|
end
|
|
116
112
|
|
|
117
|
-
|
|
113
|
+
yield self if block_given?
|
|
114
|
+
generate_invitation_token if self.invitation_token.nil? || (!@skip_invitation || @raw_invitation_token.nil?)
|
|
118
115
|
self.invitation_created_at = Time.now.utc
|
|
119
116
|
self.invitation_sent_at = self.invitation_created_at unless @skip_invitation
|
|
120
117
|
self.invited_by = invited_by if invited_by
|
|
@@ -137,10 +134,14 @@ module Devise
|
|
|
137
134
|
end
|
|
138
135
|
|
|
139
136
|
# Only verify password when is not invited
|
|
140
|
-
def
|
|
137
|
+
def active_for_authentication?
|
|
141
138
|
super unless invited_to_sign_up?
|
|
142
139
|
end
|
|
143
140
|
|
|
141
|
+
def inactive_message
|
|
142
|
+
invited_to_sign_up? ? :invited : super
|
|
143
|
+
end
|
|
144
|
+
|
|
144
145
|
def after_password_reset
|
|
145
146
|
super
|
|
146
147
|
accept_invitation! if invited_to_sign_up?
|
|
@@ -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
|
|
10
|
+
# are included each time Devise.mailer is (re)loaded.
|
|
11
11
|
config.to_prepare do
|
|
12
|
-
|
|
13
|
-
Devise
|
|
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
|
|
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
|
|
@@ -6,7 +6,7 @@ module ActiveRecord
|
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
|
7
7
|
|
|
8
8
|
def copy_devise_migration
|
|
9
|
-
migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}"
|
|
9
|
+
migration_template "migration.rb", "db/migrate/devise_invitable_add_to_#{table_name}.rb"
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
@@ -25,5 +25,9 @@ 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 :<%= table_name %>, :encrypted_password, false
|
|
29
|
+
<% if class_name.constantize.columns_hash['password_salt'] -%>
|
|
30
|
+
change_column_null :<%= table_name %>, :password_salt,false
|
|
31
|
+
<% end -%>
|
|
28
32
|
end
|
|
29
33
|
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
|
-
|
|
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
|
-
|
|
45
|
+
assert @invitee.encrypted_password.present?
|
|
46
46
|
assert_not_nil @invitee.invitation_accepted_at
|
|
47
47
|
assert_nil @invitee.invitation_token
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
assert @invitee.invited_by_id.present?
|
|
49
|
+
assert @invitee.invited_by_type.present?
|
|
50
50
|
assert !@invitee.confirmed?
|
|
51
|
-
|
|
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
|
-
|
|
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
|
data/test/generators_test.rb
CHANGED
|
@@ -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)
|
|
21
|
-
assert @output.match(%r|create
|
|
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)
|
|
27
|
-
assert @output.match(%r|invoke
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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!(
|
|
@@ -24,7 +24,7 @@ class ActionController::IntegrationTest
|
|
|
24
24
|
visit send("new_#{resource_name}_session_path")
|
|
25
25
|
fill_in "#{resource_name}_email", :with => user.email
|
|
26
26
|
fill_in "#{resource_name}_password", :with => user.password
|
|
27
|
-
click_button '
|
|
27
|
+
click_button 'Log in'
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
# Fix assert_redirect_to in integration sessions because they don't take into
|
|
@@ -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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
186
|
-
|
|
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
|
-
|
|
201
|
-
|
|
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
|
-
|
|
204
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: devise_invitable
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sergio Cambra
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|