summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/models')
-rw-r--r--spec/support/shared_examples/models/cluster_application_status_shared_examples.rb19
-rw-r--r--spec/support/shared_examples/models/cluster_application_version_shared_examples.rb2
-rw-r--r--spec/support/shared_examples/models/clusters/providers/provider_status.rb73
-rw-r--r--spec/support/shared_examples/models/concern/issuable_shared_examples.rb58
-rw-r--r--spec/support/shared_examples/models/with_uploads_shared_examples.rb3
5 files changed, 151 insertions, 4 deletions
diff --git a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
index 5341aacb445..a6653f89377 100644
--- a/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
+++ b/spec/support/shared_examples/models/cluster_application_status_shared_examples.rb
@@ -11,6 +11,20 @@ shared_examples 'cluster application status specs' do |application_name|
end
end
+ describe '#status_states' do
+ let(:cluster) { create(:cluster, :provided_by_gcp) }
+
+ subject { described_class.new(cluster: cluster) }
+
+ it 'returns a hash of state values' do
+ expect(subject.status_states).to include(:installed)
+ end
+
+ it 'returns an integer for installed state value' do
+ expect(subject.status_states[:installed]).to eq(3)
+ end
+ end
+
describe '.available' do
subject { described_class.available }
@@ -61,7 +75,7 @@ shared_examples 'cluster application status specs' do |application_name|
subject.reload
- expect(subject.version).to eq(subject.class.const_get(:VERSION))
+ expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
end
context 'application is updating' do
@@ -90,13 +104,14 @@ shared_examples 'cluster application status specs' do |application_name|
subject.reload
- expect(subject.version).to eq(subject.class.const_get(:VERSION))
+ expect(subject.version).to eq(subject.class.const_get(:VERSION, false))
end
end
end
describe '#make_errored' do
subject { create(application_name, :installing) }
+
let(:reason) { 'some errors' }
it 'is errored' do
diff --git a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
index 181b102e685..ba02da41b53 100644
--- a/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
+++ b/spec/support/shared_examples/models/cluster_application_version_shared_examples.rb
@@ -12,7 +12,7 @@ shared_examples 'cluster application version specs' do |application_name|
context 'version is the same as VERSION' do
let(:application) { build(application_name) }
- let(:version) { application.class.const_get(:VERSION) }
+ let(:version) { application.class.const_get(:VERSION, false) }
it { is_expected.to be_falsey }
end
diff --git a/spec/support/shared_examples/models/clusters/providers/provider_status.rb b/spec/support/shared_examples/models/clusters/providers/provider_status.rb
new file mode 100644
index 00000000000..63cb9a56f5b
--- /dev/null
+++ b/spec/support/shared_examples/models/clusters/providers/provider_status.rb
@@ -0,0 +1,73 @@
+# frozen_string_literal: true
+
+shared_examples 'provider status' do |factory|
+ describe 'state_machine' do
+ context 'when any => [:created]' do
+ let(:provider) { build(factory, :creating) }
+
+ it 'nullifies API credentials' do
+ expect(provider).to receive(:nullify_credentials).and_call_original
+ provider.make_created
+
+ expect(provider).to be_created
+ end
+ end
+
+ context 'when any => [:creating]' do
+ let(:provider) { build(factory) }
+ let(:operation_id) { 'operation-xxx' }
+
+ it 'calls #assign_operation_id on the provider' do
+ expect(provider).to receive(:assign_operation_id).with(operation_id).and_call_original
+
+ provider.make_creating(operation_id)
+ end
+ end
+
+ context 'when any => [:errored]' do
+ let(:provider) { build(factory, :creating) }
+ let(:status_reason) { 'err msg' }
+
+ it 'calls #nullify_credentials on the provider' do
+ expect(provider).to receive(:nullify_credentials).and_call_original
+
+ provider.make_errored(status_reason)
+ end
+
+ it 'sets a status reason' do
+ provider.make_errored(status_reason)
+
+ expect(provider.status_reason).to eq('err msg')
+ end
+
+ context 'when status_reason is nil' do
+ let(:provider) { build(factory, :errored) }
+
+ it 'does not set status_reason' do
+ provider.make_errored(nil)
+
+ expect(provider.status_reason).not_to be_nil
+ end
+ end
+ end
+ end
+
+ describe '#on_creation?' do
+ using RSpec::Parameterized::TableSyntax
+
+ subject { provider.on_creation? }
+
+ where(:status, :result) do
+ :scheduled | true
+ :creating | true
+ :created | false
+ :errored | false
+ end
+
+ with_them do
+ let(:provider) { build(factory, status) }
+
+ it { is_expected.to eq result }
+ end
+ end
+end
diff --git a/spec/support/shared_examples/models/concern/issuable_shared_examples.rb b/spec/support/shared_examples/models/concern/issuable_shared_examples.rb
index 9604555c57d..4ebb5e35e0e 100644
--- a/spec/support/shared_examples/models/concern/issuable_shared_examples.rb
+++ b/spec/support/shared_examples/models/concern/issuable_shared_examples.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
shared_examples_for 'matches_cross_reference_regex? fails fast' do
it 'fails fast for long strings' do
# took well under 1 second in CI https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/3267#note_172823
@@ -6,3 +8,59 @@ shared_examples_for 'matches_cross_reference_regex? fails fast' do
end.not_to raise_error
end
end
+
+shared_examples_for 'validates description length with custom validation' do
+ let(:issuable) { build(:issue, description: 'x' * (::Issuable::DESCRIPTION_LENGTH_MAX + 1)) }
+ let(:context) { :update }
+
+ subject { issuable.validate(context) }
+
+ context 'when Issuable is a new record' do
+ it 'validates the maximum description length' do
+ subject
+ expect(issuable.errors[:description]).to eq(["is too long (maximum is #{::Issuable::DESCRIPTION_LENGTH_MAX} characters)"])
+ end
+
+ context 'on create' do
+ let(:context) { :create }
+
+ it 'does not validate the maximum description length' do
+ allow(issuable).to receive(:description_max_length_for_new_records_is_valid).and_call_original
+
+ subject
+
+ expect(issuable).not_to have_received(:description_max_length_for_new_records_is_valid)
+ end
+ end
+ end
+
+ context 'when Issuable is an existing record' do
+ before do
+ allow(issuable).to receive(:expire_etag_cache) # to skip the expire_etag_cache callback
+
+ issuable.save!(validate: false)
+ end
+
+ it 'does not validate the maximum description length' do
+ subject
+ expect(issuable.errors).not_to have_key(:description)
+ end
+ end
+end
+
+shared_examples_for 'truncates the description to its allowed maximum length on import' do
+ before do
+ allow(issuable).to receive(:importing?).and_return(true)
+ end
+
+ let(:issuable) { build(:issue, description: 'x' * (::Issuable::DESCRIPTION_LENGTH_MAX + 1)) }
+
+ subject { issuable.validate(:create) }
+
+ it 'truncates the description to its allowed maximum length' do
+ subject
+
+ expect(issuable.description).to eq('x' * ::Issuable::DESCRIPTION_LENGTH_MAX)
+ expect(issuable.errors[:description]).to be_empty
+ end
+end
diff --git a/spec/support/shared_examples/models/with_uploads_shared_examples.rb b/spec/support/shared_examples/models/with_uploads_shared_examples.rb
index eb1ade03017..822836c771e 100644
--- a/spec/support/shared_examples/models/with_uploads_shared_examples.rb
+++ b/spec/support/shared_examples/models/with_uploads_shared_examples.rb
@@ -41,7 +41,8 @@ shared_examples_for 'model with uploads' do |supports_fileuploads|
end
it 'deletes remote files' do
- expect_any_instance_of(Uploads::Fog).to receive(:delete_keys).with(uploads.map(&:path))
+ expected_array = array_including(*uploads.map(&:path))
+ expect_any_instance_of(Uploads::Fog).to receive(:delete_keys).with(expected_array)
model_object.destroy
end