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/lib/gitlab/database')
-rw-r--r--spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb23
-rw-r--r--spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb35
2 files changed, 58 insertions, 0 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb
new file mode 100644
index 00000000000..20f3270526e
--- /dev/null
+++ b/spec/support/shared_examples/lib/gitlab/database/background_migration_job_shared_examples.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'marks background migration job records' do
+ it 'marks each job record as succeeded after processing' do
+ create(:background_migration_job, class_name: "::#{described_class.name}",
+ arguments: arguments)
+
+ expect(::Gitlab::Database::BackgroundMigrationJob).to receive(:mark_all_as_succeeded).and_call_original
+
+ expect do
+ subject.perform(*arguments)
+ end.to change { ::Gitlab::Database::BackgroundMigrationJob.succeeded.count }.from(0).to(1)
+ end
+
+ it 'returns the number of job records marked as succeeded' do
+ create(:background_migration_job, class_name: "::#{described_class.name}",
+ arguments: arguments)
+
+ jobs_updated = subject.perform(*arguments)
+
+ expect(jobs_updated).to eq(1)
+ end
+end
diff --git a/spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb
new file mode 100644
index 00000000000..ffebbabca58
--- /dev/null
+++ b/spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'a postgres model' do
+ describe '.by_identifier' do
+ it "finds the #{described_class}" do
+ expect(find(identifier)).to be_a(described_class)
+ end
+
+ it 'raises an error if not found' do
+ expect { find('public.idontexist') }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+
+ it 'raises ArgumentError if given a non-fully qualified identifier' do
+ expect { find('foo') }.to raise_error(ArgumentError, /not fully qualified/)
+ end
+ end
+
+ describe '#to_s' do
+ it 'returns the name' do
+ expect(find(identifier).to_s).to eq(name)
+ end
+ end
+
+ describe '#schema' do
+ it 'returns the schema' do
+ expect(find(identifier).schema).to eq(schema)
+ end
+ end
+
+ describe '#name' do
+ it 'returns the name' do
+ expect(find(identifier).name).to eq(name)
+ end
+ end
+end