debian-mirror-gitlab/spec/services/emails/destroy_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
791 B
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Emails::DestroyService do
2017-09-10 17:25:29 +05:30
let!(:user) { create(:user) }
let!(:email) { create(:email, user: user) }
2018-03-17 18:26:18 +05:30
subject(:service) { described_class.new(user, user: user) }
2017-09-10 17:25:29 +05:30
describe '#execute' do
it 'removes an email' do
2020-04-22 19:07:51 +05:30
response = service.execute(email)
expect(user.emails).not_to include(email)
expect(response).to be true
2017-09-10 17:25:29 +05:30
end
2021-12-11 22:18:48 +05:30
context 'when it corresponds to the user primary email' do
let(:email) { user.emails.find_by!(email: user.email) }
it 'does not remove the email and raises an exception' do
expect { service.execute(email) }.to raise_error(StandardError, 'Cannot delete primary email')
expect(user.emails).to include(email)
end
end
2017-09-10 17:25:29 +05:30
end
end