debian-mirror-gitlab/spec/policies/personal_snippet_policy_spec.rb

142 lines
3.7 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe PersonalSnippetPolicy do
2017-08-17 22:00:37 +05:30
let(:regular_user) { create(:user) }
let(:external_user) { create(:user, :external) }
let(:admin_user) { create(:user, :admin) }
let(:author_permissions) do
[
:update_personal_snippet,
:admin_personal_snippet,
:destroy_personal_snippet
]
end
def permissions(user)
2017-09-10 17:25:29 +05:30
described_class.new(user, snippet)
2017-08-17 22:00:37 +05:30
end
context 'public snippet' do
let(:snippet) { create(:personal_snippet, :public) }
context 'no user' do
subject { permissions(nil) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'author' do
subject { permissions(snippet.author) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:comment_personal_snippet)
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
context 'internal snippet' do
let(:snippet) { create(:personal_snippet, :internal) }
context 'no user' do
subject { permissions(nil) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
subject { permissions(external_user) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'snippet author' do
subject { permissions(snippet.author) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:comment_personal_snippet)
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
context 'private snippet' do
let(:snippet) { create(:project_snippet, :private) }
context 'no user' do
subject { permissions(nil) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'regular user' do
subject { permissions(regular_user) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'external user' do
subject { permissions(external_user) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_disallowed(:read_personal_snippet)
is_expected.to be_disallowed(:comment_personal_snippet)
is_expected.to be_disallowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
context 'snippet author' do
subject { permissions(snippet.author) }
it do
2017-09-10 17:25:29 +05:30
is_expected.to be_allowed(:read_personal_snippet)
is_expected.to be_allowed(:comment_personal_snippet)
is_expected.to be_allowed(*author_permissions)
2017-08-17 22:00:37 +05:30
end
end
end
end