diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2018-12-27 17:46:38 +1100 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-09-11 14:53:13 +1000 |
commit | 0e31b424fb9a07ea5ba8f6d864ff726533e8ba85 (patch) | |
tree | ac192e1c9f50ed114e332f81303621a1134af49b /spec/models/snippet_spec.rb | |
parent | bd7e1e554b3d68f31bc1f8b23e568a9950d597e0 (diff) | |
download | gitlab-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/models/snippet_spec.rb')
-rw-r--r-- | spec/models/snippet_spec.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 3524cdae3b8..0d47041ded4 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -462,4 +462,44 @@ describe Snippet do end end end + + describe '#ensure_secret_added_if_needed' do + let(:snippet) { create(:snippet) } + + context 'visibility_level is NOT SECRET' do + it 'assigns a random hex value' do + snippet.visibility_level = Gitlab::VisibilityLevel::PUBLIC + snippet.save + expect(snippet.secret).to be_nil + end + end + + context 'visibility_level is SECRET' do + it 'assigns a random hex value' do + snippet.visibility_level = Gitlab::VisibilityLevel::SECRET + snippet.save + expect(snippet.secret).not_to be_nil + end + end + end + + describe '#visibility_secret?' do + let(:snippet) { create(:snippet) } + + context 'for a Snippet that is not Secret' do + it 'returns false' do + snippet.visibility_level = Gitlab::VisibilityLevel::PUBLIC + snippet.save + expect(snippet.visibility_secret?).to be_falsey + end + end + + context 'for a Snippet that is Secret' do + it 'returns true' do + snippet.visibility_level = Gitlab::VisibilityLevel::SECRET + snippet.save + expect(snippet.visibility_secret?).to be_truthy + end + end + end end |