From 5328e3b1276d8eef15b6636a1d5b1c7a57d31ea6 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 9 Nov 2016 14:46:36 +0100 Subject: Make commit an optional arg for environments search --- spec/models/project_spec.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'spec/models') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0810d06b50f..d835eac34c2 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1646,15 +1646,18 @@ describe Project, models: true do end it 'returns environment when with_tags is set' do - expect(project.environments_for('master', project.commit, with_tags: true)).to contain_exactly(environment) + expect(project.environments_for('master', commit: project.commit, with_tags: true)) + .to contain_exactly(environment) end it 'does not return environment when no with_tags is set' do - expect(project.environments_for('master', project.commit)).to be_empty + expect(project.environments_for('master', commit: project.commit)) + .to be_empty end it 'does not return environment when commit is not part of deployment' do - expect(project.environments_for('master', project.commit('feature'))).to be_empty + expect(project.environments_for('master', commit: project.commit('feature'))) + .to be_empty end end @@ -1664,15 +1667,23 @@ describe Project, models: true do end it 'returns environment when ref is set' do - expect(project.environments_for('master', project.commit)).to contain_exactly(environment) + expect(project.environments_for('master', commit: project.commit)) + .to contain_exactly(environment) end it 'does not environment when ref is different' do - expect(project.environments_for('feature', project.commit)).to be_empty + expect(project.environments_for('feature', commit: project.commit)) + .to be_empty end it 'does not return environment when commit is not part of deployment' do - expect(project.environments_for('master', project.commit('feature'))).to be_empty + expect(project.environments_for('master', commit: project.commit('feature'))) + .to be_empty + end + + it 'returns environment when commit constraint is not set' do + expect(project.environments_for('master')) + .to contain_exactly(environment) end end end -- cgit v1.2.3 From 4a7fcc2af6eba65dff48b25c81d5925311fa933d Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 9 Nov 2016 15:29:19 +0100 Subject: Stop environments for branch after branch removal --- spec/models/repository_spec.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 04b7d19d414..6d65f6ead12 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1182,7 +1182,18 @@ describe Repository, models: true do it 'flushes the visible content cache' do expect(repository).to receive(:expire_has_visible_content_cache) - repository.after_remove_branch + repository.after_remove_branch(user, 'master') + end + + context 'when there is environment with review app available for branch' do + before do + create(:environment, :with_review_app, project: project) + end + + it 'stops environment' do + expect_any_instance_of(Environment).to receive(:stop!) + repository.after_remove_branch(user, 'master') + end end end -- cgit v1.2.3 From be3d74e096f6b5cb46b5d2440c16383633f1fc06 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 11 Nov 2016 10:16:03 +0100 Subject: Do not call environments service in repository model --- spec/models/repository_spec.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'spec/models') diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 6d65f6ead12..04b7d19d414 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -1182,18 +1182,7 @@ describe Repository, models: true do it 'flushes the visible content cache' do expect(repository).to receive(:expire_has_visible_content_cache) - repository.after_remove_branch(user, 'master') - end - - context 'when there is environment with review app available for branch' do - before do - create(:environment, :with_review_app, project: project) - end - - it 'stops environment' do - expect_any_instance_of(Environment).to receive(:stop!) - repository.after_remove_branch(user, 'master') - end + repository.after_remove_branch end end -- cgit v1.2.3 From d9d69d7ba7dd660c9b3e0ab30b58891a8b760328 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Wed, 16 Nov 2016 11:26:36 +0100 Subject: Add specs for environments recently updated on branch --- spec/models/environment_spec.rb | 21 +++++++++++++++++++++ spec/models/project_spec.rb | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) (limited to 'spec/models') diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index a94e6d0165f..60bbe3fcd72 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -166,4 +166,25 @@ describe Environment, models: true do end end end + + describe 'recently_updated_on_branch?' do + subject { environment.recently_updated_on_branch?('feature') } + + context 'when last deployment to environment is the most recent one' do + before do + create(:deployment, environment: environment, ref: 'feature') + end + + it { is_expected.to be true } + end + + context 'when last deployment to environment is not the most recent' do + before do + create(:deployment, environment: environment, ref: 'feature') + create(:deployment, environment: environment, ref: 'master') + end + + it { is_expected.to be false } + end + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index d835eac34c2..dd30ec123a7 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1688,6 +1688,48 @@ describe Project, models: true do end end + describe '#environments_recently_updated_on_branch' do + let(:project) { create(:project) } + let(:environment) { create(:environment, project: project) } + + context 'when last deployment to environment is the most recent one' do + before do + create(:deployment, environment: environment, ref: 'feature') + end + + it 'finds recently updated environment' do + expect(project.environments_recently_updated_on_branch('feature')) + .to contain_exactly(environment) + end + end + + context 'when last deployment to environment is not the most recent' do + before do + create(:deployment, environment: environment, ref: 'feature') + create(:deployment, environment: environment, ref: 'master') + end + + it 'does not find environment' do + expect(project.environments_recently_updated_on_branch('feature')) + .to be_empty + end + end + + context 'when there are two environments that deploy to the same branch' do + let(:second_environment) { create(:environment, project: project) } + + before do + create(:deployment, environment: environment, ref: 'feature') + create(:deployment, environment: second_environment, ref: 'feature') + end + + it 'finds both environments' do + expect(project.environments_recently_updated_on_branch('feature')) + .to contain_exactly(environment, second_environment) + end + end + end + def enable_lfs allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) end -- cgit v1.2.3