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/models/environment_spec.rb')
-rw-r--r--spec/models/environment_spec.rb37
1 files changed, 18 insertions, 19 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb
index 0d53ebdefe9..dfb7de34993 100644
--- a/spec/models/environment_spec.rb
+++ b/spec/models/environment_spec.rb
@@ -62,32 +62,31 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ
expect(environment).not_to be_valid
end
end
- end
-
- describe 'preloading deployment associations' do
- let!(:environment) { create(:environment, project: project) }
- associations = [:last_deployment, :last_visible_deployment, :upcoming_deployment]
- associations.concat Deployment::FINISHED_STATUSES.map { |status| "last_#{status}_deployment".to_sym }
- associations.concat Deployment::UPCOMING_STATUSES.map { |status| "last_#{status}_deployment".to_sym }
+ context 'tier' do
+ let!(:env) { build(:environment, tier: nil) }
- context 'raises error for legacy approach' do
- let!(:error_pattern) { /Preloading instance dependent scopes is not supported/ }
+ before do
+ # Disable `before_validation: :ensure_environment_tier` since it always set tier and interfere with tests.
+ # See: https://github.com/thoughtbot/shoulda/issues/178#issuecomment-1654014
- subject { described_class.preload(association_name).find_by(id: environment) }
+ allow_any_instance_of(described_class).to receive(:ensure_environment_tier).and_return(env)
+ end
- shared_examples 'raises error' do
- it do
- expect { subject }.to raise_error(error_pattern)
+ context 'presence is checked' do
+ it 'during create and update' do
+ expect(env).to validate_presence_of(:tier).on(:create)
+ expect(env).to validate_presence_of(:tier).on(:update)
end
end
- associations.each do |association|
- context association.to_s do
- let!(:association_name) { association }
-
- include_examples "raises error"
+ context 'when FF is disabled' do
+ before do
+ stub_feature_flags(validate_environment_tier_presence: false)
end
+
+ it { expect(env).to validate_presence_of(:tier).on(:create) }
+ it { expect(env).not_to validate_presence_of(:tier).on(:update) }
end
end
end
@@ -145,7 +144,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ
environment = create(:environment, name: 'gprd')
environment.update_column(:tier, nil)
- expect { environment.stop! }.to change { environment.reload.tier }.from(nil).to('production')
+ expect { environment.save! }.to change { environment.reload.tier }.from(nil).to('production')
end
it 'does not overwrite the existing environment tier' do