diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-12 21:07:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-12 21:07:34 +0300 |
commit | 90859e80ca23b8709d56b60d2066b569053e7e02 (patch) | |
tree | 15d9ac5c194220fab358c42325645fdf2c6ead13 /spec | |
parent | 7530cf5ad8dd86fbe19e129b6bb31b23849ed757 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/jobs/components/log/mock_data.js | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/puma_logging/json_formatter_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/project_services/asana_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/services/issues/zoom_link_service_spec.rb | 69 |
4 files changed, 85 insertions, 32 deletions
diff --git a/spec/frontend/jobs/components/log/mock_data.js b/spec/frontend/jobs/components/log/mock_data.js index d375d82d3ca..01f69e6328c 100644 --- a/spec/frontend/jobs/components/log/mock_data.js +++ b/spec/frontend/jobs/components/log/mock_data.js @@ -34,7 +34,7 @@ export const utilsMockData = [ content: [ { text: - 'Using Docker executor with image dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.3-golang-1.11-git-2.22-chrome-73.0-node-12.x-yarn-1.16-postgresql-9.6-graphicsmagick-1.3.33', + 'Using Docker executor with image dev.gitlab.org:5005/gitlab/gitlab-build-images:ruby-2.6.3-golang-1.12-git-2.24-lfs-2.9-chrome-73.0-node-12.x-yarn-1.16-postgresql-9.6-graphicsmagick-1.3.33', }, ], section: 'prepare-executor', diff --git a/spec/lib/gitlab/puma_logging/json_formatter_spec.rb b/spec/lib/gitlab/puma_logging/json_formatter_spec.rb new file mode 100644 index 00000000000..f7f5b99d5e5 --- /dev/null +++ b/spec/lib/gitlab/puma_logging/json_formatter_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::PumaLogging::JSONFormatter do + it "generate json format with timestamp and pid" do + Timecop.freeze( Time.utc(2019, 12, 04, 9, 10, 11, 123456)) do + expect(subject.call('log message')).to eq "{\"timestamp\":\"2019-12-04T09:10:11.123Z\",\"pid\":#{Process.pid},\"message\":\"log message\"}" + end + end +end diff --git a/spec/models/project_services/asana_service_spec.rb b/spec/models/project_services/asana_service_spec.rb index 18e839bcc64..8b6f2888c0a 100644 --- a/spec/models/project_services/asana_service_spec.rb +++ b/spec/models/project_services/asana_service_spec.rb @@ -21,6 +21,7 @@ describe AsanaService do describe 'Execute' do let(:user) { create(:user) } let(:project) { create(:project) } + let(:gid) { "123456789ABCD" } def create_data_for_commits(*messages) { @@ -48,32 +49,32 @@ describe AsanaService do end it 'calls Asana service to create a story' do - data = create_data_for_commits('Message from commit. related to #123456') + data = create_data_for_commits("Message from commit. related to ##{gid}") expected_message = "#{data[:user_name]} pushed to branch #{data[:ref]} of #{project.full_name} ( #{data[:commits][0][:url]} ): #{data[:commits][0][:message]}" - d1 = double('Asana::Task') + d1 = double('Asana::Resources::Task') expect(d1).to receive(:add_comment).with(text: expected_message) - expect(Asana::Task).to receive(:find_by_id).with(anything, '123456').once.and_return(d1) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, gid).once.and_return(d1) @asana.execute(data) end it 'calls Asana service to create a story and close a task' do data = create_data_for_commits('fix #456789') - d1 = double('Asana::Task') + d1 = double('Asana::Resources::Task') expect(d1).to receive(:add_comment) expect(d1).to receive(:update).with(completed: true) - expect(Asana::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(d1) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '456789').once.and_return(d1) @asana.execute(data) end it 'is able to close via url' do data = create_data_for_commits('closes https://app.asana.com/19292/956299/42') - d1 = double('Asana::Task') + d1 = double('Asana::Resources::Task') expect(d1).to receive(:add_comment) expect(d1).to receive(:update).with(completed: true) - expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d1) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d1) @asana.execute(data) end @@ -84,28 +85,28 @@ describe AsanaService do ref https://app.asana.com/19292/956299/42 and closing https://app.asana.com/19292/956299/12 EOF data = create_data_for_commits(message) - d1 = double('Asana::Task') + d1 = double('Asana::Resources::Task') expect(d1).to receive(:add_comment) expect(d1).to receive(:update).with(completed: true) - expect(Asana::Task).to receive(:find_by_id).with(anything, '123').once.and_return(d1) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '123').once.and_return(d1) - d2 = double('Asana::Task') + d2 = double('Asana::Resources::Task') expect(d2).to receive(:add_comment) expect(d2).to receive(:update).with(completed: true) - expect(Asana::Task).to receive(:find_by_id).with(anything, '456').once.and_return(d2) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '456').once.and_return(d2) - d3 = double('Asana::Task') + d3 = double('Asana::Resources::Task') expect(d3).to receive(:add_comment) - expect(Asana::Task).to receive(:find_by_id).with(anything, '789').once.and_return(d3) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '789').once.and_return(d3) - d4 = double('Asana::Task') + d4 = double('Asana::Resources::Task') expect(d4).to receive(:add_comment) - expect(Asana::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d4) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '42').once.and_return(d4) - d5 = double('Asana::Task') + d5 = double('Asana::Resources::Task') expect(d5).to receive(:add_comment) expect(d5).to receive(:update).with(completed: true) - expect(Asana::Task).to receive(:find_by_id).with(anything, '12').once.and_return(d5) + expect(Asana::Resources::Task).to receive(:find_by_id).with(anything, '12').once.and_return(d5) @asana.execute(data) end diff --git a/spec/services/issues/zoom_link_service_spec.rb b/spec/services/issues/zoom_link_service_spec.rb index ecca9467965..f34d2a18552 100644 --- a/spec/services/issues/zoom_link_service_spec.rb +++ b/spec/services/issues/zoom_link_service_spec.rb @@ -27,12 +27,18 @@ describe Issues::ZoomLinkService do end end - shared_context 'insufficient permissions' do + shared_context 'insufficient issue update permissions' do before do project.add_guest(user) end end + shared_context 'insufficient issue create permissions' do + before do + expect(service).to receive(:can?).with(user, :create_issue, project).and_return(false) + end + end + describe '#add_link' do shared_examples 'can add meeting' do it 'appends the new meeting to zoom_meetings' do @@ -69,16 +75,38 @@ describe Issues::ZoomLinkService do subject(:result) { service.add_link(zoom_link) } context 'without existing Zoom meeting' do - include_examples 'can add meeting' + context 'when updating an issue' do + before do + allow(issue).to receive(:persisted?).and_return(true) + end - context 'with invalid Zoom url' do - let(:zoom_link) { 'https://not-zoom.link' } + include_examples 'can add meeting' - include_examples 'cannot add meeting' + context 'with insufficient issue update permissions' do + include_context 'insufficient issue update permissions' + include_examples 'cannot add meeting' + end end - context 'with insufficient permissions' do - include_context 'insufficient permissions' + context 'when creating an issue' do + before do + allow(issue).to receive(:persisted?).and_return(false) + end + + it 'creates a new zoom meeting' do + expect(result).to be_success + expect(result.payload[:zoom_meetings][0].url).to eq(zoom_link) + end + + context 'with insufficient issue create permissions' do + include_context 'insufficient issue create permissions' + include_examples 'cannot add meeting' + end + end + + context 'with invalid Zoom url' do + let(:zoom_link) { 'https://not-zoom.link' } + include_examples 'cannot add meeting' end end @@ -92,6 +120,7 @@ describe Issues::ZoomLinkService do include_context '"added" Zoom meeting' before do allow(service).to receive(:can_add_link?).and_return(true) + allow(issue).to receive(:persisted?).and_return(true) end include_examples 'cannot add meeting' @@ -104,8 +133,8 @@ describe Issues::ZoomLinkService do context 'without "added" zoom meeting' do it { is_expected.to eq(true) } - context 'with insufficient permissions' do - include_context 'insufficient permissions' + context 'with insufficient issue update permissions' do + include_context 'insufficient issue update permissions' it { is_expected.to eq(false) } end @@ -156,12 +185,24 @@ describe Issues::ZoomLinkService do context 'with Zoom meeting' do include_context '"added" Zoom meeting' - context 'removes the link' do + context 'with existing issue' do + before do + allow(issue).to receive(:persisted?).and_return(true) + end + include_examples 'can remove meeting' end - context 'with insufficient permissions' do - include_context 'insufficient permissions' + context 'without existing issue' do + before do + allow(issue).to receive(:persisted?).and_return(false) + end + + include_examples 'cannot remove meeting' + end + + context 'with insufficient issue update permissions' do + include_context 'insufficient issue update permissions' include_examples 'cannot remove meeting' end end @@ -193,8 +234,8 @@ describe Issues::ZoomLinkService do it { is_expected.to eq(true) } end - context 'with insufficient permissions' do - include_context 'insufficient permissions' + context 'with insufficient issue update permissions' do + include_context 'insufficient issue update permissions' it { is_expected.to eq(false) } end end |