2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
# Snippet visibility scenarios are included in more details in spec/support/snippet_visibility.rb
|
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
|
|
|
|
|
2019-02-02 18:00:53 +05:30
|
|
|
let(:comment_permissions) do
|
|
|
|
[
|
|
|
|
:comment_personal_snippet,
|
|
|
|
:create_note
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_allowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_allowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_allowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_allowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_allowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_allowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_allowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_allowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
is_expected.to be_disallowed(*author_permissions)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-02 22:35:43 +05:30
|
|
|
context 'admin user' do
|
|
|
|
subject { permissions(admin_user) }
|
|
|
|
|
|
|
|
it do
|
|
|
|
is_expected.to be_allowed(:read_personal_snippet)
|
|
|
|
is_expected.to be_disallowed(:comment_personal_snippet)
|
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
|
|
|
is_expected.to be_disallowed(*author_permissions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_disallowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_disallowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
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)
|
2019-02-02 18:00:53 +05:30
|
|
|
is_expected.to be_allowed(*comment_permissions)
|
2018-05-09 12:01:36 +05:30
|
|
|
is_expected.to be_allowed(:award_emoji)
|
2017-09-10 17:25:29 +05:30
|
|
|
is_expected.to be_allowed(*author_permissions)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|