diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:09:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-06 18:09:37 +0000 |
commit | 495c22d1245b6212b21b7379a542df73dfa77206 (patch) | |
tree | 5f0f82dd6c8c4fe1c4bd411f9e398b1a6eaaa69f /spec | |
parent | f3b1e07903a7f509b11ad7cf188fac46d98f77f6 (diff) | |
download | gitlab-ce-495c22d1245b6212b21b7379a542df73dfa77206.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects/static_site_editor_controller_spec.rb | 45 | ||||
-rw-r--r-- | spec/factories/milestones.rb | 10 | ||||
-rw-r--r-- | spec/features/projects/snippets/user_updates_snippet_spec.rb | 6 | ||||
-rw-r--r-- | spec/features/snippets/user_edits_snippet_spec.rb | 6 | ||||
-rw-r--r-- | spec/frontend/__mocks__/@gitlab/ui.js | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/url_builder_spec.rb | 224 | ||||
-rw-r--r-- | spec/models/personal_snippet_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_snippet_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/project_wiki_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/notification_service_spec.rb | 18 | ||||
-rw-r--r-- | spec/services/snippets/update_service_spec.rb | 81 | ||||
-rw-r--r-- | spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb | 70 |
13 files changed, 229 insertions, 242 deletions
diff --git a/spec/controllers/projects/static_site_editor_controller_spec.rb b/spec/controllers/projects/static_site_editor_controller_spec.rb new file mode 100644 index 00000000000..7f1b67fc734 --- /dev/null +++ b/spec/controllers/projects/static_site_editor_controller_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Projects::StaticSiteEditorController do + let(:project) { create(:project, :public, :repository) } + + describe 'GET show' do + let(:default_params) do + { + namespace_id: project.namespace, + project_id: project, + id: 'master/README.md' + } + end + + context 'User roles' do + context 'anonymous' do + before do + get :show, params: default_params + end + + it 'redirects to sign in and returns' do + expect(response).to redirect_to(new_user_session_path) + end + end + + %w[guest developer maintainer].each do |role| + context "as #{role}" do + let(:user) { create(:user) } + + before do + project.add_role(user, role) + sign_in(user) + get :show, params: default_params + end + + it 'renders the edit page' do + expect(response).to render_template(:show) + end + end + end + end + end +end diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 151d286cc29..ae98ac1bbd7 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -25,6 +25,14 @@ FactoryBot.define do due_date { Date.new(2000, 1, 30) } end + trait :on_project do + project + end + + trait :on_group do + group + end + after(:build, :stub) do |milestone, evaluator| if evaluator.group milestone.group = evaluator.group @@ -44,5 +52,7 @@ FactoryBot.define do factory :active_milestone, traits: [:active] factory :closed_milestone, traits: [:closed] + factory :project_milestone, traits: [:on_project] + factory :group_milestone, traits: [:on_group] end end diff --git a/spec/features/projects/snippets/user_updates_snippet_spec.rb b/spec/features/projects/snippets/user_updates_snippet_spec.rb index 58ca922b9cb..bad3fde8a4a 100644 --- a/spec/features/projects/snippets/user_updates_snippet_spec.rb +++ b/spec/features/projects/snippets/user_updates_snippet_spec.rb @@ -54,11 +54,9 @@ describe 'Projects > Snippets > User updates a snippet', :js do end context 'when the git operation fails' do - let(:error_message) { 'foobar' } - before do allow_next_instance_of(Snippets::UpdateService) do |instance| - allow(instance).to receive(:create_commit).and_raise(StandardError, error_message) + allow(instance).to receive(:create_commit).and_raise(StandardError) end fill_in('project_snippet_title', with: 'Snippet new title') @@ -67,7 +65,7 @@ describe 'Projects > Snippets > User updates a snippet', :js do end it 'renders edit page and displays the error' do - expect(page.find('.flash-container span').text).to eq(error_message) + expect(page.find('.flash-container span').text).to eq('Error updating the snippet') expect(page).to have_content('Edit Snippet') end end diff --git a/spec/features/snippets/user_edits_snippet_spec.rb b/spec/features/snippets/user_edits_snippet_spec.rb index 1ec18e3e0e3..0bbb92b1f3f 100644 --- a/spec/features/snippets/user_edits_snippet_spec.rb +++ b/spec/features/snippets/user_edits_snippet_spec.rb @@ -85,11 +85,9 @@ describe 'User edits snippet', :js do end context 'when the git operation fails' do - let(:error_message) { 'foobar' } - before do allow_next_instance_of(Snippets::UpdateService) do |instance| - allow(instance).to receive(:create_commit).and_raise(StandardError, error_message) + allow(instance).to receive(:create_commit).and_raise(StandardError) end fill_in 'personal_snippet_title', with: 'New Snippet Title' @@ -98,7 +96,7 @@ describe 'User edits snippet', :js do end it 'renders edit page and displays the error' do - expect(page.find('.flash-container span').text).to eq(error_message) + expect(page.find('.flash-container span').text).to eq('Error updating the snippet') expect(page).to have_content('Edit Snippet') end end diff --git a/spec/frontend/__mocks__/@gitlab/ui.js b/spec/frontend/__mocks__/@gitlab/ui.js index 7f893bf7ed7..d65fab80d3b 100644 --- a/spec/frontend/__mocks__/@gitlab/ui.js +++ b/spec/frontend/__mocks__/@gitlab/ui.js @@ -31,6 +31,6 @@ export const GlPopover = { }, }, render(h) { - return h('div', this.$attrs, this.$slots.default); + return h('div', this.$attrs, Object.keys(this.$slots).map(s => this.$slots[s])); }, }; diff --git a/spec/lib/gitlab/url_builder_spec.rb b/spec/lib/gitlab/url_builder_spec.rb index c2eb1b4c25d..1b23f331b89 100644 --- a/spec/lib/gitlab/url_builder_spec.rb +++ b/spec/lib/gitlab/url_builder_spec.rb @@ -3,186 +3,116 @@ require 'spec_helper' describe Gitlab::UrlBuilder do - describe '.build' do - context 'when passing a Commit' do - it 'returns a proper URL' do - commit = build_stubbed(:commit) - - url = described_class.build(commit) - - expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}" - end - end - - context 'when passing a batch loaded Commit' do - it 'returns a proper URL' do - commit = BatchLoader.for(:commit).batch do |batch, loader| - batch.each { |commit| loader.call(:commit, build_stubbed(:commit)) } - end + subject { described_class } - url = described_class.build(commit) + describe '#build' do + it 'delegates to the class method' do + expect(subject).to receive(:build).with(:foo, bar: :baz) - expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.full_path}/-/commit/#{commit.id}" - end + subject.instance.build(:foo, bar: :baz) end + end - context 'when passing an Issue' do - it 'returns a proper URL' do - issue = build_stubbed(:issue, iid: 42) - - url = described_class.build(issue) - - expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}" - end + describe '.build' do + using RSpec::Parameterized::TableSyntax + + where(:factory, :path_generator) do + :project | ->(project) { "/#{project.full_path}" } + :commit | ->(commit) { "/#{commit.project.full_path}/-/commit/#{commit.id}" } + :issue | ->(issue) { "/#{issue.project.full_path}/-/issues/#{issue.iid}" } + :merge_request | ->(merge_request) { "/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}" } + :project_milestone | ->(milestone) { "/#{milestone.project.full_path}/-/milestones/#{milestone.iid}" } + :project_snippet | ->(snippet) { "/#{snippet.project.full_path}/snippets/#{snippet.id}" } + :project_wiki | ->(wiki) { "/#{wiki.project.full_path}/-/wikis/home" } + :ci_build | ->(build) { "/#{build.project.full_path}/-/jobs/#{build.id}" } + + :group | ->(group) { "/groups/#{group.full_path}" } + :group_milestone | ->(milestone) { "/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}" } + + :user | ->(user) { "/#{user.full_path}" } + :personal_snippet | ->(snippet) { "/snippets/#{snippet.id}" } + :wiki_page | ->(wiki_page) { "#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}" } + + :note_on_commit | ->(note) { "/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" } + :diff_note_on_commit | ->(note) { "/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" } + :discussion_note_on_commit | ->(note) { "/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" } + :legacy_diff_note_on_commit | ->(note) { "/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" } + + :note_on_issue | ->(note) { "/#{note.project.full_path}/-/issues/#{note.noteable.iid}#note_#{note.id}" } + :discussion_note_on_issue | ->(note) { "/#{note.project.full_path}/-/issues/#{note.noteable.iid}#note_#{note.id}" } + + :note_on_merge_request | ->(note) { "/#{note.project.full_path}/-/merge_requests/#{note.noteable.iid}#note_#{note.id}" } + :diff_note_on_merge_request | ->(note) { "/#{note.project.full_path}/-/merge_requests/#{note.noteable.iid}#note_#{note.id}" } + :discussion_note_on_merge_request | ->(note) { "/#{note.project.full_path}/-/merge_requests/#{note.noteable.iid}#note_#{note.id}" } + :legacy_diff_note_on_merge_request | ->(note) { "/#{note.project.full_path}/-/merge_requests/#{note.noteable.iid}#note_#{note.id}" } + + :note_on_project_snippet | ->(note) { "/#{note.project.full_path}/snippets/#{note.noteable_id}#note_#{note.id}" } + :discussion_note_on_project_snippet | ->(note) { "/#{note.project.full_path}/snippets/#{note.noteable_id}#note_#{note.id}" } + :discussion_note_on_personal_snippet | ->(note) { "/snippets/#{note.noteable_id}#note_#{note.id}" } + :note_on_personal_snippet | ->(note) { "/snippets/#{note.noteable_id}#note_#{note.id}" } end - context 'when passing a Milestone' do - let(:group) { create(:group) } - let(:project) { create(:project, :public, namespace: group) } - - context 'belonging to a project' do - it 'returns a proper URL' do - milestone = create(:milestone, project: project) + with_them do + let(:object) { build_stubbed(factory) } + let(:path) { path_generator.call(object) } - url = described_class.build(milestone) - - expect(url).to eq "#{Settings.gitlab['url']}/#{milestone.project.full_path}/-/milestones/#{milestone.iid}" - end + it 'returns the full URL' do + expect(subject.build(object)).to eq("#{Gitlab.config.gitlab.url}#{path}") end - context 'belonging to a group' do - it 'returns a proper URL' do - milestone = create(:milestone, group: group) - - url = described_class.build(milestone) - - expect(url).to eq "#{Settings.gitlab['url']}/groups/#{milestone.group.full_path}/-/milestones/#{milestone.iid}" - end + it 'returns only the path if only_path is given' do + expect(subject.build(object, only_path: true)).to eq(path) end end - context 'when passing a MergeRequest' do - it 'returns a proper URL' do - merge_request = build_stubbed(:merge_request, iid: 42) + context 'when passing a commit without a project' do + let(:commit) { build_stubbed(:commit) } - url = described_class.build(merge_request) + it 'returns an empty string' do + allow(commit).to receive(:project).and_return(nil) - expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}" + expect(subject.build(commit)).to eq('') end end - context 'when passing a ProjectSnippet' do - it 'returns a proper URL' do - project_snippet = create(:project_snippet) + context 'when passing a commit note without a project' do + let(:note) { build_stubbed(:note_on_commit) } - url = described_class.build(project_snippet) + it 'returns an empty string' do + allow(note).to receive(:project).and_return(nil) - expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{project_snippet.id}" + expect(subject.build(note)).to eq('') end end - context 'when passing a PersonalSnippet' do - it 'returns a proper URL' do - personal_snippet = create(:personal_snippet) + context 'when passing a Snippet' do + let(:snippet) { build_stubbed(:personal_snippet) } - url = described_class.build(personal_snippet) + it 'returns a raw snippet URL if requested' do + url = subject.build(snippet, raw: true) - expect(url).to eq "#{Settings.gitlab['url']}/snippets/#{personal_snippet.id}" + expect(url).to eq "#{Gitlab.config.gitlab.url}/snippets/#{snippet.id}/raw" end end - context 'when passing a Note' do - context 'on a Commit' do - it 'returns a proper URL' do - note = build_stubbed(:note_on_commit) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" - end - end - - context 'on a Commit Diff' do - it 'returns a proper URL' do - note = build_stubbed(:diff_note_on_commit) - - url = described_class.build(note) + context 'when passing an unsupported class' do + let(:object) { Object.new } - expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.full_path}/-/commit/#{note.commit_id}#note_#{note.id}" - end + it 'raises an exception' do + expect { subject.build(object) }.to raise_error(NotImplementedError) end + end - context 'on an Issue' do - it 'returns a proper URL' do - issue = create(:issue, iid: 42) - note = build_stubbed(:note_on_issue, noteable: issue) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.full_path}/-/issues/#{issue.iid}#note_#{note.id}" - end - end - - context 'on a MergeRequest' do - it 'returns a proper URL' do - merge_request = create(:merge_request, iid: 42) - note = build_stubbed(:note_on_merge_request, noteable: merge_request) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}" - end - end - - context 'on a MergeRequest Diff' do - it 'returns a proper URL' do - merge_request = create(:merge_request, iid: 42) - note = build_stubbed(:diff_note_on_merge_request, noteable: merge_request) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.full_path}/-/merge_requests/#{merge_request.iid}#note_#{note.id}" - end - end - - context 'on a ProjectSnippet' do - it 'returns a proper URL' do - project_snippet = create(:project_snippet) - note = build_stubbed(:note_on_project_snippet, noteable: project_snippet) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/#{project_snippet.project.full_path}/snippets/#{note.noteable_id}#note_#{note.id}" - end - end - - context 'on a PersonalSnippet' do - it 'returns a proper URL' do - personal_snippet = create(:personal_snippet) - note = build_stubbed(:note_on_personal_snippet, noteable: personal_snippet) - - url = described_class.build(note) - - expect(url).to eq "#{Settings.gitlab['url']}/snippets/#{note.noteable_id}#note_#{note.id}" - end - end - - context 'on another object' do - it 'returns a proper URL' do - project = build_stubbed(:project) - - expect { described_class.build(project) } - .to raise_error(NotImplementedError, "No URL builder defined for #{project.inspect}") + context 'when passing a batch loaded model' do + let(:project) { build_stubbed(:project) } + let(:object) do + BatchLoader.for(:project).batch do |batch, loader| + batch.each { |_| loader.call(:project, project) } end end - end - - context 'when passing a WikiPage' do - it 'returns a proper URL' do - wiki_page = build(:wiki_page) - url = described_class.build(wiki_page) - expect(url).to eq "#{Gitlab.config.gitlab.url}#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}" + it 'returns the URL for the real object' do + expect(subject.build(object, only_path: true)).to eq("/#{project.full_path}") end end end diff --git a/spec/models/personal_snippet_spec.rb b/spec/models/personal_snippet_spec.rb index 4a949a75cbd..a055f107e33 100644 --- a/spec/models/personal_snippet_spec.rb +++ b/spec/models/personal_snippet_spec.rb @@ -21,8 +21,6 @@ describe PersonalSnippet do let_it_be(:container) { create(:personal_snippet, :repository) } let(:stubbed_container) { build_stubbed(:personal_snippet) } let(:expected_full_path) { "@snippets/#{container.id}" } - let(:expected_repository_klass) { Repository } - let(:expected_storage_klass) { Storage::Hashed } let(:expected_web_url_path) { "snippets/#{container.id}" } end end diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb index 09b4ec3677c..719a74f995d 100644 --- a/spec/models/project_snippet_spec.rb +++ b/spec/models/project_snippet_spec.rb @@ -37,8 +37,6 @@ describe ProjectSnippet do let_it_be(:container) { create(:project_snippet, :repository) } let(:stubbed_container) { build_stubbed(:project_snippet) } let(:expected_full_path) { "#{container.project.full_path}/@snippets/#{container.id}" } - let(:expected_repository_klass) { Repository } - let(:expected_storage_klass) { Storage::Hashed } let(:expected_web_url_path) { "#{container.project.full_path}/snippets/#{container.id}" } end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 0904ebca670..21c074cdce2 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -116,9 +116,6 @@ describe Project do let_it_be(:container) { create(:project, :repository, path: 'somewhere') } let(:stubbed_container) { build_stubbed(:project) } let(:expected_full_path) { "#{container.namespace.full_path}/somewhere" } - let(:expected_repository_klass) { Repository } - let(:expected_storage_klass) { Storage::Hashed } - let(:expected_web_url_path) { "#{container.namespace.full_path}/somewhere" } end it 'has an inverse relationship with merge requests' do diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 2d660d1deab..9f5fd3a9495 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -28,7 +28,7 @@ describe ProjectWiki do describe '#web_url' do it 'returns the full web URL to the wiki' do - expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}/-/wikis/home") + expect(subject.web_url).to eq(Gitlab::UrlBuilder.build(subject)) end end diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 9fa8f807330..86f37e9204c 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -1022,24 +1022,6 @@ describe NotificationService, :mailer do should_not_email(@u_lazy_participant) end - it 'emails new assignee' do - issue.assignees = [@u_mentioned] - notification.reassigned_issue(issue, @u_disabled, [@u_mentioned]) - - expect(issue.assignees.first).to be @u_mentioned - should_email(issue.assignees.first) - should_email(@u_watcher) - should_email(@u_guest_watcher) - should_email(@u_guest_custom) - should_email(@u_participant_mentioned) - should_email(@subscriber) - should_email(@u_custom_global) - should_not_email(@unsubscriber) - should_not_email(@u_participating) - should_not_email(@u_disabled) - should_not_email(@u_lazy_participant) - end - it 'does not email new assignee if they are the current user' do issue.assignees = [@u_mentioned] notification.reassigned_issue(issue, @u_mentioned, [@u_mentioned]) diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb index 9c88e741d51..05fb725c065 100644 --- a/spec/services/snippets/update_service_spec.rb +++ b/spec/services/snippets/update_service_spec.rb @@ -139,18 +139,80 @@ describe Snippets::UpdateService do subject end end + end - it 'returns error when the commit action fails' do - error_message = 'foobar' + shared_examples 'commit operation fails' do + let_it_be(:gitlab_shell) { Gitlab::Shell.new } - allow_next_instance_of(SnippetRepository) do |instance| - allow(instance).to receive(:multi_files_action).and_raise(SnippetRepository::CommitError, error_message) - end + before do + allow(service).to receive(:create_commit).and_raise(SnippetRepository::CommitError) + end + it 'returns error' do response = subject expect(response).to be_error - expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message + expect(response.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet' + end + + context 'when repository is empty' do + before do + allow(service).to receive(:repository_empty?).and_return(true) + end + + it 'destroys the created repository in disk' do + subject + + expect(gitlab_shell.repository_exists?(snippet.repository.storage, "#{snippet.disk_path}.git")).to be_falsey + end + + it 'destroys the SnippetRepository object' do + subject + + expect(snippet.reload.snippet_repository).to be_nil + end + + it 'expires the repository exists method cache' do + response = subject + + expect(response).to be_error + expect(response.payload[:snippet].repository_exists?).to be_falsey + end + end + + context 'when repository is not empty' do + before do + allow(service).to receive(:repository_empty?).and_return(false) + end + + it 'does not destroy the repository' do + subject + + expect(gitlab_shell.repository_exists?(snippet.repository.storage, "#{snippet.disk_path}.git")).to be_truthy + end + + it 'does not destroy the snippet repository' do + subject + + expect(snippet.reload.snippet_repository).not_to be_nil + end + + it 'expires the repository exists method cache' do + response = subject + + expect(response).to be_error + expect(response.payload[:snippet].repository_exists?).to be_truthy + end + end + + it 'rolls back any snippet modifications' do + option_keys = options.stringify_keys.keys + orig_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) } + + subject + + current_attrs = snippet.attributes.select { |k, v| k.in?(option_keys) } + expect(orig_attrs).to eq current_attrs end end @@ -186,12 +248,13 @@ describe Snippets::UpdateService do response = subject expect(response).to be_error - expect(response.payload[:snippet].errors[:repository].to_sentence).to eq error_message + expect(response.payload[:snippet].errors[:repository].to_sentence).to eq 'Error updating the snippet' end end it 'returns error if snippet does not have a snippet_repository' do allow(snippet).to receive(:snippet_repository).and_return(nil) + allow(snippet).to receive(:track_snippet_repository).and_return(nil) expect(subject).to be_error end @@ -219,11 +282,13 @@ describe Snippets::UpdateService do it_behaves_like 'public visibility level restrictions apply' it_behaves_like 'snippet update data is tracked' it_behaves_like 'updates repository content' + it_behaves_like 'commit operation fails' context 'when snippet does not have a repository' do let!(:snippet) { create(:project_snippet, author: user, project: project) } it_behaves_like 'creates repository and creates file' + it_behaves_like 'commit operation fails' end end @@ -235,11 +300,13 @@ describe Snippets::UpdateService do it_behaves_like 'public visibility level restrictions apply' it_behaves_like 'snippet update data is tracked' it_behaves_like 'updates repository content' + it_behaves_like 'commit operation fails' context 'when snippet does not have a repository' do let!(:snippet) { create(:personal_snippet, author: user, project: project) } it_behaves_like 'creates repository and creates file' + it_behaves_like 'commit operation fails' end end end diff --git a/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb b/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb index 368ec0694fd..41de499f590 100644 --- a/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb @@ -1,6 +1,11 @@ # frozen_string_literal: true RSpec.shared_examples 'model with repository' do + let(:container) { raise NotImplementedError } + let(:stubbed_container) { raise NotImplementedError } + let(:expected_full_path) { raise NotImplementedError } + let(:expected_web_url_path) { expected_full_path } + describe '#commits_by' do let(:commits) { container.repository.commits('HEAD', limit: 3).commits } let(:commit_shas) { commits.map(&:id) } @@ -46,74 +51,33 @@ RSpec.shared_examples 'model with repository' do end end - describe '#ssh_url_to_repo' do - it 'returns container ssh address' do - expect(container.ssh_url_to_repo).to eq container.url_to_repo + describe '#url_to_repo' do + it 'returns the SSH URL to the repository' do + expect(container.url_to_repo).to eq("#{Gitlab.config.gitlab_shell.ssh_path_prefix}#{expected_web_url_path}.git") end end - describe '#http_url_to_repo' do - subject { container.http_url_to_repo } - - context 'when a custom HTTP clone URL root is not set' do - it 'returns the url to the repo without a username' do - expect(subject).to eq("#{container.web_url}.git") - expect(subject).not_to include('@') - end + describe '#ssh_url_to_repo' do + it 'returns the SSH URL to the repository' do + expect(container.ssh_url_to_repo).to eq(container.url_to_repo) end + end - context 'when a custom HTTP clone URL root is set' do - before do - stub_application_setting(custom_http_clone_url_root: custom_http_clone_url_root) - end - - context 'when custom HTTP clone URL root has a relative URL root' do - context 'when custom HTTP clone URL root ends with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab/' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(subject).to eq("#{custom_http_clone_url_root}#{expected_web_url_path}.git") - end - end - - context 'when custom HTTP clone URL root does not end with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/mygitlab' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(subject).to eq("#{custom_http_clone_url_root}/#{expected_web_url_path}.git") - end - end - end - - context 'when custom HTTP clone URL root does not have a relative URL root' do - context 'when custom HTTP clone URL root ends with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234/' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(subject).to eq("#{custom_http_clone_url_root}#{expected_web_url_path}.git") - end - end - - context 'when custom HTTP clone URL root does not end with a slash' do - let(:custom_http_clone_url_root) { 'https://git.example.com:51234' } - - it 'returns the url to the repo, with the root replaced with the custom one' do - expect(subject).to eq("#{custom_http_clone_url_root}/#{expected_web_url_path}.git") - end - end - end + describe '#http_url_to_repo' do + it 'returns the HTTP URL to the repository' do + expect(container.http_url_to_repo).to eq("#{Gitlab.config.gitlab.url}/#{expected_web_url_path}.git") end end describe '#repository' do it 'returns valid repo' do - expect(container.repository).to be_kind_of(expected_repository_klass) + expect(container.repository).to be_kind_of(Repository) end end describe '#storage' do it 'returns valid storage' do - expect(container.storage).to be_kind_of(expected_storage_klass) + expect(container.storage).to be_kind_of(Storage::Hashed) end end |