summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 09:06:07 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-08 09:06:07 +0000
commitd23b2a0871f3ca507aafa949e0314625f1f0c6a7 (patch)
treeb1e26c7460bdae25f19103e14978a3aaeef52037 /spec/helpers
parent1ef4b65f55f4fc6524a47050b4f6d686beb81d3a (diff)
downloadgitlab-ce-d23b2a0871f3ca507aafa949e0314625f1f0c6a7.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/snippets_helper_spec.rb206
1 files changed, 195 insertions, 11 deletions
diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb
index 66c8d576a4c..d88e151a11c 100644
--- a/spec/helpers/snippets_helper_spec.rb
+++ b/spec/helpers/snippets_helper_spec.rb
@@ -3,33 +3,217 @@
require 'spec_helper'
describe SnippetsHelper do
+ include Gitlab::Routing
include IconsHelper
- describe '#embedded_snippet_raw_button' do
- it 'gives view raw button of embedded snippets for project snippets' do
- @snippet = create(:project_snippet, :public)
+ let_it_be(:public_personal_snippet) { create(:personal_snippet, :public) }
+ let_it_be(:public_project_snippet) { create(:project_snippet, :public) }
+
+ describe '#reliable_snippet_path' do
+ subject { reliable_snippet_path(snippet) }
+
+ context 'personal snippets' do
+ let(:snippet) { public_personal_snippet }
+
+ context 'public' do
+ it 'returns a full path' do
+ expect(subject).to eq("/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ context 'project snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns a full path' do
+ expect(subject).to eq("/#{snippet.project.full_path}/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ describe '#reliable_snippet_url' do
+ subject { reliable_snippet_url(snippet) }
+
+ context 'personal snippets' do
+ let(:snippet) { public_personal_snippet }
+
+ context 'public' do
+ it 'returns a full url' do
+ expect(subject).to eq("http://test.host/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ context 'project snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns a full url' do
+ expect(subject).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ describe '#reliable_raw_snippet_path' do
+ subject { reliable_raw_snippet_path(snippet) }
+
+ context 'personal snippets' do
+ let(:snippet) { public_personal_snippet }
- expect(embedded_snippet_raw_button.to_s).to eq("<a class=\"btn\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"Open raw\" href=\"#{raw_project_snippet_url(@snippet.project, @snippet)}\">#{external_snippet_icon('doc-code')}</a>")
+ context 'public' do
+ it 'returns a full path' do
+ expect(subject).to eq("/snippets/#{snippet.id}/raw")
+ end
+ end
end
- it 'gives view raw button of embedded snippets for personal snippets' do
+ context 'project snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns a full path' do
+ expect(subject).to eq("/#{snippet.project.full_path}/snippets/#{snippet.id}/raw")
+ end
+ end
+ end
+
+ describe '#reliable_raw_snippet_url' do
+ subject { reliable_raw_snippet_url(snippet) }
+
+ context 'personal snippets' do
+ let(:snippet) { public_personal_snippet }
+
+ context 'public' do
+ it 'returns a full url' do
+ expect(subject).to eq("http://test.host/snippets/#{snippet.id}/raw")
+ end
+ end
+ end
+
+ context 'project snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns a full url' do
+ expect(subject).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}/raw")
+ end
+ end
+ end
+
+ describe '#embedded_raw_snippet_button' do
+ subject { embedded_raw_snippet_button.to_s }
+
+ it 'returns view raw button of embedded snippets for personal snippets' do
@snippet = create(:personal_snippet, :public)
- expect(embedded_snippet_raw_button.to_s).to eq("<a class=\"btn\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"Open raw\" href=\"#{raw_snippet_url(@snippet)}\">#{external_snippet_icon('doc-code')}</a>")
+ expect(subject).to eq(download_link("http://test.host/snippets/#{@snippet.id}/raw"))
+ end
+
+ it 'returns view raw button of embedded snippets for project snippets' do
+ @snippet = create(:project_snippet, :public)
+
+ expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
+ end
+
+ def download_link(url)
+ "<a class=\"btn\" target=\"_blank\" rel=\"noopener noreferrer\" title=\"Open raw\" href=\"#{url}\">#{external_snippet_icon('doc-code')}</a>"
end
end
describe '#embedded_snippet_download_button' do
- it 'gives download button of embedded snippets for project snippets' do
+ subject { embedded_snippet_download_button }
+
+ it 'returns download button of embedded snippets for personal snippets' do
+ @snippet = create(:personal_snippet, :public)
+
+ expect(subject).to eq(download_link("http://test.host/snippets/#{@snippet.id}/raw"))
+ end
+
+ it 'returns download button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public)
- expect(embedded_snippet_download_button.to_s).to eq("<a class=\"btn\" target=\"_blank\" title=\"Download\" rel=\"noopener noreferrer\" href=\"#{raw_project_snippet_url(@snippet.project, @snippet, inline: false)}\">#{external_snippet_icon('download')}</a>")
+ expect(subject).to eq(download_link("http://test.host/#{@snippet.project.path_with_namespace}/snippets/#{@snippet.id}/raw"))
end
- it 'gives download button of embedded snippets for personal snippets' do
- @snippet = create(:personal_snippet, :public)
+ def download_link(url)
+ "<a class=\"btn\" target=\"_blank\" title=\"Download\" rel=\"noopener noreferrer\" href=\"#{url}?inline=false\">#{external_snippet_icon('download')}</a>"
+ end
+ end
+
+ describe '#snippet_embed_tag' do
+ subject { snippet_embed_tag(snippet) }
+
+ context 'personal snippets' do
+ let(:snippet) { public_personal_snippet }
+
+ context 'public' do
+ it 'returns a script tag with the snippet full url' do
+ expect(subject).to eq(script_embed("http://test.host/snippets/#{snippet.id}"))
+ end
+ end
+ end
+
+ context 'project snippets' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns a script tag with the snippet full url' do
+ expect(subject).to eq(script_embed("http://test.host/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}"))
+ end
+ end
+
+ def script_embed(url)
+ "<script src=\"#{url}.js\"></script>"
+ end
+ end
+
+ describe '#download_raw_snippet_button' do
+ subject { download_raw_snippet_button(snippet) }
+
+ context 'with personal snippet' do
+ let(:snippet) { public_personal_snippet }
+
+ it 'returns the download button' do
+ expect(subject).to eq(download_link("/snippets/#{snippet.id}/raw"))
+ end
+ end
+
+ context 'with project snippet' do
+ let(:snippet) { public_project_snippet }
+
+ it 'returns the download button' do
+ expect(subject).to eq(download_link("/#{snippet.project.path_with_namespace}/snippets/#{snippet.id}/raw"))
+ end
+ end
+
+ def download_link(url)
+ "<a target=\"_blank\" rel=\"noopener noreferrer\" class=\"btn btn-sm has-tooltip\" title=\"Download\" data-container=\"body\" href=\"#{url}?inline=false\"><i aria-hidden=\"true\" data-hidden=\"true\" class=\"fa fa-download\"></i></a>"
+ end
+ end
+
+ describe '#snippet_badge' do
+ let(:snippet) { build(:personal_snippet, visibility) }
+
+ subject { snippet_badge(snippet) }
+
+ context 'when snippet is private' do
+ let(:visibility) { :private }
+
+ it 'returns the snippet badge' do
+ expect(subject).to eq "<span class=\"badge badge-gray\"><i class=\"fa fa-lock\"></i> private</span>"
+ end
+ end
+
+ context 'when snippet is public' do
+ let(:visibility) { :public }
+
+ it 'does not return anything' do
+ expect(subject).to be_nil
+ end
+ end
+
+ context 'when snippet is internal' do
+ let(:visibility) { :internal }
- expect(embedded_snippet_download_button.to_s).to eq("<a class=\"btn\" target=\"_blank\" title=\"Download\" rel=\"noopener noreferrer\" href=\"#{raw_snippet_url(@snippet, inline: false)}\">#{external_snippet_icon('download')}</a>")
+ it 'does not return anything' do
+ expect(subject).to be_nil
+ end
end
end
end