Commit 9866b3f2 authored by Sean McGivern's avatar Sean McGivern

Merge branch '329559-decouple-acceptance-of-invites-from-predicate-method' into 'master'

Decouple acceptance of invites from predicate method

See merge request gitlab-org/gitlab!61379
parents 2393b1eb 5d24ea16
......@@ -6,7 +6,8 @@ module AcceptsPendingInvitations
def accept_pending_invitations
return unless resource.active_for_authentication?
if resource.accept_pending_invitations!.any?
if resource.pending_invitations.load.any?
resource.accept_pending_invitations!
clear_stored_location_for_resource
after_pending_invitations_hook
end
......
......@@ -22,7 +22,7 @@ class Email < ApplicationRecord
self.reconfirmable = false # currently email can't be changed, no need to reconfirm
delegate :username, :can?, to: :user
delegate :username, :can?, :pending_invitations, :accept_pending_invitations!, to: :user
def email=(value)
write_attribute(:email, value.downcase.strip)
......@@ -32,10 +32,6 @@ class Email < ApplicationRecord
self.errors.add(:email, 'has already been taken') if User.exists?(email: self.email)
end
def accept_pending_invitations!
user.accept_pending_invitations!
end
def validate_email_format
self.errors.add(:email, I18n.t(:invalid, scope: 'valid_email.validations.email')) unless ValidateEmail.valid?(self.email)
end
......
......@@ -4,13 +4,25 @@ require 'spec_helper'
RSpec.describe 'AdditionalEmailToExistingAccount' do
describe 'add secondary email associated with account' do
let(:user) { create(:user) }
let_it_be(:user) { create(:user) }
let_it_be(:email) { create(:email, user: user) }
it 'verifies confirmation of additional email' do
before do
sign_in(user)
end
it 'verifies confirmation of additional email' do
visit email_confirmation_path(confirmation_token: email.confirmation_token)
expect(page).to have_content 'Your email address has been successfully confirmed.'
end
it 'accepts any pending invites for an email confirmation' do
member = create(:group_member, :invited, invite_email: email.email)
email = create(:email, user: user)
visit email_confirmation_path(confirmation_token: email.confirmation_token)
expect(member.reload.user).to eq(user)
expect(page).to have_content 'Your email address has been successfully confirmed.'
end
end
......
......@@ -44,12 +44,11 @@ RSpec.describe Email do
end
end
describe 'delegation' do
let(:user) { create(:user) }
it 'delegates to :user' do
expect(build(:email, user: user).username).to eq user.username
end
describe 'delegations' do
it { is_expected.to delegate_method(:can?).to(:user) }
it { is_expected.to delegate_method(:username).to(:user) }
it { is_expected.to delegate_method(:pending_invitations).to(:user) }
it { is_expected.to delegate_method(:accept_pending_invitations!).to(:user) }
end
describe 'Devise emails' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment