Commit dd4a8df4 authored by Shinya Maeda's avatar Shinya Maeda

Validate enum uniqueness

parent a445aa0a
...@@ -15,6 +15,8 @@ describe Ci::BuildMetadata do ...@@ -15,6 +15,8 @@ describe Ci::BuildMetadata do
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let(:build_metadata) { build.metadata } let(:build_metadata) { build.metadata }
it_behaves_like 'Unique enum values'
describe '#update_timeout_state' do describe '#update_timeout_state' do
subject { build_metadata } subject { build_metadata }
......
...@@ -12,6 +12,8 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do ...@@ -12,6 +12,8 @@ describe Ci::BuildTraceChunk, :clean_gitlab_redis_shared_state do
described_class.new(build: build, chunk_index: chunk_index, data_store: data_store, raw_data: raw_data) described_class.new(build: build, chunk_index: chunk_index, data_store: data_store, raw_data: raw_data)
end end
it_behaves_like 'Unique enum values'
before do before do
stub_feature_flags(ci_enable_live_trace: true) stub_feature_flags(ci_enable_live_trace: true)
stub_artifacts_object_storage stub_artifacts_object_storage
......
...@@ -15,6 +15,8 @@ describe Ci::JobArtifact do ...@@ -15,6 +15,8 @@ describe Ci::JobArtifact do
it { is_expected.to delegate_method(:open).to(:file) } it { is_expected.to delegate_method(:open).to(:file) }
it { is_expected.to delegate_method(:exists?).to(:file) } it { is_expected.to delegate_method(:exists?).to(:file) }
it_behaves_like 'Unique enum values'
describe '.test_reports' do describe '.test_reports' do
subject { described_class.test_reports } subject { described_class.test_reports }
......
...@@ -28,6 +28,8 @@ describe Ci::Pipeline, :mailer do ...@@ -28,6 +28,8 @@ describe Ci::Pipeline, :mailer do
it { is_expected.to respond_to :short_sha } it { is_expected.to respond_to :short_sha }
it { is_expected.to delegate_method(:full_path).to(:project).with_prefix } it { is_expected.to delegate_method(:full_path).to(:project).with_prefix }
it_behaves_like 'Unique enum values'
describe 'associations' do describe 'associations' do
it 'has a bidirectional relationship with projects' do it 'has a bidirectional relationship with projects' do
expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:pipelines) expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:pipelines)
......
require 'spec_helper' require 'spec_helper'
describe Ci::Runner do describe Ci::Runner do
it_behaves_like 'Unique enum values'
describe 'validation' do describe 'validation' do
it { is_expected.to validate_presence_of(:access_level) } it { is_expected.to validate_presence_of(:access_level) }
it { is_expected.to validate_presence_of(:runner_type) } it { is_expected.to validate_presence_of(:runner_type) }
......
...@@ -3,6 +3,8 @@ require 'spec_helper' ...@@ -3,6 +3,8 @@ require 'spec_helper'
describe Ci::Stage, :models do describe Ci::Stage, :models do
let(:stage) { create(:ci_stage_entity) } let(:stage) { create(:ci_stage_entity) }
it_behaves_like 'Unique enum values'
describe 'associations' do describe 'associations' do
before do before do
create(:ci_build, stage_id: stage.id) create(:ci_build, stage_id: stage.id)
......
...@@ -6,6 +6,7 @@ describe Clusters::Applications::Ingress do ...@@ -6,6 +6,7 @@ describe Clusters::Applications::Ingress do
include_examples 'cluster application core specs', :clusters_applications_ingress include_examples 'cluster application core specs', :clusters_applications_ingress
include_examples 'cluster application status specs', :clusters_applications_ingress include_examples 'cluster application status specs', :clusters_applications_ingress
include_examples 'cluster application helm specs', :clusters_applications_ingress include_examples 'cluster application helm specs', :clusters_applications_ingress
it_behaves_like 'Unique enum values'
before do before do
allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in) allow(ClusterWaitForIngressIpAddressWorker).to receive(:perform_in)
......
...@@ -30,6 +30,8 @@ describe Clusters::Cluster do ...@@ -30,6 +30,8 @@ describe Clusters::Cluster do
it { is_expected.to respond_to :project } it { is_expected.to respond_to :project }
it_behaves_like 'Unique enum values'
describe '.enabled' do describe '.enabled' do
subject { described_class.enabled } subject { described_class.enabled }
......
...@@ -18,6 +18,8 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching ...@@ -18,6 +18,8 @@ describe Clusters::Platforms::Kubernetes, :use_clean_rails_memory_store_caching
it { is_expected.to delegate_method(:managed?).to(:cluster) } it { is_expected.to delegate_method(:managed?).to(:cluster) }
it { is_expected.to delegate_method(:kubernetes_namespace).to(:cluster) } it { is_expected.to delegate_method(:kubernetes_namespace).to(:cluster) }
it_behaves_like 'Unique enum values'
describe 'before_validation' do describe 'before_validation' do
context 'when namespace includes upper case' do context 'when namespace includes upper case' do
let(:kubernetes) { create(:cluster_platform_kubernetes, :configured, namespace: namespace) } let(:kubernetes) { create(:cluster_platform_kubernetes, :configured, namespace: namespace) }
......
...@@ -29,6 +29,8 @@ describe CommitStatus do ...@@ -29,6 +29,8 @@ describe CommitStatus do
it { is_expected.to respond_to :running? } it { is_expected.to respond_to :running? }
it { is_expected.to respond_to :pending? } it { is_expected.to respond_to :pending? }
it_behaves_like 'Unique enum values'
describe '#author' do describe '#author' do
subject { commit_status.author } subject { commit_status.author }
......
...@@ -16,6 +16,8 @@ describe Deployment do ...@@ -16,6 +16,8 @@ describe Deployment do
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }
it_behaves_like 'Unique enum values'
describe '#scheduled_actions' do describe '#scheduled_actions' do
subject { deployment.scheduled_actions } subject { deployment.scheduled_actions }
......
...@@ -8,6 +8,8 @@ RSpec.describe GpgSignature do ...@@ -8,6 +8,8 @@ RSpec.describe GpgSignature do
let(:gpg_key) { create(:gpg_key) } let(:gpg_key) { create(:gpg_key) }
let(:gpg_key_subkey) { create(:gpg_key_subkey) } let(:gpg_key_subkey) { create(:gpg_key_subkey) }
it_behaves_like 'Unique enum values'
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:gpg_key) } it { is_expected.to belong_to(:gpg_key) }
......
...@@ -11,6 +11,8 @@ describe InternalId do ...@@ -11,6 +11,8 @@ describe InternalId do
it { is_expected.to validate_presence_of(:usage) } it { is_expected.to validate_presence_of(:usage) }
end end
it_behaves_like 'Unique enum values'
describe '.generate_next' do describe '.generate_next' do
subject { described_class.generate_next(issue, scope, usage, init) } subject { described_class.generate_next(issue, scope, usage, init) }
......
...@@ -21,6 +21,8 @@ describe List do ...@@ -21,6 +21,8 @@ describe List do
end end
end end
it_behaves_like 'Unique enum values'
describe '#destroy' do describe '#destroy' do
it 'can be destroyed when list_type is set to label' do it 'can be destroyed when list_type is set to label' do
subject = create(:list) subject = create(:list)
......
...@@ -6,6 +6,8 @@ RSpec.describe NotificationSetting do ...@@ -6,6 +6,8 @@ RSpec.describe NotificationSetting do
it { is_expected.to belong_to(:source) } it { is_expected.to belong_to(:source) }
end end
it_behaves_like 'Unique enum values'
describe "Validation" do describe "Validation" do
subject { described_class.new(source_id: 1, source_type: 'Project') } subject { described_class.new(source_id: 1, source_type: 'Project') }
......
...@@ -10,6 +10,8 @@ describe ProjectAutoDevops do ...@@ -10,6 +10,8 @@ describe ProjectAutoDevops do
it { is_expected.to respond_to(:created_at) } it { is_expected.to respond_to(:created_at) }
it { is_expected.to respond_to(:updated_at) } it { is_expected.to respond_to(:updated_at) }
it_behaves_like 'Unique enum values'
describe '#has_domain?' do describe '#has_domain?' do
context 'when domain is defined' do context 'when domain is defined' do
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') } let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') }
......
...@@ -375,6 +375,8 @@ describe Project do ...@@ -375,6 +375,8 @@ describe Project do
end end
end end
it_behaves_like 'Unique enum values'
describe 'Respond to' do describe 'Respond to' do
it { is_expected.to respond_to(:url_to_repo) } it { is_expected.to respond_to(:url_to_repo) }
it { is_expected.to respond_to(:repo_exists?) } it { is_expected.to respond_to(:repo_exists?) }
......
...@@ -11,6 +11,8 @@ describe PrometheusMetric do ...@@ -11,6 +11,8 @@ describe PrometheusMetric do
it { is_expected.to validate_presence_of(:query) } it { is_expected.to validate_presence_of(:query) }
it { is_expected.to validate_presence_of(:group) } it { is_expected.to validate_presence_of(:group) }
it_behaves_like 'Unique enum values'
describe 'common metrics' do describe 'common metrics' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
......
require 'spec_helper' require 'spec_helper'
describe PushEventPayload do describe PushEventPayload do
it_behaves_like 'Unique enum values'
describe 'saving payloads' do describe 'saving payloads' do
it 'does not allow commit messages longer than 70 characters' do it 'does not allow commit messages longer than 70 characters' do
event = create(:push_event) event = create(:push_event)
......
...@@ -7,6 +7,8 @@ RSpec.describe ResourceLabelEvent, type: :model do ...@@ -7,6 +7,8 @@ RSpec.describe ResourceLabelEvent, type: :model do
let(:issue) { create(:issue) } let(:issue) { create(:issue) }
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
it_behaves_like 'Unique enum values'
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
it { is_expected.to belong_to(:issue) } it { is_expected.to belong_to(:issue) }
......
...@@ -3,6 +3,8 @@ require 'rails_helper' ...@@ -3,6 +3,8 @@ require 'rails_helper'
describe UserCallout do describe UserCallout do
let!(:callout) { create(:user_callout) } let!(:callout) { create(:user_callout) }
it_behaves_like 'Unique enum values'
describe 'relationships' do describe 'relationships' do
it { is_expected.to belong_to(:user) } it { is_expected.to belong_to(:user) }
end end
......
...@@ -159,6 +159,8 @@ describe User do ...@@ -159,6 +159,8 @@ describe User do
it { is_expected.to validate_length_of(:bio).is_at_most(255) } it { is_expected.to validate_length_of(:bio).is_at_most(255) }
it_behaves_like 'Unique enum values'
it_behaves_like 'an object with email-formated attributes', :email do it_behaves_like 'an object with email-formated attributes', :email do
subject { build(:user) } subject { build(:user) }
end end
......
# frozen_string_literal: true
shared_examples 'Unique enum values' do
described_class.defined_enums.each do |name, hash|
it "has unique values in #{name}" do
expect(hash.values).to contain_exactly(*hash.values.uniq)
end
end
end
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