diff options
author | James Lopez <james@jameslopez.es> | 2016-11-15 15:27:50 +0100 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-11-17 08:22:58 +0100 |
commit | f93607a305346607f4296c266d40be1692febbec (patch) | |
tree | 945b639dc0a1a8d5ef741991ccf16ba3c2e9a066 /spec | |
parent | ca6da6ea3034a58c0edbc62336d2d49ea6e11fc9 (diff) | |
download | gitlab-ce-f93607a305346607f4296c266d40be1692febbec.tar.gz |
get rid of light url builder and fix wrong spec
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab/url_builder_spec.rb | 137 |
1 files changed, 91 insertions, 46 deletions
diff --git a/spec/lib/gitlab/url_builder_spec.rb b/spec/lib/gitlab/url_builder_spec.rb index 5d876fdb603..a826b24419a 100644 --- a/spec/lib/gitlab/url_builder_spec.rb +++ b/spec/lib/gitlab/url_builder_spec.rb @@ -1,74 +1,119 @@ require 'spec_helper' -describe Gitlab::LightUrlBuilder, lib: true do - context 'when passing a Commit' do - it 'returns a proper URL' do - commit = build_stubbed(:commit) +describe Gitlab::UrlBuilder, lib: true do + describe '.build' do + context 'when passing a Commit' do + it 'returns a proper URL' do + commit = build_stubbed(:commit) - url = described_class.build(entity: :commit, project: commit.project, id: commit.id) + url = described_class.build(commit) - expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.path_with_namespace}/commit/#{commit.id}" + expect(url).to eq "#{Settings.gitlab['url']}/#{commit.project.path_with_namespace}/commit/#{commit.id}" + end end - end - context 'when passing an Issue' do - it 'returns a proper URL' do - issue = build_stubbed(:issue, iid: 42) + context 'when passing an Issue' do + it 'returns a proper URL' do + issue = build_stubbed(:issue, iid: 42) - url = described_class.build(entity: :issue, project: issue.project, id: issue.iid) + url = described_class.build(issue) - expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}" + expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/issues/#{issue.iid}" + end 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 MergeRequest' do + it 'returns a proper URL' do + merge_request = build_stubbed(:merge_request, iid: 42) - url = described_class.build(entity: :merge_request, project: merge_request.project, id: merge_request.iid) + url = described_class.build(merge_request) - expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}" + expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/merge_requests/#{merge_request.iid}" + end end - end - context 'when passing a build' do - it 'returns a proper URL' do - build = build_stubbed(:ci_build, project: build_stubbed(:empty_project)) + 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(entity: :build, project: build.project, id: build.id) + url = described_class.build(note) - expect(url).to eq "#{Settings.gitlab['url']}/#{build.project.path_with_namespace}/builds/#{build.id}" - end - end + expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}" + end + end - context 'when passing a branch' do - it 'returns a proper URL' do - branch = 'branch_name' - project = build_stubbed(:empty_project) + context 'on a Commit Diff' do + it 'returns a proper URL' do + note = build_stubbed(:diff_note_on_commit) - url = described_class.build(entity: :branch, project: project, id: branch) + url = described_class.build(note) - expect(url).to eq "#{Settings.gitlab['url']}/#{project.path_with_namespace}/commits/#{branch}" - end - end + expect(url).to eq "#{Settings.gitlab['url']}/#{note.project.path_with_namespace}/commit/#{note.commit_id}#note_#{note.id}" + end + end - context 'on a User' do - it 'returns a proper URL' do - user = build_stubbed(:user) + 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(entity: :user, id: user.username) + url = described_class.build(note) - expect(url).to eq "#{Settings.gitlab['url']}/#{user.username}" - end - end + expect(url).to eq "#{Settings.gitlab['url']}/#{issue.project.path_with_namespace}/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) - context 'on a user avatar' do - it 'returns a proper URL' do - user = create(:user) + url = described_class.build(note) + + expect(url).to eq "#{Settings.gitlab['url']}/#{merge_request.project.path_with_namespace}/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.path_with_namespace}/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.path_with_namespace}/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') + end + end + end - url = described_class.build(entity: :user_avatar, id: user.id) + 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 user.avatar_url + expect(url).to eq "#{Gitlab.config.gitlab.url}#{wiki_page.wiki.wiki_base_path}/#{wiki_page.slug}" + end end end end |