From 147f0428c00e7a10e908438a99a1558c24be41f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 22 Jan 2018 19:29:15 +0100 Subject: Add validation for auto_devops_domain --- spec/models/application_setting_spec.rb | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'spec') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index ef480e7a80a..0d7b98229a4 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -114,6 +114,46 @@ describe ApplicationSetting do it { expect(setting.repository_storages).to eq(['default']) } end + context 'auto_devops_domain setting' do + context 'when auto_devops_enabled? is true' do + before do + setting.update(auto_devops_enabled: true) + end + + context 'with a valid value' do + before do + setting.update(auto_devops_domain: 'domain.com') + end + + it 'is valid' do + expect(setting).to be_valid + end + end + + context 'with an invalid value' do + before do + setting.update(auto_devops_domain: 'definitelynotahostname') + end + + it 'is invalid' do + expect(setting).to be_invalid + end + end + end + + context 'when auto_devops_enabled? is false' do + before do + setting.update(auto_devops_enabled: false) + end + + it 'can be blank' do + setting.update(auto_devops_domain: '') + + expect(setting).to be_valid + end + end + end + context 'circuitbreaker settings' do [:circuitbreaker_failure_count_threshold, :circuitbreaker_check_interval, -- cgit v1.2.1 From 57060295031f1ad2d5f058889561a68ede04d2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 22 Jan 2018 19:31:03 +0100 Subject: Expose auto_devops_domain in admin settings view --- spec/features/admin/admin_settings_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 1218ea52227..cfc6697c79a 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -47,6 +47,16 @@ feature 'Admin updates settings' do expect(page).to have_content "Application settings saved successfully" end + scenario 'Change AutoDevOps settings' do + check 'Enabled Auto DevOps (Beta) for projects by default' + fill_in 'Auto devops domain', with: 'domain.com' + click_button 'Save' + + expect(current_application_settings.auto_devops_enabled?).to be true + expect(current_application_settings.auto_devops_domain).to eq('domain.com') + expect(page).to have_content "Application settings saved successfully" + end + scenario 'Change Slack Notifications Service template settings' do first(:link, 'Service Templates').click click_link 'Slack notifications' -- cgit v1.2.1 From 8f0a14843a630fec2eec22920ce922d5548ddec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 22 Jan 2018 19:31:35 +0100 Subject: Expose instance AutoDevOps domain in Project --- spec/models/project_spec.rb | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 987be8e8b46..dc0825aad73 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2976,18 +2976,40 @@ describe Project do subject { project.auto_devops_variables } - context 'when enabled in settings' do + context 'when enabled in instance settings' do before do stub_application_setting(auto_devops_enabled: true) end + context 'when domain is empty' do + before do + stub_application_setting(auto_devops_domain: nil) + end + + it 'variables does not include AUTO_DEVOPS_DOMAIN' do + is_expected.not_to include(domain_variable) + end + end + + context 'when domain is configured' do + before do + stub_application_setting(auto_devops_domain: 'example.com') + end + + it 'variables includes AUTO_DEVOPS_DOMAIN' do + is_expected.to include(domain_variable) + end + end + end + + context 'when explicitely enabled' do context 'when domain is empty' do before do create(:project_auto_devops, project: project, domain: nil) end - it 'variables are empty' do - is_expected.to be_empty + it 'variables does not include AUTO_DEVOPS_DOMAIN' do + is_expected.not_to include(domain_variable) end end @@ -2996,11 +3018,15 @@ describe Project do create(:project_auto_devops, project: project, domain: 'example.com') end - it "variables are not empty" do - is_expected.not_to be_empty + it 'variables includes AUTO_DEVOPS_DOMAIN' do + is_expected.to include(domain_variable) end end end + + def domain_variable + { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true } + end end describe '#latest_successful_builds_for' do -- cgit v1.2.1 From 6028f9eecfad1190e99c830b3367b7ccb9fb5c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 22 Jan 2018 20:37:02 +0100 Subject: Refactor auto_devops_domain setting specs --- spec/models/application_setting_spec.rb | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'spec') diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 0d7b98229a4..ae2d34750a7 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -120,6 +120,12 @@ describe ApplicationSetting do setting.update(auto_devops_enabled: true) end + it 'can be blank' do + setting.update(auto_devops_domain: '') + + expect(setting).to be_valid + end + context 'with a valid value' do before do setting.update(auto_devops_domain: 'domain.com') @@ -140,18 +146,6 @@ describe ApplicationSetting do end end end - - context 'when auto_devops_enabled? is false' do - before do - setting.update(auto_devops_enabled: false) - end - - it 'can be blank' do - setting.update(auto_devops_domain: '') - - expect(setting).to be_valid - end - end end context 'circuitbreaker settings' do -- cgit v1.2.1 From a31539847fd431e18053d0ea5a007dc38134b3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 1 Feb 2018 23:29:11 +0100 Subject: Add specs for .auto_devops_warning_message --- spec/helpers/auto_devops_helper_spec.rb | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'spec') diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index 5e272af6073..1fcbad5875d 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -82,4 +82,39 @@ describe AutoDevopsHelper do it { is_expected.to eq(false) } end end + + describe '.auto_devops_warning_message' do + subject { helper.auto_devops_warning_message(project) } + + context 'when the service is missing' do + before do + allow(helper).to receive(:missing_service?).and_return(true) + end + + context 'when the domain is missing' do + before do + allow(helper).to receive(:missing_domain?).and_return(true) + end + + it { is_expected.to match(/Auto Review Apps and Auto Deploy need a domain name and a .* to work correctly./) } + end + + context 'when the domain is not missing' do + before do + allow(helper).to receive(:missing_domain?).and_return(false) + end + + it { is_expected.to match(/Auto Review Apps and Auto Deploy need a .* to work correctly./) } + end + end + + context 'when the domain is missing' do + before do + allow(helper).to receive(:missing_service?).and_return(false) + allow(helper).to receive(:missing_domain?).and_return(true) + end + + it { is_expected.to eq('Auto Review Apps and Auto Deploy need a domain name to work correctly.') } + end + end end -- cgit v1.2.1 From e6487168ea1e0016a76e3e62f156990dd4412679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 1 Feb 2018 23:59:14 +0100 Subject: Read the AutoDevOps instance domain in ProjectAutoDevOps --- spec/models/project_auto_devops_spec.rb | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) (limited to 'spec') diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb index 12069575866..de90080b4b8 100644 --- a/spec/models/project_auto_devops_spec.rb +++ b/spec/models/project_auto_devops_spec.rb @@ -18,7 +18,21 @@ describe ProjectAutoDevops do context 'when domain is empty' do let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') } - it { expect(auto_devops).not_to have_domain } + context 'when there is an instance domain specified' do + before do + stub_application_setting(auto_devops_domain: 'example.com') + end + + it { expect(auto_devops).to have_domain } + end + + context 'when there is no instance domain specified' do + before do + stub_application_setting(auto_devops_domain: nil) + end + + it { expect(auto_devops).not_to have_domain } + end end end @@ -29,9 +43,32 @@ describe ProjectAutoDevops do let(:domain) { 'example.com' } it 'returns AUTO_DEVOPS_DOMAIN' do - expect(auto_devops.variables).to include( - { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }) + expect(auto_devops.variables).to include(domain_variable) end end + + context 'when domain is not defined' do + let(:domain) { nil } + + context 'when there is an instance domain specified' do + before do + stub_application_setting(auto_devops_domain: 'example.com') + end + + it { expect(auto_devops.variables).to include(domain_variable) } + end + + context 'when there is no instance domain specified' do + before do + stub_application_setting(auto_devops_domain: nil) + end + + it { expect(auto_devops.variables).not_to include(domain_variable) } + end + end + + def domain_variable + { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true } + end end end -- cgit v1.2.1 From 3443f3eb125186679afcbca2d58943e288691f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 2 Feb 2018 19:54:00 +0100 Subject: Rename AutoDevopsHelper helper methods --- spec/helpers/auto_devops_helper_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/helpers/auto_devops_helper_spec.rb b/spec/helpers/auto_devops_helper_spec.rb index 1fcbad5875d..1950c2b129b 100644 --- a/spec/helpers/auto_devops_helper_spec.rb +++ b/spec/helpers/auto_devops_helper_spec.rb @@ -88,12 +88,12 @@ describe AutoDevopsHelper do context 'when the service is missing' do before do - allow(helper).to receive(:missing_service?).and_return(true) + allow(helper).to receive(:missing_auto_devops_service?).and_return(true) end context 'when the domain is missing' do before do - allow(helper).to receive(:missing_domain?).and_return(true) + allow(helper).to receive(:missing_auto_devops_domain?).and_return(true) end it { is_expected.to match(/Auto Review Apps and Auto Deploy need a domain name and a .* to work correctly./) } @@ -101,7 +101,7 @@ describe AutoDevopsHelper do context 'when the domain is not missing' do before do - allow(helper).to receive(:missing_domain?).and_return(false) + allow(helper).to receive(:missing_auto_devops_domain?).and_return(false) end it { is_expected.to match(/Auto Review Apps and Auto Deploy need a .* to work correctly./) } @@ -110,8 +110,8 @@ describe AutoDevopsHelper do context 'when the domain is missing' do before do - allow(helper).to receive(:missing_service?).and_return(false) - allow(helper).to receive(:missing_domain?).and_return(true) + allow(helper).to receive(:missing_auto_devops_service?).and_return(false) + allow(helper).to receive(:missing_auto_devops_domain?).and_return(true) end it { is_expected.to eq('Auto Review Apps and Auto Deploy need a domain name to work correctly.') } -- cgit v1.2.1 From 56bcb3e8c87bf25cb33ed02832c146e966cc4d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 3 Feb 2018 01:56:11 +0100 Subject: Use Gitlab::CurrentSettings instead of current_application_settings --- spec/features/admin/admin_settings_spec.rb | 4 ++-- spec/models/project_auto_devops_spec.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec') diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 3da2f4e2fdb..39b213988f0 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -52,8 +52,8 @@ feature 'Admin updates settings' do fill_in 'Auto devops domain', with: 'domain.com' click_button 'Save' - expect(current_application_settings.auto_devops_enabled?).to be true - expect(current_application_settings.auto_devops_domain).to eq('domain.com') + expect(Gitlab::CurrentSettings.auto_devops_enabled?).to be true + expect(Gitlab::CurrentSettings.auto_devops_domain).to eq('domain.com') expect(page).to have_content "Application settings saved successfully" end diff --git a/spec/models/project_auto_devops_spec.rb b/spec/models/project_auto_devops_spec.rb index de90080b4b8..296b91a771c 100644 --- a/spec/models/project_auto_devops_spec.rb +++ b/spec/models/project_auto_devops_spec.rb @@ -20,7 +20,7 @@ describe ProjectAutoDevops do context 'when there is an instance domain specified' do before do - stub_application_setting(auto_devops_domain: 'example.com') + allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com') end it { expect(auto_devops).to have_domain } @@ -28,7 +28,7 @@ describe ProjectAutoDevops do context 'when there is no instance domain specified' do before do - stub_application_setting(auto_devops_domain: nil) + allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil) end it { expect(auto_devops).not_to have_domain } @@ -52,7 +52,7 @@ describe ProjectAutoDevops do context 'when there is an instance domain specified' do before do - stub_application_setting(auto_devops_domain: 'example.com') + allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com') end it { expect(auto_devops.variables).to include(domain_variable) } @@ -60,7 +60,7 @@ describe ProjectAutoDevops do context 'when there is no instance domain specified' do before do - stub_application_setting(auto_devops_domain: nil) + allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil) end it { expect(auto_devops.variables).not_to include(domain_variable) } -- cgit v1.2.1