forked from scambra/devise_invitable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that
invitation_token/invitation_accepted_at
fields are roll…
…ed back on a failed `accept`, otherwise the user is left in a state where `invitation_accepted?` is true, but the user is invalid. This issue was exposed by the recent fix that set `@accepting_invitation` to false after finishing accepting.
- Loading branch information
1 parent
bb25eec
commit 81dd92b
Showing
2 changed files
with
19 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,9 +228,13 @@ def setup | |
assert user.invitation_token.present? | ||
assert_nil user.invitation_accepted_at | ||
user.accept_invitation! | ||
assert_nil user.invitation_token | ||
assert user.invitation_accepted_at.present? | ||
assert user.invitation_accepted? | ||
user.reload | ||
assert_nil user.invitation_token | ||
assert user.invitation_accepted_at.present? | ||
assert user.invitation_accepted? | ||
end | ||
|
||
test 'should not clear invitation token or set accepted_at if record is invalid' do | ||
|
@@ -245,6 +249,17 @@ def setup | |
assert_nil user.invitation_accepted_at | ||
end | ||
|
||
test 'should not require reloading if invalid' do | ||
user = User.invite!(:email => "[email protected]") | ||
assert user.invitation_token.present? | ||
assert_nil user.invitation_accepted_at | ||
user.attributes = { :password => '123456789', :password_confirmation => '987654321' } | ||
user.accept_invitation! | ||
assert user.invitation_token.present? | ||
assert_nil user.invitation_accepted_at | ||
assert !user.invitation_accepted? | ||
end | ||
|
||
test 'should clear invitation token while resetting the password' do | ||
user = User.invite!(:email => "[email protected]") | ||
assert user.invited_to_sign_up? | ||
|