diff options
Diffstat (limited to 'spec/models/environment_spec.rb')
-rw-r--r-- | spec/models/environment_spec.rb | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index 9cf82c707f1..33142922670 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -166,6 +166,37 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ end end + describe '#long_stopping?' do + subject { environment1.long_stopping? } + + let(:long_ago) { (described_class::LONG_STOP + 1.day).ago } + let(:not_long_ago) { (described_class::LONG_STOP - 1.day).ago } + + context 'when a stopping environment has not been updated recently' do + let!(:environment1) { create(:environment, state: 'stopping', project: project, updated_at: long_ago) } + + it { is_expected.to eq(true) } + end + + context 'when a stopping environment has been updated recently' do + let!(:environment1) { create(:environment, state: 'stopping', project: project, updated_at: not_long_ago) } + + it { is_expected.to eq(false) } + end + + context 'when a non stopping environment has not been updated recently' do + let!(:environment1) { create(:environment, project: project, updated_at: long_ago) } + + it { is_expected.to eq(false) } + end + + context 'when a non stopping environment has been updated recently' do + let!(:environment1) { create(:environment, project: project, updated_at: not_long_ago) } + + it { is_expected.to eq(false) } + end + end + describe ".stopped_review_apps" do let_it_be(:project) { create(:project, :repository) } let_it_be(:old_stopped_review_env) { create(:environment, :with_review_app, :stopped, created_at: 31.days.ago, project: project) } @@ -406,6 +437,47 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching, feature_categ end end + describe '.long_stopping' do + subject { described_class.long_stopping } + + let_it_be(:project) { create(:project) } + let(:environment) { create(:environment, project: project) } + let(:long) { (described_class::LONG_STOP + 1.day).ago } + let(:short) { (described_class::LONG_STOP - 1.day).ago } + + context 'when a stopping environment has not been updated recently' do + before do + environment.update!(state: :stopping, updated_at: long) + end + + it { is_expected.to eq([environment]) } + end + + context 'when a stopping environment has been updated recently' do + before do + environment.update!(state: :stopping, updated_at: short) + end + + it { is_expected.to be_empty } + end + + context 'when a non stopping environment has not been updated recently' do + before do + environment.update!(state: :available, updated_at: long) + end + + it { is_expected.to be_empty } + end + + context 'when a non stopping environment has been updated recently' do + before do + environment.update!(state: :available, updated_at: short) + end + + it { is_expected.to be_empty } + end + end + describe '.pluck_names' do subject { described_class.pluck_names } |