]> git.openstreetmap.org Git - rails.git/blob - test/abilities/changeset_comment_api_capability_test.rb
Merge remote-tracking branch 'upstream/pull/6787'
[rails.git] / test / abilities / changeset_comment_api_capability_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class ChangesetCommentApiCapabilityTest < ActiveSupport::TestCase
6   test "as a normal user without scopes" do
7     user = create(:user)
8     scopes = Set.new
9     ability = ApiAbility.new user, scopes
10
11     assert ability.cannot? :create, ChangesetComment
12     assert ability.cannot? :create, :changeset_comment_visibility
13     assert ability.cannot? :destroy, :changeset_comment_visibility
14   end
15
16   test "as a normal user with write_changeset_comments scope" do
17     user = create(:user)
18     scopes = Set.new %w[write_changeset_comments]
19     ability = ApiAbility.new user, scopes
20
21     assert ability.can? :create, ChangesetComment
22     assert ability.cannot? :create, :changeset_comment_visibility
23     assert ability.cannot? :destroy, :changeset_comment_visibility
24   end
25
26   test "as a moderator without scopes" do
27     user = create(:moderator_user)
28     scopes = Set.new
29     ability = ApiAbility.new user, scopes
30
31     assert ability.cannot? :create, ChangesetComment
32     assert ability.cannot? :create, :changeset_comment_visibility
33     assert ability.cannot? :destroy, :changeset_comment_visibility
34   end
35
36   test "as a moderator with write_changeset_comments scope" do
37     user = create(:moderator_user)
38     scopes = Set.new %w[write_changeset_comments]
39     ability = ApiAbility.new user, scopes
40
41     assert ability.can? :create, ChangesetComment
42     assert ability.can? :create, :changeset_comment_visibility
43     assert ability.can? :destroy, :changeset_comment_visibility
44   end
45 end