summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/url_builder_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 12:26:25 +0000
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/url_builder_spec.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
downloadgitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/url_builder_spec.rb')
-rw-r--r--spec/lib/gitlab/url_builder_spec.rb39
1 files changed, 34 insertions, 5 deletions
diff --git a/spec/lib/gitlab/url_builder_spec.rb b/spec/lib/gitlab/url_builder_spec.rb
index e91d17bfbe8..a16ff252bc1 100644
--- a/spec/lib/gitlab/url_builder_spec.rb
+++ b/spec/lib/gitlab/url_builder_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::UrlBuilder do
+RSpec.describe Gitlab::UrlBuilder do
subject { described_class }
describe '#build' do
@@ -87,12 +87,41 @@ describe Gitlab::UrlBuilder do
end
context 'when passing a Snippet' do
- let(:snippet) { build_stubbed(:personal_snippet) }
+ let_it_be(:personal_snippet) { create(:personal_snippet, :repository) }
+ let_it_be(:project_snippet) { create(:project_snippet, :repository) }
+ let(:blob) { snippet.blobs.first }
+ let(:ref) { blob.repository.root_ref }
- it 'returns a raw snippet URL if requested' do
- url = subject.build(snippet, raw: true)
+ context 'for a PersonalSnippet' do
+ let(:snippet) { personal_snippet }
- expect(url).to eq "#{Gitlab.config.gitlab.url}/snippets/#{snippet.id}/raw"
+ it 'returns a raw snippet URL if requested' do
+ url = subject.build(snippet, raw: true)
+
+ expect(url).to eq "#{Gitlab.config.gitlab.url}/snippets/#{snippet.id}/raw"
+ end
+
+ it 'returns a raw snippet blob URL if requested' do
+ url = subject.build(snippet, file: blob.path, ref: ref)
+
+ expect(url).to eq "#{Gitlab.config.gitlab.url}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"
+ end
+ end
+
+ context 'for a ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'returns a raw snippet URL if requested' do
+ url = subject.build(snippet, raw: true)
+
+ expect(url).to eq "#{Gitlab.config.gitlab.url}/#{snippet.project.full_path}/snippets/#{snippet.id}/raw"
+ end
+
+ it 'returns a raw snippet blob URL if requested' do
+ url = subject.build(snippet, file: blob.path, ref: ref)
+
+ expect(url).to eq "#{Gitlab.config.gitlab.url}/#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}"
+ end
end
end