summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/lib/gitlab/database/postgres_model_shared_examples.rb35
1 files changed, 35 insertions, 0 deletions
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