diff --git a/app/models/invitation.rb b/app/models/invitation.rb index 348fb37b68..9de9d0465e 100644 --- a/app/models/invitation.rb +++ b/app/models/invitation.rb @@ -24,7 +24,7 @@ class Invitation < ApplicationRecord # Build new user on information in this invitation. def make_user(params = {}) - self.user = account.users.build_with_fields params.reverse_merge(email: email, invitation: self) + self.user = account.users.build_with_fields params.reverse_merge(email: email) end def accepted? diff --git a/app/models/user/invitations.rb b/app/models/user/invitations.rb index 53a51611ee..fb7904fd2e 100644 --- a/app/models/user/invitations.rb +++ b/app/models/user/invitations.rb @@ -4,10 +4,7 @@ module User::Invitations included do after_commit :accept_invitation, :on => :create - attr_accessor :invitation - - # TODO: refactor to make this work removing above attribute. - # has_one :invitation + has_one :invitation # rubocop:disable Rails/HasManyOrHasOneDependent -- before_destroy :destroy_invitation handles it before_destroy :destroy_invitation end @@ -18,7 +15,8 @@ def accept_invitation def destroy_invitation if account # some tests fail because of account being nil - invit = account.invitations.find_by_email(email) || account.invitations.find_by_user_id(id) # || eventually invitation + invitations = account.invitations + invit = invitations.find_by(email: email) || invitations.find_by(user_id: id) # halt the destruction if the destruction of invitation failed throw :abort if invit && invit.destroy == false end diff --git a/test/integration/developer_portal/accounts/invitee_signups_controller_test.rb b/test/integration/developer_portal/accounts/invitee_signups_controller_test.rb index 03c6a4fe71..5121e07258 100644 --- a/test/integration/developer_portal/accounts/invitee_signups_controller_test.rb +++ b/test/integration/developer_portal/accounts/invitee_signups_controller_test.rb @@ -46,6 +46,7 @@ def setup assert_equal I18n.t('developer_portal.accounts.invitee_signups.create.success'), flash[:notice] assert_redirected_to login_path + assert invitation.reload.accepted? end test 'create pushes webhook' do diff --git a/test/integration/provider/invitee_signups_controller_integration_test.rb b/test/integration/provider/invitee_signups_controller_integration_test.rb index e3943dea13..cba9d25ded 100644 --- a/test/integration/provider/invitee_signups_controller_integration_test.rb +++ b/test/integration/provider/invitee_signups_controller_integration_test.rb @@ -26,6 +26,7 @@ def setup assert_equal I18n.t('provider.invitee_signups.create.success'), flash[:success] assert_redirected_to provider_login_path + assert invitation.reload.accepted? end test 'do not set unpermitted attributes' do diff --git a/test/unit/authentication/strategy/oauth2_test.rb b/test/unit/authentication/strategy/oauth2_test.rb index 2815f444f3..d2ae3342ef 100644 --- a/test/unit/authentication/strategy/oauth2_test.rb +++ b/test/unit/authentication/strategy/oauth2_test.rb @@ -334,6 +334,7 @@ class SsoSignupTest < ActiveSupport::TestCase assert_equal result.username, user_data[:username] assert result.active? assert authentication_strategy.error_message.blank? + assert invitation.reload.accepted? end end end diff --git a/test/unit/authentication/strategy/provider_oauth2_test.rb b/test/unit/authentication/strategy/provider_oauth2_test.rb index 59e9bf422e..276db8e3fc 100644 --- a/test/unit/authentication/strategy/provider_oauth2_test.rb +++ b/test/unit/authentication/strategy/provider_oauth2_test.rb @@ -258,6 +258,7 @@ class SsoSignupTest < ActiveSupport::TestCase assert_equal result.username, user_data[:username] assert result.active? assert authentication_strategy.error_message.blank? + assert invitation.reload.accepted? end end end