diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2019-03-04 21:37:08 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2019-03-04 21:37:08 +0300 |
commit | 5169dafccf70bf50d780bfdbeea0802f094520cc (patch) | |
tree | 5cab3938be5142156c93ab5a9913d1e9fc6b1529 /spec/policies/commit_policy_spec.rb | |
parent | 9faf957bd3cfc5cdc248c3e862579902cc1da39c (diff) |
Forbid creating discussions for users with restricted access
Diffstat (limited to 'spec/policies/commit_policy_spec.rb')
-rw-r--r-- | spec/policies/commit_policy_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/policies/commit_policy_spec.rb b/spec/policies/commit_policy_spec.rb new file mode 100644 index 00000000000..2259693cf01 --- /dev/null +++ b/spec/policies/commit_policy_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe CommitPolicy do + describe '#rules' do + let(:user) { create(:user) } + let(:commit) { project.repository.head_commit } + let(:policy) { described_class.new(user, commit) } + + context 'when project is public' do + let(:project) { create(:project, :public, :repository) } + + it 'can read commit and create a note' do + expect(policy).to be_allowed(:read_commit) + end + + context 'when repository access level is private' do + let(:project) { create(:project, :public, :repository, :repository_private) } + + it 'can not read commit and create a note' do + expect(policy).to be_disallowed(:read_commit) + end + + context 'when the user is a project member' do + before do + project.add_developer(user) + end + + it 'can read commit and create a note' do + expect(policy).to be_allowed(:read_commit) + end + end + end + end + + context 'when project is private' do + let(:project) { create(:project, :private, :repository) } + + it 'can not read commit and create a note' do + expect(policy).to be_disallowed(:read_commit) + end + + context 'when the user is a project member' do + before do + project.add_developer(user) + end + + it 'can read commit and create a note' do + expect(policy).to be_allowed(:read_commit) + end + end + end + end +end |