builds_spec.rb 2.0 KB
Newer Older
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
require 'spec_helper'
require 'email_spec'
require 'mailers/shared/notify'

describe Notify do
  include EmailSpec::Matchers

  include_context 'gitlab email notification'

  describe 'build notification email' do
    let(:build) { create(:ci_build) }
    let(:project) { build.project }

    shared_examples 'build email' do
      it 'contains name of project' do
        is_expected.to have_body_text build.project_name
      end

      it 'contains link to project' do
        is_expected.to have_body_text namespace_project_path(project.namespace, project)
      end
    end

    shared_examples 'an email with X-GitLab headers containing build details' do
      it 'has X-GitLab-Build* headers' do
        is_expected.to have_header 'X-GitLab-Build-Id', /#{build.id}/
        is_expected.to have_header 'X-GitLab-Build-Ref', /#{build.ref}/
      end
    end

    describe 'build success' do
      subject { Notify.build_success_email(build.id, 'wow@example.com') }
      before { build.success }

      it_behaves_like 'build email'
      it_behaves_like 'an email with X-GitLab headers containing build details'
      it_behaves_like 'an email with X-GitLab headers containing project details'

      it 'has header indicating build status' do
        is_expected.to have_header 'X-GitLab-Build-Status', 'success'
      end

      it 'has the correct subject' do
        is_expected.to have_subject /Build success for/
      end
    end

    describe 'build fail' do
      subject { Notify.build_fail_email(build.id, 'wow@example.com') }
      before { build.drop }

      it_behaves_like 'build email'
      it_behaves_like 'an email with X-GitLab headers containing build details'
      it_behaves_like 'an email with X-GitLab headers containing project details'

      it 'has header indicating build status' do
        is_expected.to have_header 'X-GitLab-Build-Status', 'failed'
      end

      it 'has the correct subject' do
        is_expected.to have_subject /Build failed for/
      end
    end
  end
end