diff options
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 34dfc7a1fce..fd89a3a2e22 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -479,7 +479,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do end context 'when matching action is defined' do - let(:build) { create(:ci_build) } + let(:build) { create(:ci_build, :success) } let!(:deployment) do create(:deployment, :success, @@ -549,7 +549,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do context 'when matching action is defined' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build_a) { create(:ci_build, pipeline: pipeline) } + let(:build_a) { create(:ci_build, :success, pipeline: pipeline) } before do create(:deployment, :success, @@ -586,6 +586,12 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do expect(action).to eq(close_action) expect(action.user).to eq(user) end + + it 'environment is not stopped' do + subject + + expect(environment).not_to be_stopped + end end context 'if action did finish' do @@ -632,8 +638,8 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do context 'when there are more then one stop action for the environment' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:build_a) { create(:ci_build, pipeline: pipeline) } - let(:build_b) { create(:ci_build, pipeline: pipeline) } + let(:build_a) { create(:ci_build, :success, pipeline: pipeline) } + let(:build_b) { create(:ci_build, :success, pipeline: pipeline) } let!(:close_actions) do [ @@ -666,9 +672,9 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do expect(actions.pluck(:user)).to match_array(close_actions.pluck(:user)) end - context 'when there are failed deployment jobs' do + context 'when there are failed builds' do before do - create(:ci_build, pipeline: pipeline, name: 'close_app_c') + create(:ci_build, :failed, pipeline: pipeline, name: 'close_app_c') create(:deployment, :failed, environment: environment, @@ -676,11 +682,11 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do on_stop: 'close_app_c') end - it 'returns only stop actions from successful deployment jobs' do + it 'returns only stop actions from successful builds' do actions = subject expect(actions).to match_array(close_actions) - expect(actions.count).to eq(environment.successful_deployments.count) + expect(actions.count).to eq(pipeline.latest_successful_builds.count) end end end @@ -697,8 +703,8 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do context 'when there are multiple deployments with actions' do let(:pipeline) { create(:ci_pipeline, project: project) } - let(:ci_build_a) { create(:ci_build, project: project, pipeline: pipeline) } - let(:ci_build_b) { create(:ci_build, project: project, pipeline: pipeline) } + let(:ci_build_a) { create(:ci_build, :success, project: project, pipeline: pipeline) } + let(:ci_build_b) { create(:ci_build, :success, project: project, pipeline: pipeline) } let!(:ci_build_c) { create(:ci_build, :manual, project: project, pipeline: pipeline, name: 'close_app_a') } let!(:ci_build_d) { create(:ci_build, :manual, project: project, pipeline: pipeline, name: 'close_app_b') } @@ -714,7 +720,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do before do # Create failed deployment without stop_action. - build = create(:ci_build, project: project, pipeline: pipeline) + build = create(:ci_build, :failed, project: project, pipeline: pipeline) create(:deployment, :failed, project: project, environment: environment, deployable: build) end @@ -736,10 +742,10 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do context 'when there are deployments for multiple pipelines' do let(:pipeline_a) { create(:ci_pipeline, project: project) } let(:pipeline_b) { create(:ci_pipeline, project: project) } - let(:ci_build_a) { create(:ci_build, project: project, pipeline: pipeline_a) } - let(:ci_build_b) { create(:ci_build, project: project, pipeline: pipeline_b) } - let(:ci_build_c) { create(:ci_build, project: project, pipeline: pipeline_a) } - let(:ci_build_d) { create(:ci_build, project: project, pipeline: pipeline_a) } + let(:ci_build_a) { create(:ci_build, :success, project: project, pipeline: pipeline_a) } + let(:ci_build_b) { create(:ci_build, :failed, project: project, pipeline: pipeline_b) } + let(:ci_build_c) { create(:ci_build, :success, project: project, pipeline: pipeline_a) } + let(:ci_build_d) { create(:ci_build, :failed, project: project, pipeline: pipeline_a) } # Successful deployments for pipeline_a let!(:deployment_a) { create(:deployment, :success, project: project, environment: environment, deployable: ci_build_a) } @@ -756,6 +762,16 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do it 'returns the successful deployment jobs for the last deployment pipeline' do expect(subject.pluck(:id)).to contain_exactly(deployment_a.id, deployment_b.id) end + + context 'when the feature flag is disabled' do + before do + stub_feature_flags(batch_load_environment_last_deployment_group: false) + end + + it 'returns the successful deployment jobs for the last deployment pipeline' do + expect(subject.pluck(:id)).to contain_exactly(deployment_a.id, deployment_b.id) + end + end end end @@ -1730,17 +1746,17 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do let!(:environment3) { create(:environment, project: project, state: 'stopped') } it 'returns the environments count grouped by state' do - expect(project.environments.count_by_state).to eq({ stopped: 2, available: 1 }) + expect(project.environments.count_by_state).to eq({ stopped: 2, available: 1, stopping: 0 }) end it 'returns the environments count grouped by state with zero value' do environment2.update!(state: 'stopped') - expect(project.environments.count_by_state).to eq({ stopped: 3, available: 0 }) + expect(project.environments.count_by_state).to eq({ stopped: 3, available: 0, stopping: 0 }) end end it 'returns zero state counts when environments are empty' do - expect(project.environments.count_by_state).to eq({ stopped: 0, available: 0 }) + expect(project.environments.count_by_state).to eq({ stopped: 0, available: 0, stopping: 0 }) end end |