From 1ea1db491c8bc90789acda45c9002aaa5c4dc498 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 27 Jan 2020 15:08:51 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/lib/gitlab/gl_repository/repo_type_spec.rb | 22 +++- spec/lib/gitlab/gl_repository_spec.rb | 8 +- spec/models/project_spec.rb | 4 +- spec/requests/api/internal/base_spec.rb | 6 +- spec/requests/git_http_spec.rb | 4 +- spec/requests/jwt_controller_spec.rb | 22 ++-- spec/requests/lfs_http_spec.rb | 8 +- spec/requests/lfs_locks_api_spec.rb | 14 +-- spec/requests/openid_connect_spec.rb | 4 +- spec/requests/rack_attack_global_spec.rb | 28 ++--- spec/requests/user_avatar_spec.rb | 4 +- spec/services/akismet_service_spec.rb | 137 +++++++++++++++++++++ .../pre_post_stages_spec.rb | 2 +- .../lib/gitlab/repo_type_shared_examples.rb | 26 ++-- 14 files changed, 226 insertions(+), 63 deletions(-) create mode 100644 spec/services/akismet_service_spec.rb (limited to 'spec') diff --git a/spec/lib/gitlab/gl_repository/repo_type_spec.rb b/spec/lib/gitlab/gl_repository/repo_type_spec.rb index 9e09e1411ab..8bbcc644f6d 100644 --- a/spec/lib/gitlab/gl_repository/repo_type_spec.rb +++ b/spec/lib/gitlab/gl_repository/repo_type_spec.rb @@ -2,33 +2,45 @@ require 'spec_helper' describe Gitlab::GlRepository::RepoType do - set(:project) { create(:project) } + let_it_be(:project) { create(:project) } describe Gitlab::GlRepository::PROJECT do it_behaves_like 'a repo type' do let(:expected_identifier) { "project-#{project.id}" } let(:expected_id) { project.id.to_s } - let(:expected_suffix) { "" } + let(:expected_suffix) { '' } let(:expected_repository) { project.repository } + let(:expected_container) { project } end - it "knows its type" do + it 'knows its type' do expect(described_class).not_to be_wiki expect(described_class).to be_project end + + it 'checks if repository path is valid' do + expect(described_class.valid?(project.repository.full_path)).to be_truthy + expect(described_class.valid?(project.wiki.repository.full_path)).to be_truthy + end end describe Gitlab::GlRepository::WIKI do it_behaves_like 'a repo type' do let(:expected_identifier) { "wiki-#{project.id}" } let(:expected_id) { project.id.to_s } - let(:expected_suffix) { ".wiki" } + let(:expected_suffix) { '.wiki' } let(:expected_repository) { project.wiki.repository } + let(:expected_container) { project } end - it "knows its type" do + it 'knows its type' do expect(described_class).to be_wiki expect(described_class).not_to be_project end + + it 'checks if repository path is valid' do + expect(described_class.valid?(project.repository.full_path)).to be_falsey + expect(described_class.valid?(project.wiki.repository.full_path)).to be_truthy + end end end diff --git a/spec/lib/gitlab/gl_repository_spec.rb b/spec/lib/gitlab/gl_repository_spec.rb index 3290bef8aa5..3cfc4c2a132 100644 --- a/spec/lib/gitlab/gl_repository_spec.rb +++ b/spec/lib/gitlab/gl_repository_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe ::Gitlab::GlRepository do describe '.parse' do - set(:project) { create(:project, :repository) } + let_it_be(:project) { create(:project, :repository) } it 'parses a project gl_repository' do expect(described_class.parse("project-#{project.id}")).to eq([project, Gitlab::GlRepository::PROJECT]) @@ -14,8 +14,12 @@ describe ::Gitlab::GlRepository do expect(described_class.parse("wiki-#{project.id}")).to eq([project, Gitlab::GlRepository::WIKI]) end - it 'throws an argument error on an invalid gl_repository' do + it 'throws an argument error on an invalid gl_repository type' do expect { described_class.parse("badformat-#{project.id}") }.to raise_error(ArgumentError) end + + it 'throws an argument error on an invalid gl_repository id' do + expect { described_class.parse("project-foo") }.to raise_error(ArgumentError) + end end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ee65561cc3e..51320b2c9f9 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -3992,7 +3992,7 @@ describe Project do end it 'schedules HashedStorage::ProjectMigrateWorker with delayed start when the project repo is in use' do - Gitlab::ReferenceCounter.new(Gitlab::GlRepository::PROJECT.identifier_for_repositorable(project)).increase + Gitlab::ReferenceCounter.new(Gitlab::GlRepository::PROJECT.identifier_for_container(project)).increase expect(HashedStorage::ProjectMigrateWorker).to receive(:perform_in) @@ -4000,7 +4000,7 @@ describe Project do end it 'schedules HashedStorage::ProjectMigrateWorker with delayed start when the wiki repo is in use' do - Gitlab::ReferenceCounter.new(Gitlab::GlRepository::WIKI.identifier_for_repositorable(project)).increase + Gitlab::ReferenceCounter.new(Gitlab::GlRepository::WIKI.identifier_for_container(project)).increase expect(HashedStorage::ProjectMigrateWorker).to receive(:perform_in) diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb index 6f784830f9d..29112fe5853 100644 --- a/spec/requests/api/internal/base_spec.rb +++ b/spec/requests/api/internal/base_spec.rb @@ -268,7 +268,7 @@ describe API::Internal::Base do end context 'with env passed as a JSON' do - let(:gl_repository) { Gitlab::GlRepository::WIKI.identifier_for_repositorable(project) } + let(:gl_repository) { Gitlab::GlRepository::WIKI.identifier_for_container(project) } it 'sets env in RequestStore' do obj_dir_relative = './objects' @@ -1054,9 +1054,9 @@ describe API::Internal::Base do def gl_repository_for(project_or_wiki) case project_or_wiki when ProjectWiki - Gitlab::GlRepository::WIKI.identifier_for_repositorable(project_or_wiki.project) + Gitlab::GlRepository::WIKI.identifier_for_container(project_or_wiki.project) when Project - Gitlab::GlRepository::PROJECT.identifier_for_repositorable(project_or_wiki) + Gitlab::GlRepository::PROJECT.identifier_for_container(project_or_wiki) else nil end diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index d9c398923c5..9f493fdffea 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -848,7 +848,7 @@ describe 'Git HTTP requests' do end it "redirects" do - expect(response).to have_gitlab_http_status(302) + expect(response).to have_gitlab_http_status(:found) end end end @@ -890,7 +890,7 @@ describe 'Git HTTP requests' do it "responds with status 200" do clone_get(path, env) do |response| - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end diff --git a/spec/requests/jwt_controller_spec.rb b/spec/requests/jwt_controller_spec.rb index 199c2dbe9ca..754ab3e6a45 100644 --- a/spec/requests/jwt_controller_spec.rb +++ b/spec/requests/jwt_controller_spec.rb @@ -15,12 +15,12 @@ describe JwtController do context 'existing service' do subject! { get '/jwt/auth', params: parameters } - it { expect(response).to have_gitlab_http_status(200) } + it { expect(response).to have_gitlab_http_status(:ok) } context 'returning custom http code' do let(:service) { double(execute: { http_status: 505 }) } - it { expect(response).to have_gitlab_http_status(505) } + it { expect(response).to have_gitlab_http_status(:http_version_not_supported) } end end @@ -43,7 +43,7 @@ describe JwtController do subject! { get '/jwt/auth', params: parameters, headers: headers } - it { expect(response).to have_gitlab_http_status(401) } + it { expect(response).to have_gitlab_http_status(:unauthorized) } end context 'using personal access tokens' do @@ -58,7 +58,7 @@ describe JwtController do subject! { get '/jwt/auth', params: parameters, headers: headers } it 'authenticates correctly' do - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect(service_class).to have_received(:new).with(nil, user, ActionController::Parameters.new(parameters).permit!) end end @@ -96,7 +96,7 @@ describe JwtController do context 'without personal token' do it 'rejects the authorization attempt' do - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') end end @@ -106,7 +106,7 @@ describe JwtController do let(:headers) { { authorization: credentials(user.username, access_token.token) } } it 'accepts the authorization attempt' do - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end end @@ -116,7 +116,7 @@ describe JwtController do get '/jwt/auth', params: parameters, headers: headers - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -127,7 +127,7 @@ describe JwtController do it 'rejects the authorization attempt' do get '/jwt/auth', params: parameters, headers: headers - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) expect(response.body).not_to include('You must use a personal access token with \'api\' scope for Git over HTTP') end end @@ -139,7 +139,7 @@ describe JwtController do end get '/jwt/auth', params: parameters, headers: headers - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) expect(response.body).to include('You must use a personal access token with \'api\' scope for Git over HTTP') end end @@ -150,7 +150,7 @@ describe JwtController do it 'accepts the authorization attempt' do get '/jwt/auth', params: parameters - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end it 'allows read access' do @@ -163,7 +163,7 @@ describe JwtController do context 'unknown service' do subject! { get '/jwt/auth', params: { service: 'unknown' } } - it { expect(response).to have_gitlab_http_status(404) } + it { expect(response).to have_gitlab_http_status(:not_found) } end def credentials(login, password) diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index 62b9ee1d361..0e02c0f001b 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -227,7 +227,7 @@ describe 'Git LFS API and storage' do end it 'responds with redirect' do - expect(response).to have_gitlab_http_status(302) + expect(response).to have_gitlab_http_status(:found) end it 'responds with the file location' do @@ -1011,7 +1011,7 @@ describe 'Git LFS API and storage' do it 'responds with status 403' do subject - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end end @@ -1027,7 +1027,7 @@ describe 'Git LFS API and storage' do it 'responds with status 200' do subject - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) object = LfsObject.find_by_oid(sample_oid) expect(object).to be_present @@ -1070,7 +1070,7 @@ describe 'Git LFS API and storage' do it 'rejects slashes in the tempfile name (path traversal)' do put_finalize('../bar', with_tempfile: true) - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end end diff --git a/spec/requests/lfs_locks_api_spec.rb b/spec/requests/lfs_locks_api_spec.rb index 41f54162266..41cf1a80205 100644 --- a/spec/requests/lfs_locks_api_spec.rb +++ b/spec/requests/lfs_locks_api_spec.rb @@ -23,7 +23,7 @@ describe 'Git LFS File Locking API' do it 'returns a forbidden 403 response' do post_lfs_json url, body, headers - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end end @@ -51,7 +51,7 @@ describe 'Git LFS File Locking API' do it 'return an error message' do post_lfs_json url, body, headers - expect(response).to have_gitlab_http_status(409) + expect(response).to have_gitlab_http_status(:conflict) expect(json_response.keys).to match_array(%w(lock message documentation_url)) expect(json_response['message']).to match(/already locked/) @@ -68,7 +68,7 @@ describe 'Git LFS File Locking API' do it 'creates the lock' do post_lfs_json url, body, headers - expect(response).to have_gitlab_http_status(201) + expect(response).to have_gitlab_http_status(:created) expect(json_response['lock'].keys).to match_array(%w(id path locked_at owner)) end @@ -87,7 +87,7 @@ describe 'Git LFS File Locking API' do do_get url, nil, headers - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect(json_response['locks'].size).to eq(2) expect(json_response['locks'].first.keys).to match_array(%w(id path locked_at owner)) @@ -106,7 +106,7 @@ describe 'Git LFS File Locking API' do post_lfs_json url, nil, headers - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect(json_response['ours'].size).to eq(1) expect(json_response['ours'].first['path']).to eq('README') @@ -126,7 +126,7 @@ describe 'Git LFS File Locking API' do it 'deletes the lock' do post_lfs_json url, nil, headers - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end it 'returns the deleted lock' do @@ -142,7 +142,7 @@ describe 'Git LFS File Locking API' do project.add_maintainer(maintainer) post_lfs_json url, { force: true }, headers - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end end diff --git a/spec/requests/openid_connect_spec.rb b/spec/requests/openid_connect_spec.rb index bac1a4e18c8..d7c08484dc4 100644 --- a/spec/requests/openid_connect_spec.rb +++ b/spec/requests/openid_connect_spec.rb @@ -75,7 +75,7 @@ describe 'OpenID Connect requests' do it 'userinfo response is unauthorized' do request_user_info! - expect(response).to have_gitlab_http_status 403 + expect(response).to have_gitlab_http_status(:forbidden) expect(response.body).to be_blank end end @@ -177,7 +177,7 @@ describe 'OpenID Connect requests' do it 'correctly returns the configuration' do get '/.well-known/openid-configuration' - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect(json_response['issuer']).to eq('http://localhost') expect(json_response['jwks_uri']).to eq('http://www.example.com/oauth/discovery/keys') expect(json_response['scopes_supported']).to eq(%w[api read_user read_repository write_repository sudo openid profile email]) diff --git a/spec/requests/rack_attack_global_spec.rb b/spec/requests/rack_attack_global_spec.rb index 9968b2e4aba..da0ca4c197a 100644 --- a/spec/requests/rack_attack_global_spec.rb +++ b/spec/requests/rack_attack_global_spec.rb @@ -53,7 +53,7 @@ describe 'Rack Attack global throttles' do # At first, allow requests under the rate limit. requests_per_period.times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end # the last straw @@ -63,7 +63,7 @@ describe 'Rack Attack global throttles' do it 'allows requests after throttling and then waiting for the next period' do requests_per_period.times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end expect_rejection { get url_that_does_not_require_authentication } @@ -71,7 +71,7 @@ describe 'Rack Attack global throttles' do Timecop.travel(period.from_now) do requests_per_period.times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end expect_rejection { get url_that_does_not_require_authentication } @@ -81,7 +81,7 @@ describe 'Rack Attack global throttles' do it 'counts requests from different IPs separately' do requests_per_period.times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end expect_next_instance_of(Rack::Attack::Request) do |instance| @@ -90,14 +90,14 @@ describe 'Rack Attack global throttles' do # would be over limit for the same IP get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end context 'when the request is to the api internal endpoints' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do get url_api_internal, params: { secret_token: Gitlab::Shell.secret_token } - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end end end @@ -109,7 +109,7 @@ describe 'Rack Attack global throttles' do it 'does not cont as unauthenticated' do (1 + requests_per_period).times do post request_jobs_url, params: { token: runner.token } - expect(response).to have_http_status 204 + expect(response).to have_gitlab_http_status(:no_content) end end end @@ -117,7 +117,7 @@ describe 'Rack Attack global throttles' do it 'logs RackAttack info into structured logs' do requests_per_period.times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end arguments = { @@ -143,7 +143,7 @@ describe 'Rack Attack global throttles' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do get url_that_does_not_require_authentication - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end end end @@ -243,7 +243,7 @@ describe 'Rack Attack global throttles' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do post protected_path_that_does_not_require_authentication, params: post_params - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end end end @@ -257,7 +257,7 @@ describe 'Rack Attack global throttles' do it 'rejects requests over the rate limit' do requests_per_period.times do post protected_path_that_does_not_require_authentication, params: post_params - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end expect_rejection { post protected_path_that_does_not_require_authentication, params: post_params } @@ -272,7 +272,7 @@ describe 'Rack Attack global throttles' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do post protected_path_that_does_not_require_authentication, params: post_params - expect(response).to have_http_status 200 + expect(response).to have_gitlab_http_status(:ok) end end end @@ -329,7 +329,7 @@ describe 'Rack Attack global throttles' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do post(*request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end end end @@ -369,7 +369,7 @@ describe 'Rack Attack global throttles' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do post url_that_requires_authentication - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end end end diff --git a/spec/requests/user_avatar_spec.rb b/spec/requests/user_avatar_spec.rb index 9451674161c..66c7ce4d533 100644 --- a/spec/requests/user_avatar_spec.rb +++ b/spec/requests/user_avatar_spec.rb @@ -19,7 +19,7 @@ describe 'Loading a user avatar' do it 'only performs three SQL queries' do get user.avatar_url # Skip queries on first application load - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect { get user.avatar_url }.not_to exceed_query_limit(3) end end @@ -29,7 +29,7 @@ describe 'Loading a user avatar' do it 'only performs two SQL queries' do get user.avatar_url # Skip queries on first application load - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect { get user.avatar_url }.not_to exceed_query_limit(2) end end diff --git a/spec/services/akismet_service_spec.rb b/spec/services/akismet_service_spec.rb new file mode 100644 index 00000000000..4f1c23b701b --- /dev/null +++ b/spec/services/akismet_service_spec.rb @@ -0,0 +1,137 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe AkismetService do + let(:fake_akismet_client) { double(:akismet_client) } + + let_it_be(:text) { "Would you like to buy some tinned meat product?" } + let_it_be(:spam_owner) { create(:user) } + + subject do + options = { ip_address: '1.2.3.4', user_agent: 'some user_agent', referrer: 'some referrer' } + described_class.new(spam_owner.name, spam_owner.email, text, options) + end + + before do + stub_application_setting(akismet_enabled: true) + allow(subject).to receive(:akismet_client).and_return(fake_akismet_client) + end + + shared_examples 'no activity if Akismet is not enabled' do |method_call| + # if the method name is `submit`, it requires an argument, so add it + before do + stub_application_setting(akismet_enabled: false) + end + + it 'is automatically false' do + expect(subject.send(method_call)).to be_falsey + end + + it 'performs no check' do + expect(fake_akismet_client).not_to receive(:public_send) + + subject.send(method_call) + end + end + + shared_examples 'false if Akismet is not available' do |method_call| + context 'if Akismet is not available' do + before do + allow(fake_akismet_client).to receive(:public_send).and_raise(StandardError.new("oh noes!")) + end + + specify do + expect(subject.send(method_call)).to be_falsey + end + + it 'logs an error' do + logger_spy = double(:logger) + expect(Rails).to receive(:logger).and_return(logger_spy) + expect(logger_spy).to receive(:error).with(/skipping/) + + subject.send(method_call) + end + end + end + + describe '#spam?' do + it_behaves_like 'no activity if Akismet is not enabled', :spam?, :check + + context 'if Akismet is enabled' do + context 'the text is spam' do + before do + allow(fake_akismet_client).to receive(:check).and_return([true, false]) + end + + specify do + expect(subject.spam?).to be_truthy + end + end + + context 'the text is blatant spam' do + before do + allow(fake_akismet_client).to receive(:check).and_return([false, true]) + end + + specify do + expect(subject.spam?).to be_truthy + end + end + + context 'the text is not spam' do + before do + allow(fake_akismet_client).to receive(:check).and_return([false, false]) + end + + specify do + expect(subject.spam?).to be_falsey + end + end + + context 'if Akismet is not available' do + before do + allow(fake_akismet_client).to receive(:check).and_raise(StandardError.new("oh noes!")) + end + + specify do + expect(subject.spam?).to be_falsey + end + + it 'logs an error' do + logger_spy = double(:logger) + expect(Rails).to receive(:logger).and_return(logger_spy) + expect(logger_spy).to receive(:error).with(/skipping check/) + + subject.spam? + end + end + end + end + + describe '#submit_ham' do + it_behaves_like 'no activity if Akismet is not enabled', :submit_ham + it_behaves_like 'false if Akismet is not available', :submit_ham + + context 'if Akismet is available' do + specify do + expect(fake_akismet_client).to receive(:public_send).with(:ham, any_args) + + expect(subject.submit_ham).to be_truthy + end + end + end + + describe '#submit_spam' do + it_behaves_like 'no activity if Akismet is not enabled', :submit_spam + it_behaves_like 'false if Akismet is not available', :submit_spam + + context 'if Akismet is available' do + specify do + expect(fake_akismet_client).to receive(:public_send).with(:spam, any_args) + + expect(subject.submit_spam).to be_truthy + end + end + end +end diff --git a/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb b/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb index db9b89f090f..2b11b98f58c 100644 --- a/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb +++ b/spec/services/ci/create_pipeline_service/pre_post_stages_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' describe Ci::CreatePipelineService do - context '.pre/.post stages' do + describe '.pre/.post stages' do let_it_be(:user) { create(:admin) } let_it_be(:project) { create(:project, :repository, creator: user) } diff --git a/spec/support/shared_examples/lib/gitlab/repo_type_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/repo_type_shared_examples.rb index f4960b9f134..3d88b317417 100644 --- a/spec/support/shared_examples/lib/gitlab/repo_type_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/repo_type_shared_examples.rb @@ -1,30 +1,40 @@ # frozen_string_literal: true RSpec.shared_examples 'a repo type' do - describe "#identifier_for_repositorable" do - subject { described_class.identifier_for_repositorable(project) } + describe '#identifier_for_container' do + subject { described_class.identifier_for_container(project) } it { is_expected.to eq(expected_identifier) } end - describe "#fetch_id" do - it "finds an id match in the identifier" do + describe '#fetch_id' do + it 'finds an id match in the identifier' do expect(described_class.fetch_id(expected_identifier)).to eq(expected_id) end it 'does not break on other identifiers' do - expect(described_class.fetch_id("wiki-noid")).to eq(nil) + expect(described_class.fetch_id('wiki-noid')).to eq(nil) end end - describe "#path_suffix" do + describe '#fetch_container!' do + it 'returns the container' do + expect(described_class.fetch_container!(expected_identifier)).to eq expected_container + end + + it 'raises an exception if the identifier is invalid' do + expect { described_class.fetch_container!('project-noid') }.to raise_error ArgumentError + end + end + + describe '#path_suffix' do subject { described_class.path_suffix } it { is_expected.to eq(expected_suffix) } end - describe "#repository_for" do - it "finds the repository for the repo type" do + describe '#repository_for' do + it 'finds the repository for the repo type' do expect(described_class.repository_for(project)).to eq(expected_repository) end end -- cgit v1.2.3