Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ci_feature_usage_spec.rb « projects « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 674faa6e7d15825583b5a6680d2f411782422c6b (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
44
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::CiFeatureUsage, type: :model do
  describe 'associations' do
    it { is_expected.to belong_to(:project) }
  end

  it_behaves_like 'having unique enum values'

  describe 'validations' do
    it { is_expected.to validate_presence_of(:project) }
    it { is_expected.to validate_presence_of(:feature) }
  end

  describe '.insert_usage' do
    let_it_be(:project) { create(:project) }

    context 'when data is not a duplicate' do
      it 'creates a new record' do
        expect { described_class.insert_usage(project_id: project.id, default_branch: false, feature: :code_coverage) }
          .to change { described_class.count }

        expect(described_class.first).to have_attributes(
          project_id: project.id,
          default_branch: false,
          feature: 'code_coverage'
        )
      end
    end

    context 'when data is a duplicate' do
      before do
        create(:project_ci_feature_usage, project: project, default_branch: false, feature: :code_coverage)
      end

      it 'does not create a new record' do
        expect { described_class.insert_usage(project_id: project.id, default_branch: false, feature: :code_coverage) }
          .not_to change { described_class.count }
      end
    end
  end
end