From ff72de88bbc0d3c2681620fb576bf0e8379bdb42 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 17:43:26 -0700 Subject: remove use of deprecated webmock feature in jira specs --- spec/features/projects/services/jira_service_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'spec') diff --git a/spec/features/projects/services/jira_service_spec.rb b/spec/features/projects/services/jira_service_spec.rb index 2ea50e8f672..bf2ee2a10b1 100644 --- a/spec/features/projects/services/jira_service_spec.rb +++ b/spec/features/projects/services/jira_service_spec.rb @@ -6,7 +6,11 @@ feature 'Setup Jira service', :feature, :js do let(:service) { project.create_jira_service } let(:url) { 'http://jira.example.com' } - let(:project_url) { 'http://username:password@jira.example.com/rest/api/2/project/GitLabProject' } + + def stub_project_url + WebMock.stub_request(:get, 'http://jira.example.com/rest/api/2/project/GitLabProject') + .with(basic_auth: %w(username password)) + end def fill_form(active = true) check 'Active' if active @@ -27,9 +31,7 @@ feature 'Setup Jira service', :feature, :js do describe 'user sets and activates Jira Service' do context 'when Jira connection test succeeds' do - before do - WebMock.stub_request(:get, project_url) - end + before { stub_project_url } it 'activates the JIRA service' do click_link('JIRA') @@ -43,9 +45,7 @@ feature 'Setup Jira service', :feature, :js do end context 'when Jira connection test fails' do - before do - WebMock.stub_request(:get, project_url).to_return(status: 401) - end + before { stub_project_url.to_return(status: 401) } it 'shows errors when some required fields are not filled in' do click_link('JIRA') -- cgit v1.2.1 From 9ca4a3988b494e667d1e8cd71a7ac2fb598f618d Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 17:47:35 -0700 Subject: rm use of deprecated webmock api in bamboo_service_spec --- spec/models/project_services/bamboo_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/models/project_services/bamboo_service_spec.rb b/spec/models/project_services/bamboo_service_spec.rb index e62fd69e567..7b1a554d1fb 100644 --- a/spec/models/project_services/bamboo_service_spec.rb +++ b/spec/models/project_services/bamboo_service_spec.rb @@ -217,13 +217,13 @@ describe BambooService, models: true, caching: true do end def stub_request(status: 200, body: nil) - bamboo_full_url = 'http://mic:password@gitlab.com/bamboo/rest/api/latest/result?label=123&os_authType=basic' + bamboo_full_url = 'http://gitlab.com/bamboo/rest/api/latest/result?label=123&os_authType=basic' WebMock.stub_request(:get, bamboo_full_url).to_return( status: status, headers: { 'Content-Type' => 'application/json' }, body: body - ) + ).with(basic_auth: %w(mic password)) end def bamboo_response(result_key: 42, build_state: 'success', size: 1) -- cgit v1.2.1 From e57d1bbf138aadd9c54a3e886d66d8b02e2497ae Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 17:53:39 -0700 Subject: rm use of deprecated webmock api in jira model spec --- spec/models/project_services/jira_service_spec.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'spec') diff --git a/spec/models/project_services/jira_service_spec.rb b/spec/models/project_services/jira_service_spec.rb index e2b8226124f..c86f56c55eb 100644 --- a/spec/models/project_services/jira_service_spec.rb +++ b/spec/models/project_services/jira_service_spec.rb @@ -106,15 +106,15 @@ describe JiraService, models: true do @jira_service.save - project_issues_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123' - @transitions_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/transitions' - @comment_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/comment' - @remote_link_url = 'http://gitlab_jira_username:gitlab_jira_password@jira.example.com/rest/api/2/issue/JIRA-123/remotelink' - - WebMock.stub_request(:get, project_issues_url) - WebMock.stub_request(:post, @transitions_url) - WebMock.stub_request(:post, @comment_url) - WebMock.stub_request(:post, @remote_link_url) + project_issues_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123' + @transitions_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/transitions' + @comment_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/comment' + @remote_link_url = 'http://jira.example.com/rest/api/2/issue/JIRA-123/remotelink' + + WebMock.stub_request(:get, project_issues_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)) + WebMock.stub_request(:post, @transitions_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)) + WebMock.stub_request(:post, @comment_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)) + WebMock.stub_request(:post, @remote_link_url).with(basic_auth: %w(gitlab_jira_username gitlab_jira_password)) end it "calls JIRA API" do @@ -202,9 +202,9 @@ describe JiraService, models: true do end def test_settings(api_url) - project_url = "http://jira_username:jira_password@#{api_url}/rest/api/2/project/GitLabProject" + project_url = "http://#{api_url}/rest/api/2/project/GitLabProject" - WebMock.stub_request(:get, project_url) + WebMock.stub_request(:get, project_url).with(basic_auth: %w(jira_username jira_password)) jira_service.test_settings end -- cgit v1.2.1 From 7ef3cf64d6d6af9941401af748274677ff3af15d Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 17:59:32 -0700 Subject: rm use of deprecated webmock api in campfire_service_spec --- spec/models/project_services/campfire_service_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'spec') diff --git a/spec/models/project_services/campfire_service_spec.rb b/spec/models/project_services/campfire_service_spec.rb index de55627dd27..56ff3596190 100644 --- a/spec/models/project_services/campfire_service_spec.rb +++ b/spec/models/project_services/campfire_service_spec.rb @@ -39,21 +39,22 @@ describe CampfireService, models: true do room: 'test-room' ) @sample_data = Gitlab::DataBuilder::Push.build_sample(project, user) - @rooms_url = 'https://verySecret:X@project-name.campfirenow.com/rooms.json' + @rooms_url = 'https://project-name.campfirenow.com/rooms.json' + @auth = %w(verySecret X) @headers = { 'Content-Type' => 'application/json; charset=utf-8' } end it "calls Campfire API to get a list of rooms and speak in a room" do # make sure a valid list of rooms is returned body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms.json') - WebMock.stub_request(:get, @rooms_url).to_return( + WebMock.stub_request(:get, @rooms_url).with(basic_auth: @auth).to_return( body: body, status: 200, headers: @headers ) # stub the speak request with the room id found in the previous request's response - speak_url = 'https://verySecret:X@project-name.campfirenow.com/room/123/speak.json' - WebMock.stub_request(:post, speak_url) + speak_url = 'https://project-name.campfirenow.com/room/123/speak.json' + WebMock.stub_request(:post, speak_url).with(basic_auth: @auth) @campfire_service.execute(@sample_data) @@ -66,7 +67,7 @@ describe CampfireService, models: true do it "calls Campfire API to get a list of rooms but shouldn't speak in a room" do # return a list of rooms that do not contain a room named 'test-room' body = File.read(Rails.root + 'spec/fixtures/project_services/campfire/rooms2.json') - WebMock.stub_request(:get, @rooms_url).to_return( + WebMock.stub_request(:get, @rooms_url).with(basic_auth: @auth).to_return( body: body, status: 200, headers: @headers -- cgit v1.2.1 From 2f0a7088d33a1630c3e54812d10219b75cdf7bc4 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 17:59:45 -0700 Subject: rm use of deprecated webmock api in teamcity_service_spec --- spec/models/project_services/teamcity_service_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/models/project_services/teamcity_service_spec.rb b/spec/models/project_services/teamcity_service_spec.rb index 7349eb4149a..6b004098510 100644 --- a/spec/models/project_services/teamcity_service_spec.rb +++ b/spec/models/project_services/teamcity_service_spec.rb @@ -205,10 +205,12 @@ describe TeamcityService, models: true, caching: true do end def stub_request(status: 200, body: nil, build_status: 'success') - teamcity_full_url = 'http://mic:password@gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,number:123' + teamcity_full_url = 'http://gitlab.com/teamcity/httpAuth/app/rest/builds/branch:unspecified:any,number:123' + auth = %w(mic password) + body ||= %Q({"build":{"status":"#{build_status}","id":"666"}}) - WebMock.stub_request(:get, teamcity_full_url).to_return( + WebMock.stub_request(:get, teamcity_full_url).with(basic_auth: auth).to_return( status: status, headers: { 'Content-Type' => 'application/json' }, body: body -- cgit v1.2.1 From a274359ecd485218ed7c42b750a43992ff3142ef Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 26 Jun 2017 19:24:12 -0700 Subject: rubocop fix: don't use single line blocks --- spec/features/projects/services/jira_service_spec.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/spec/features/projects/services/jira_service_spec.rb b/spec/features/projects/services/jira_service_spec.rb index bf2ee2a10b1..8cd216c8fdb 100644 --- a/spec/features/projects/services/jira_service_spec.rb +++ b/spec/features/projects/services/jira_service_spec.rb @@ -31,7 +31,9 @@ feature 'Setup Jira service', :feature, :js do describe 'user sets and activates Jira Service' do context 'when Jira connection test succeeds' do - before { stub_project_url } + before do + stub_project_url + end it 'activates the JIRA service' do click_link('JIRA') @@ -45,7 +47,9 @@ feature 'Setup Jira service', :feature, :js do end context 'when Jira connection test fails' do - before { stub_project_url.to_return(status: 401) } + before do + stub_project_url.to_return(status: 401) + end it 'shows errors when some required fields are not filled in' do click_link('JIRA') -- cgit v1.2.1