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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/models')
-rw-r--r--spec/support/shared_examples/models/chat_service_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/models/chat_slash_commands_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/models/clusters/elastic_stack_client_shared.rb82
-rw-r--r--spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb4
-rw-r--r--spec/support/shared_examples/models/concerns/cron_schedulable_shared_examples.rb23
-rw-r--r--spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/models/cycle_analytics_stage_shared_examples.rb13
-rw-r--r--spec/support/shared_examples/models/packages/debian/architecture_shared_examples.rb18
-rw-r--r--spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb55
-rw-r--r--spec/support/shared_examples/models/packages/debian/component_shared_examples.rb12
-rw-r--r--spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb45
-rw-r--r--spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/models/wiki_shared_examples.rb42
13 files changed, 216 insertions, 88 deletions
diff --git a/spec/support/shared_examples/models/chat_service_shared_examples.rb b/spec/support/shared_examples/models/chat_service_shared_examples.rb
index 59e249bb865..4a47aad0957 100644
--- a/spec/support/shared_examples/models/chat_service_shared_examples.rb
+++ b/spec/support/shared_examples/models/chat_service_shared_examples.rb
@@ -163,7 +163,7 @@ RSpec.shared_examples "chat service" do |service_name|
context "with issue events" do
let(:opts) { { title: "Awesome issue", description: "please fix" } }
let(:sample_data) do
- service = Issues::CreateService.new(project, user, opts)
+ service = Issues::CreateService.new(project: project, current_user: user, params: opts)
issue = service.execute
service.hook_data(issue, "open")
end
@@ -182,7 +182,7 @@ RSpec.shared_examples "chat service" do |service_name|
end
let(:sample_data) do
- service = MergeRequests::CreateService.new(project, user, opts)
+ service = MergeRequests::CreateService.new(project: project, current_user: user, params: opts)
merge_request = service.execute
service.hook_data(merge_request, "open")
end
diff --git a/spec/support/shared_examples/models/chat_slash_commands_shared_examples.rb b/spec/support/shared_examples/models/chat_slash_commands_shared_examples.rb
index 0ee24dd93d7..49729afce61 100644
--- a/spec/support/shared_examples/models/chat_slash_commands_shared_examples.rb
+++ b/spec/support/shared_examples/models/chat_slash_commands_shared_examples.rb
@@ -81,7 +81,7 @@ RSpec.shared_examples 'chat slash commands service' do
end
context 'when the user is authenticated' do
- let!(:chat_name) { create(:chat_name, service: subject) }
+ let!(:chat_name) { create(:chat_name, integration: subject) }
let(:params) { { token: 'token', team_id: chat_name.team_id, user_id: chat_name.chat_id } }
subject do
diff --git a/spec/support/shared_examples/models/clusters/elastic_stack_client_shared.rb b/spec/support/shared_examples/models/clusters/elastic_stack_client_shared.rb
new file mode 100644
index 00000000000..d3ce916cd64
--- /dev/null
+++ b/spec/support/shared_examples/models/clusters/elastic_stack_client_shared.rb
@@ -0,0 +1,82 @@
+# frozen_string_literal: true
+
+# Input
+# - factory: [:clusters_applications_elastic_stack, :clusters_integrations_elastic_stack]
+RSpec.shared_examples 'cluster-based #elasticsearch_client' do |factory|
+ describe '#elasticsearch_client' do
+ context 'cluster is nil' do
+ subject { build(factory, cluster: nil) }
+
+ it 'returns nil' do
+ expect(subject.cluster).to be_nil
+ expect(subject.elasticsearch_client).to be_nil
+ end
+ end
+
+ context "cluster doesn't have kubeclient" do
+ let(:cluster) { create(:cluster) }
+
+ subject { create(factory, cluster: cluster) }
+
+ it 'returns nil' do
+ expect(subject.elasticsearch_client).to be_nil
+ end
+ end
+
+ context 'cluster has kubeclient' do
+ let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
+ let(:kubernetes_url) { subject.cluster.platform_kubernetes.api_url }
+ let(:kube_client) { subject.cluster.kubeclient.core_client }
+
+ subject { create(factory, cluster: cluster) }
+
+ before do
+ subject.cluster.platform_kubernetes.namespace = 'a-namespace'
+ stub_kubeclient_discover(cluster.platform_kubernetes.api_url)
+
+ create(:cluster_kubernetes_namespace,
+ cluster: cluster,
+ cluster_project: cluster.cluster_project,
+ project: cluster.cluster_project.project)
+ end
+
+ it 'creates proxy elasticsearch_client' do
+ expect(subject.elasticsearch_client).to be_instance_of(Elasticsearch::Transport::Client)
+ end
+
+ it 'copies proxy_url, options and headers from kube client to elasticsearch_client' do
+ expect(Elasticsearch::Client)
+ .to(receive(:new))
+ .with(url: a_valid_url)
+ .and_call_original
+
+ client = subject.elasticsearch_client
+ faraday_connection = client.transport.connections.first.connection
+
+ expect(faraday_connection.headers["Authorization"]).to eq(kube_client.headers[:Authorization])
+ expect(faraday_connection.ssl.cert_store).to be_instance_of(OpenSSL::X509::Store)
+ expect(faraday_connection.ssl.verify).to eq(1)
+ expect(faraday_connection.options.timeout).to be_nil
+ end
+
+ context 'when cluster is not reachable' do
+ before do
+ allow(kube_client).to receive(:proxy_url).and_raise(Kubeclient::HttpError.new(401, 'Unauthorized', nil))
+ end
+
+ it 'returns nil' do
+ expect(subject.elasticsearch_client).to be_nil
+ end
+ end
+
+ context 'when timeout is provided' do
+ it 'sets timeout in elasticsearch_client' do
+ client = subject.elasticsearch_client(timeout: 123)
+ faraday_connection = client.transport.connections.first.connection
+
+ expect(faraday_connection.options.timeout).to eq(123)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
index 3db5d7a8d7d..ec9756007f1 100644
--- a/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
+++ b/spec/support/shared_examples/models/concerns/bulk_insert_safe_shared_examples.rb
@@ -30,10 +30,6 @@ RSpec.shared_examples 'a BulkInsertSafe model' do |klass|
expect { target_class.set_callback(name) {} }.not_to raise_error
end
end
-
- it 'does not raise an error when the call is triggered by belongs_to' do
- expect { target_class.belongs_to(:other_record) }.not_to raise_error
- end
end
describe '.bulk_insert!' do
diff --git a/spec/support/shared_examples/models/concerns/cron_schedulable_shared_examples.rb b/spec/support/shared_examples/models/concerns/cron_schedulable_shared_examples.rb
new file mode 100644
index 00000000000..47a02a8fa49
--- /dev/null
+++ b/spec/support/shared_examples/models/concerns/cron_schedulable_shared_examples.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'handles set_next_run_at' do
+ context 'when schedule runs every minute' do
+ it "updates next_run_at to the worker's execution time" do
+ travel_to(1.day.ago) do
+ expect(schedule.next_run_at).to eq(cron_worker_next_run_at)
+ end
+ end
+ end
+
+ context 'when there are two different schedules in the same time zones' do
+ it 'sets the sames next_run_at' do
+ expect(schedule_1.next_run_at).to eq(schedule_2.next_run_at)
+ end
+ end
+
+ context 'when cron is updated for existing schedules' do
+ it 'updates next_run_at automatically' do
+ expect { schedule.update!(cron: new_cron) }.to change { schedule.next_run_at }
+ end
+ end
+end
diff --git a/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb b/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb
index 819cf6018fe..3f1588c46b3 100644
--- a/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb
+++ b/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb
@@ -36,7 +36,7 @@ RSpec.shared_examples 'handles repository moves' do
container.set_repository_read_only!
expect(subject).not_to be_valid
- expect(subject.errors[error_key].first).to match(/is read only/)
+ expect(subject.errors[error_key].first).to match(/is read-only/)
end
end
end
diff --git a/spec/support/shared_examples/models/cycle_analytics_stage_shared_examples.rb b/spec/support/shared_examples/models/cycle_analytics_stage_shared_examples.rb
index 17948d648cb..d23f95b2e9e 100644
--- a/spec/support/shared_examples/models/cycle_analytics_stage_shared_examples.rb
+++ b/spec/support/shared_examples/models/cycle_analytics_stage_shared_examples.rb
@@ -58,6 +58,19 @@ RSpec.shared_examples 'value stream analytics stage' do
it { expect(stage).not_to be_valid }
end
+
+ # rubocop: disable Rails/SaveBang
+ describe '.by_value_stream' do
+ it 'finds stages by value stream' do
+ stage1 = create(factory)
+ create(factory) # other stage with different value stream
+
+ result = described_class.by_value_stream(stage1.value_stream)
+
+ expect(result).to eq([stage1])
+ end
+ end
+ # rubocop: enable Rails/SaveBang
end
describe '#subject_class' do
diff --git a/spec/support/shared_examples/models/packages/debian/architecture_shared_examples.rb b/spec/support/shared_examples/models/packages/debian/architecture_shared_examples.rb
index fbb94b4f5c1..33a04059491 100644
--- a/spec/support/shared_examples/models/packages/debian/architecture_shared_examples.rb
+++ b/spec/support/shared_examples/models/packages/debian/architecture_shared_examples.rb
@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.shared_examples 'Debian Distribution Architecture' do |factory, container, can_freeze|
- let_it_be_with_refind(:architecture) { create(factory) } # rubocop:disable Rails/SaveBang
- let_it_be(:architecture_same_distribution, freeze: can_freeze) { create(factory, distribution: architecture.distribution) }
+ let_it_be_with_refind(:architecture) { create(factory, name: 'name1') }
+ let_it_be(:architecture_same_distribution, freeze: can_freeze) { create(factory, distribution: architecture.distribution, name: 'name2') }
let_it_be(:architecture_same_name, freeze: can_freeze) { create(factory, name: architecture.name) }
subject { architecture }
@@ -30,20 +30,22 @@ RSpec.shared_examples 'Debian Distribution Architecture' do |factory, container,
end
describe 'scopes' do
+ describe '.ordered_by_name' do
+ subject { described_class.with_distribution(architecture.distribution).ordered_by_name }
+
+ it { expect(subject).to match_array([architecture, architecture_same_distribution]) }
+ end
+
describe '.with_distribution' do
subject { described_class.with_distribution(architecture.distribution) }
- it 'does not return other distributions' do
- expect(subject.to_a).to match_array([architecture, architecture_same_distribution])
- end
+ it { expect(subject).to match_array([architecture, architecture_same_distribution]) }
end
describe '.with_name' do
subject { described_class.with_name(architecture.name) }
- it 'does not return other distributions' do
- expect(subject.to_a).to match_array([architecture, architecture_same_name])
- end
+ it { expect(subject).to match_array([architecture, architecture_same_name]) }
end
end
end
diff --git a/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb b/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb
index 02ced49ee94..e6b16d5881d 100644
--- a/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb
+++ b/spec/support/shared_examples/models/packages/debian/component_file_shared_example.rb
@@ -114,11 +114,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_container(container2) }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_container)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_other_container)
end
end
@@ -126,11 +122,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_codename_or_suite(distribution2.codename) }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_container)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_other_container)
end
end
@@ -138,11 +130,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_component_name(component1_2.name) }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_component)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_other_component)
end
end
@@ -150,14 +138,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_file_type(:source) }
it do
- # let_it_be_with_refind triggers a query
- component_file_with_file_type_source
-
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_with_file_type_source)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_with_file_type_source)
end
end
@@ -165,11 +146,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_architecture_name(architecture1_2.name) }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_architecture)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_other_architecture)
end
end
@@ -177,11 +154,7 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_compression_type(:xz) }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_compression_type)
- end
-
- expect(queries.count).to eq(1)
+ expect(subject.to_a).to contain_exactly(component_file_other_compression_type)
end
end
@@ -189,11 +162,19 @@ RSpec.shared_examples 'Debian Component File' do |container_type, can_freeze|
subject { described_class.with_file_sha256('other_sha256') }
it do
- queries = ActiveRecord::QueryRecorder.new do
- expect(subject.to_a).to contain_exactly(component_file_other_file_sha256)
- end
+ expect(subject.to_a).to contain_exactly(component_file_other_file_sha256)
+ end
+ end
+
+ describe '.created_before' do
+ let_it_be(:component_file1) { create("debian_#{container_type}_component_file", component: component1_1, architecture: architecture1_1, created_at: 4.hours.ago) }
+ let_it_be(:component_file2) { create("debian_#{container_type}_component_file", component: component1_1, architecture: architecture1_1, created_at: 3.hours.ago) }
+ let_it_be(:component_file3) { create("debian_#{container_type}_component_file", component: component1_1, architecture: architecture1_1, created_at: 1.hour.ago) }
- expect(queries.count).to eq(1)
+ subject { described_class.created_before(2.hours.ago) }
+
+ it do
+ expect(subject.to_a).to contain_exactly(component_file1, component_file2)
end
end
end
diff --git a/spec/support/shared_examples/models/packages/debian/component_shared_examples.rb b/spec/support/shared_examples/models/packages/debian/component_shared_examples.rb
index 23e76d32fb0..635d45f40e5 100644
--- a/spec/support/shared_examples/models/packages/debian/component_shared_examples.rb
+++ b/spec/support/shared_examples/models/packages/debian/component_shared_examples.rb
@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.shared_examples 'Debian Distribution Component' do |factory, container, can_freeze|
- let_it_be_with_refind(:component) { create(factory) } # rubocop:disable Rails/SaveBang
- let_it_be(:component_same_distribution, freeze: can_freeze) { create(factory, distribution: component.distribution) }
+ let_it_be_with_refind(:component) { create(factory, name: 'name1') }
+ let_it_be(:component_same_distribution, freeze: can_freeze) { create(factory, distribution: component.distribution, name: 'name2') }
let_it_be(:component_same_name, freeze: can_freeze) { create(factory, name: component.name) }
subject { component }
@@ -32,6 +32,14 @@ RSpec.shared_examples 'Debian Distribution Component' do |factory, container, ca
end
describe 'scopes' do
+ describe '.ordered_by_name' do
+ subject { described_class.with_distribution(component.distribution).ordered_by_name }
+
+ it 'sorts by name' do
+ expect(subject.to_a).to eq([component, component_same_distribution])
+ end
+ end
+
describe '.with_distribution' do
subject { described_class.with_distribution(component.distribution) }
diff --git a/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb b/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb
index 9eacacf725f..8693d6868e9 100644
--- a/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb
+++ b/spec/support/shared_examples/models/packages/debian/distribution_shared_examples.rb
@@ -19,11 +19,6 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
it { is_expected.to have_many(:components).class_name("Packages::Debian::#{container.capitalize}Component").inverse_of(:distribution) }
it { is_expected.to have_many(:architectures).class_name("Packages::Debian::#{container.capitalize}Architecture").inverse_of(:distribution) }
-
- if container != :group
- it { is_expected.to have_many(:publications).class_name('Packages::Debian::Publication').inverse_of(:distribution).with_foreign_key(:distribution_id) }
- it { is_expected.to have_many(:packages).class_name('Packages::Package').through(:publications) }
- end
end
describe 'validations' do
@@ -228,4 +223,44 @@ RSpec.shared_examples 'Debian Distribution' do |factory, container, can_freeze|
end
end
end
+
+ if container == :project
+ describe 'project distribution specifics' do
+ describe 'relationships' do
+ it { is_expected.to have_many(:publications).class_name('Packages::Debian::Publication').inverse_of(:distribution).with_foreign_key(:distribution_id) }
+ it { is_expected.to have_many(:packages).class_name('Packages::Package').through(:publications) }
+ it { is_expected.to have_many(:package_files).class_name('Packages::PackageFile').through(:packages) }
+ end
+ end
+ else
+ describe 'group distribution specifics' do
+ let_it_be(:public_project) { create(:project, :public, group: distribution_with_suite.container)}
+ let_it_be(:public_distribution_with_same_codename) { create(:debian_project_distribution, container: public_project, codename: distribution_with_suite.codename) }
+ let_it_be(:public_package_with_same_codename) { create(:debian_package, project: public_project, published_in: public_distribution_with_same_codename)}
+ let_it_be(:public_distribution_with_same_suite) { create(:debian_project_distribution, container: public_project, suite: distribution_with_suite.suite) }
+ let_it_be(:public_package_with_same_suite) { create(:debian_package, project: public_project, published_in: public_distribution_with_same_suite)}
+
+ let_it_be(:private_project) { create(:project, :private, group: distribution_with_suite.container)}
+ let_it_be(:private_distribution_with_same_codename) { create(:debian_project_distribution, container: private_project, codename: distribution_with_suite.codename) }
+ let_it_be(:private_package_with_same_codename) { create(:debian_package, project: private_project, published_in: private_distribution_with_same_codename)}
+ let_it_be(:private_distribution_with_same_suite) { create(:debian_project_distribution, container: private_project, suite: distribution_with_suite.suite) }
+ let_it_be(:private_package_with_same_suite) { create(:debian_package, project: private_project, published_in: private_distribution_with_same_codename)}
+
+ describe '#packages' do
+ subject { distribution_with_suite.packages }
+
+ it 'returns only public packages with same codename' do
+ expect(subject.to_a).to contain_exactly(public_package_with_same_codename)
+ end
+ end
+
+ describe '#package_files' do
+ subject { distribution_with_suite.package_files }
+
+ it 'returns only files from public packages with same codename' do
+ expect(subject.to_a).to contain_exactly(*public_package_with_same_codename.package_files)
+ end
+ end
+ end
+ end
end
diff --git a/spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb b/spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb
index 71a76121d38..09b7d1be704 100644
--- a/spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb
+++ b/spec/support/shared_examples/models/slack_mattermost_notifications_shared_examples.rb
@@ -201,7 +201,7 @@ RSpec.shared_examples 'slack or mattermost notifications' do |service_name|
context 'deployment events' do
let_it_be(:deployment) { create(:deployment) }
- let(:data) { Gitlab::DataBuilder::Deployment.build(deployment) }
+ let(:data) { Gitlab::DataBuilder::Deployment.build(deployment, Time.current) }
it_behaves_like 'calls the service API with the event message', /Deploy to (.*?) created/
end
diff --git a/spec/support/shared_examples/models/wiki_shared_examples.rb b/spec/support/shared_examples/models/wiki_shared_examples.rb
index 6b243aef3e6..2498bf35a09 100644
--- a/spec/support/shared_examples/models/wiki_shared_examples.rb
+++ b/spec/support/shared_examples/models/wiki_shared_examples.rb
@@ -469,34 +469,30 @@ RSpec.shared_examples 'wiki model' do
end
describe '#delete_page' do
- shared_examples 'delete_page operations' do
- let(:page) { create(:wiki_page, wiki: wiki) }
+ let(:page) { create(:wiki_page, wiki: wiki) }
- it 'deletes the page' do
- subject.delete_page(page)
+ it 'deletes the page' do
+ subject.delete_page(page)
- expect(subject.list_pages.count).to eq(0)
- end
+ expect(subject.list_pages.count).to eq(0)
+ end
- it 'sets the correct commit email' do
- subject.delete_page(page)
+ it 'sets the correct commit email' do
+ subject.delete_page(page)
- expect(user.commit_email).not_to eq(user.email)
- expect(commit.author_email).to eq(user.commit_email)
- expect(commit.committer_email).to eq(user.commit_email)
- end
+ expect(user.commit_email).not_to eq(user.email)
+ expect(commit.author_email).to eq(user.commit_email)
+ expect(commit.committer_email).to eq(user.commit_email)
+ end
- it 'runs after_wiki_activity callbacks' do
- page
+ it 'runs after_wiki_activity callbacks' do
+ page
- expect(subject).to receive(:after_wiki_activity)
+ expect(subject).to receive(:after_wiki_activity)
- subject.delete_page(page)
- end
+ subject.delete_page(page)
end
- it_behaves_like 'delete_page operations'
-
context 'when an error is raised' do
it 'logs the error and returns false' do
page = build(:wiki_page, wiki: wiki)
@@ -509,14 +505,6 @@ RSpec.shared_examples 'wiki model' do
expect(subject.delete_page(page)).to be_falsey
end
end
-
- context 'when feature flag :gitaly_replace_wiki_delete_page is disabled' do
- before do
- stub_feature_flags(gitaly_replace_wiki_delete_page: false)
- end
-
- it_behaves_like 'delete_page operations'
- end
end
describe '#ensure_repository' do