summaryrefslogtreecommitdiff
path: root/spec/models/project_services/emails_on_push_service_spec.rb
blob: ffe241aa88050233598081991be869ce3f248a69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

require 'spec_helper'

describe EmailsOnPushService do
  describe 'Validations' do
    context 'when service is active' do
      before do
        subject.active = true
      end

      it { is_expected.to validate_presence_of(:recipients) }
    end

    context 'when service is inactive' do
      before do
        subject.active = false
      end

      it { is_expected.not_to validate_presence_of(:recipients) }
    end
  end

  context 'project emails' do
    let(:push_data) { { object_kind: 'push' } }
    let(:project)   { create(:project, :repository) }
    let(:service)   { create(:emails_on_push_service, project: project) }

    it 'does not send emails when disabled' do
      expect(project).to receive(:emails_disabled?).and_return(true)
      expect(EmailsOnPushWorker).not_to receive(:perform_async)

      service.execute(push_data)
    end

    it 'does send emails when enabled' do
      expect(project).to receive(:emails_disabled?).and_return(false)
      expect(EmailsOnPushWorker).to receive(:perform_async)

      service.execute(push_data)
    end
  end
end