summaryrefslogtreecommitdiff
path: root/spec/presenters
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-10 07:53:40 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-10 07:53:40 +0000
commitcfc792b9ca064990e6540cb742e80529ea669a81 (patch)
tree147cd4256319990cebbc02fe8e4fbbbe06f5720a /spec/presenters
parent93c6764dacd4c605027ef1cd367d3aebe420b223 (diff)
downloadgitlab-ce-cfc792b9ca064990e6540cb742e80529ea669a81.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/presenters')
-rw-r--r--spec/presenters/snippet_presenter_spec.rb130
1 files changed, 130 insertions, 0 deletions
diff --git a/spec/presenters/snippet_presenter_spec.rb b/spec/presenters/snippet_presenter_spec.rb
new file mode 100644
index 00000000000..d874dbcc279
--- /dev/null
+++ b/spec/presenters/snippet_presenter_spec.rb
@@ -0,0 +1,130 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe SnippetPresenter do
+ include Gitlab::Routing.url_helpers
+
+ let_it_be(:user) { create(:user) }
+ let_it_be(:personal_snippet) { create(:personal_snippet, author: user) }
+ let_it_be(:project_snippet) { create(:project_snippet, author: user) }
+
+ let(:project) { project_snippet.project }
+ let(:presenter) { described_class.new(snippet, current_user: user) }
+
+ before do
+ project.add_developer(user)
+ end
+
+ describe '#web_url' do
+ subject { presenter.web_url }
+
+ context 'with PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it 'returns snippet web url' do
+ expect(subject).to match "/snippets/#{snippet.id}"
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'returns snippet web url' do
+ expect(subject).to match "/#{project.full_path}/snippets/#{snippet.id}"
+ end
+ end
+ end
+
+ describe '#raw_url' do
+ subject { presenter.raw_url }
+
+ context 'with PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it 'returns snippet web url' do
+ expect(subject).to match "/snippets/#{snippet.id}/raw"
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'returns snippet web url' do
+ expect(subject).to match "/#{project.full_path}/snippets/#{snippet.id}/raw"
+ end
+ end
+ end
+
+ describe '#can_read_snippet?' do
+ subject { presenter.can_read_snippet? }
+
+ context 'with PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it 'checks read_personal_snippet' do
+ expect(presenter).to receive(:can?).with(user, :read_personal_snippet, snippet)
+
+ subject
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'checks read_project_snippet ' do
+ expect(presenter).to receive(:can?).with(user, :read_project_snippet, snippet)
+
+ subject
+ end
+ end
+ end
+
+ describe '#can_update_snippet?' do
+ subject { presenter.can_update_snippet? }
+
+ context 'with PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it 'checks update_personal_snippet' do
+ expect(presenter).to receive(:can?).with(user, :update_personal_snippet, snippet)
+
+ subject
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'checks update_project_snippet ' do
+ expect(presenter).to receive(:can?).with(user, :update_project_snippet, snippet)
+
+ subject
+ end
+ end
+ end
+
+ describe '#can_admin_snippet?' do
+ subject { presenter.can_admin_snippet? }
+
+ context 'with PersonalSnippet' do
+ let(:snippet) { personal_snippet }
+
+ it 'checks admin_personal_snippet' do
+ expect(presenter).to receive(:can?).with(user, :admin_personal_snippet, snippet)
+
+ subject
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ let(:snippet) { project_snippet }
+
+ it 'checks admin_project_snippet ' do
+ expect(presenter).to receive(:can?).with(user, :admin_project_snippet, snippet)
+
+ subject
+ end
+ end
+ end
+end