Skip to content

Commit

Permalink
[webui][ci] Add comment policy test for nobody
Browse files Browse the repository at this point in the history
- Add test for "nobody" user. He cannot destroy any comment.
- The initialize method is not needed. It is as ApplicationPolicy.
  • Loading branch information
eduardoj authored and Moisés Déniz Alemán committed Oct 25, 2017
1 parent 9be339d commit 3e122b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/api/app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def initialize(user, record)

def destroy?
return false if @user.blank?

# Admins can always delete all comments
return true if @user.is_admin?

Expand Down
8 changes: 7 additions & 1 deletion src/api/spec/policies/comment_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
require "rails_helper"

RSpec.describe CommentPolicy do
subject { CommentPolicy }
let(:anonymous_user) { create(:user_nobody) }
let(:comment_author) { create(:confirmed_user, login: 'burdenski') }
let(:admin_user) { create(:admin_user, login: 'admin') }
let(:user) { create(:confirmed_user, login: 'tom') }
let(:project) { create(:project, name: 'CommentableProject') }
let(:comment) { create(:comment_project, commentable: project, user: comment_author) }

subject { CommentPolicy }

permissions :destroy? do
it 'Not logged users cannot destroy comments' do
expect(subject).not_to permit(nil, comment)
end

it 'Users can destroy their own comments' do
expect(subject).to permit(comment_author, comment)
end
Expand Down

0 comments on commit 3e122b1

Please sign in to comment.