summaryrefslogtreecommitdiff
path: root/spec/helpers/snippets_helper_spec.rb
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-12-27 17:46:38 +1100
committerAsh McKenzie <amckenzie@gitlab.com>2019-09-11 14:53:13 +1000
commit0e31b424fb9a07ea5ba8f6d864ff726533e8ba85 (patch)
treeac192e1c9f50ed114e332f81303621a1134af49b /spec/helpers/snippets_helper_spec.rb
parentbd7e1e554b3d68f31bc1f8b23e568a9950d597e0 (diff)
downloadgitlab-ce-13235-secret-snippets.tar.gz
Add Secret support for Snippets13235-secret-snippets
Snippets can now be created as type Secret which are non-searched Snippets that can accessed publicly if the correct secret_word is known.
Diffstat (limited to 'spec/helpers/snippets_helper_spec.rb')
-rw-r--r--spec/helpers/snippets_helper_spec.rb88
1 files changed, 86 insertions, 2 deletions
diff --git a/spec/helpers/snippets_helper_spec.rb b/spec/helpers/snippets_helper_spec.rb
index ce5e037f88d..8f54605e8e8 100644
--- a/spec/helpers/snippets_helper_spec.rb
+++ b/spec/helpers/snippets_helper_spec.rb
@@ -3,7 +3,91 @@ require 'spec_helper'
describe SnippetsHelper do
include IconsHelper
- describe '#embedded_snippet_raw_button' do
+ describe '.reliable_snippet_path' do
+ context 'personal snippets' do
+ context 'public' do
+ it 'gives a full path' do
+ snippet = create(:personal_snippet, :public)
+
+ expect(reliable_snippet_path(snippet)).to eq("/snippets/#{snippet.id}")
+ end
+ end
+
+ context 'secret' do
+ it 'gives a full path, including secret word' do
+ snippet = create(:personal_snippet, :secret)
+
+ expect(reliable_snippet_path(snippet)).to match(%r{/snippets/#{snippet.id}\?secret=\w+})
+ end
+ end
+ end
+
+ context 'project snippets' do
+ it 'gives a full path' do
+ snippet = create(:project_snippet, :public)
+
+ expect(reliable_snippet_path(snippet)).to eq("/#{snippet.project.full_path}/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ describe '.reliable_snippet_url' do
+ context 'personal snippets' do
+ context 'public' do
+ it 'gives a full url' do
+ snippet = create(:personal_snippet, :public)
+
+ expect(reliable_snippet_url(snippet)).to eq("http://test.host/snippets/#{snippet.id}")
+ end
+ end
+
+ context 'secret' do
+ it 'gives a full url, including secret word' do
+ snippet = create(:personal_snippet, :secret)
+
+ expect(reliable_snippet_url(snippet)).to match(%r{http://test.host/snippets/#{snippet.id}\?secret=\w+})
+ end
+ end
+ end
+
+ context 'project snippets' do
+ it 'gives a full url' do
+ snippet = create(:project_snippet, :public)
+
+ expect(reliable_snippet_url(snippet)).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ describe '.shareable_snippets_link' do
+ context 'personal snippets' do
+ context 'public' do
+ it 'gives a full link' do
+ snippet = create(:personal_snippet, :public)
+
+ expect(reliable_snippet_url(snippet)).to eq("http://test.host/snippets/#{snippet.id}")
+ end
+ end
+
+ context 'secret' do
+ it 'gives a full link, including secret word' do
+ snippet = create(:personal_snippet, :secret)
+
+ expect(reliable_snippet_url(snippet)).to match(%r{http://test.host/snippets/#{snippet.id}\?secret=\w+})
+ end
+ end
+ end
+
+ context 'project snippets' do
+ it 'gives a full link' do
+ snippet = create(:project_snippet, :public)
+
+ expect(reliable_snippet_url(snippet)).to eq("http://test.host/#{snippet.project.full_path}/snippets/#{snippet.id}")
+ end
+ end
+ end
+
+ describe '.embedded_snippet_raw_button' do
it 'gives view raw button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public)
@@ -17,7 +101,7 @@ describe SnippetsHelper do
end
end
- describe '#embedded_snippet_download_button' do
+ describe '.embedded_snippet_download_button' do
it 'gives download button of embedded snippets for project snippets' do
@snippet = create(:project_snippet, :public)