diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-25 21:09:23 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-25 21:09:23 +0000 |
commit | 32fd4cd5e2134511936899d6bcc4aaf18b9be6fd (patch) | |
tree | 10378ceffed52dd0e160a0d9bcf3c5ab72c18958 /spec/models | |
parent | 951616a26a61e880860ad862c1d45a8e3762b4bc (diff) | |
download | gitlab-ce-32fd4cd5e2134511936899d6bcc4aaf18b9be6fd.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/build_spec.rb | 58 | ||||
-rw-r--r-- | spec/models/environment_status_spec.rb | 16 | ||||
-rw-r--r-- | spec/models/pages_domain_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/project_services/chat_notification_service_spec.rb | 23 |
4 files changed, 104 insertions, 1 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 4bfb5771bb8..37219365ecf 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2509,6 +2509,64 @@ describe Ci::Build do end end + describe 'CHANGED_PAGES variables' do + let(:route_map_yaml) do + <<~ROUTEMAP + - source: 'bar/branch-test.txt' + public: '/bar/branches' + ROUTEMAP + end + + before do + allow_any_instance_of(Project) + .to receive(:route_map_for).with(/.+/) + .and_return(Gitlab::RouteMap.new(route_map_yaml)) + end + + context 'with a deployment environment and a merge request' do + let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } + let(:environment) { create(:environment, project: merge_request.project, name: "foo-#{project.default_branch}") } + let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) } + + it 'populates CI_MERGE_REQUEST_CHANGED_PAGES_* variables' do + expect(subject).to include( + { key: 'CI_MERGE_REQUEST_CHANGED_PAGE_PATHS', value: '/bar/branches', public: true, masked: false }, + { key: 'CI_MERGE_REQUEST_CHANGED_PAGE_URLS', value: File.join(environment.external_url, '/bar/branches'), public: true, masked: false } + ) + end + + context 'with a deployment environment and no merge request' do + let(:environment) { create(:environment, project: project, name: "foo-#{project.default_branch}") } + let(:build) { create(:ci_build, pipeline: pipeline, environment: environment.name) } + + it 'does not append CHANGED_PAGES variables' do + ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ } + + expect(ci_variables).to be_empty + end + end + + context 'with no deployment environment and a present merge request' do + let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline, source_project: project, target_project: project) } + let(:build) { create(:ci_build, pipeline: merge_request.all_pipelines.take) } + + it 'does not append CHANGED_PAGES variables' do + ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ } + + expect(ci_variables).to be_empty + end + end + + context 'with no deployment environment and no merge request' do + it 'does not append CHANGED_PAGES variables' do + ci_variables = subject.select { |var| var[:key] =~ /MERGE_REQUEST_CHANGED_PAGES/ } + + expect(ci_variables).to be_empty + end + end + end + end + context 'when build has user' do let(:user_variables) do [ diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb index 0f2c6928820..10283b54796 100644 --- a/spec/models/environment_status_spec.rb +++ b/spec/models/environment_status_spec.rb @@ -51,8 +51,10 @@ describe EnvironmentStatus do # - source: /files\/(.+)/ # public: '\1' describe '#changes' do + subject { environment_status.changes } + it 'contains only added and modified public pages' do - expect(environment_status.changes).to contain_exactly( + expect(subject).to contain_exactly( { path: 'ruby-style-guide.html', external_url: "#{environment.external_url}/ruby-style-guide.html" @@ -64,6 +66,18 @@ describe EnvironmentStatus do end end + describe '#changed_paths' do + subject { environment_status.changed_urls } + + it { is_expected.to contain_exactly("#{environment.external_url}/ruby-style-guide.html", "#{environment.external_url}/html/page.html") } + end + + describe '#changed_urls' do + subject { environment_status.changed_paths } + + it { is_expected.to contain_exactly('ruby-style-guide.html', 'html/page.html') } + end + describe '.for_merge_request' do let(:admin) { create(:admin) } let!(:pipeline) { create(:ci_pipeline, sha: sha, merge_requests_as_head_pipeline: [merge_request]) } diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 7b24ca5eb23..33459767302 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -643,4 +643,12 @@ describe PagesDomain do end end end + + describe '.find_by_domain_case_insensitive' do + it 'lookup is case-insensitive' do + pages_domain = create(:pages_domain, domain: "Pages.IO") + + expect(PagesDomain.find_by_domain_case_insensitive('pages.io')).to eq(pages_domain) + end + end end diff --git a/spec/models/project_services/chat_notification_service_spec.rb b/spec/models/project_services/chat_notification_service_spec.rb index 45ea4cd74ed..64c7a9b230d 100644 --- a/spec/models/project_services/chat_notification_service_spec.rb +++ b/spec/models/project_services/chat_notification_service_spec.rb @@ -74,5 +74,28 @@ describe ChatNotificationService do chat_service.execute(data) end end + + shared_examples 'with channel specified' do |channel, expected_channels| + before do + allow(chat_service).to receive(:push_channel).and_return(channel) + end + + it 'notifies all channels' do + expect(chat_service).to receive(:notify).with(any_args, hash_including(channel: expected_channels)).and_return(true) + expect(chat_service.execute(data)).to be(true) + end + end + + context 'with single channel specified' do + it_behaves_like 'with channel specified', 'slack-integration', ['slack-integration'] + end + + context 'with multiple channel names specified' do + it_behaves_like 'with channel specified', 'slack-integration,#slack-test', ['slack-integration', '#slack-test'] + end + + context 'with multiple channel names with spaces specified' do + it_behaves_like 'with channel specified', 'slack-integration, #slack-test, @UDLP91W0A', ['slack-integration', '#slack-test', '@UDLP91W0A'] + end end end |