]> git.openstreetmap.org Git - rails.git/blob - test/abilities/note_api_capability_test.rb
Merge remote-tracking branch 'upstream/pull/6787'
[rails.git] / test / abilities / note_api_capability_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class NoteApiCapabilityTest < 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     [:create, :comment, :close, :reopen, :destroy].each do |action|
12       assert ability.cannot? action, Note
13     end
14   end
15
16   test "as a normal user with write_notes scope" do
17     user = create(:user)
18     scopes = Set.new %w[write_notes]
19     ability = ApiAbility.new user, scopes
20
21     [:destroy].each do |action|
22       assert ability.cannot? action, Note
23     end
24
25     [:create, :comment, :close, :reopen].each do |action|
26       assert ability.can? action, Note
27     end
28   end
29
30   test "as a moderator without scopes" do
31     user = create(:moderator_user)
32     scopes = Set.new
33     ability = ApiAbility.new user, scopes
34
35     [:destroy].each do |action|
36       assert ability.cannot? action, Note
37     end
38   end
39
40   test "as a moderator with write_notes scope" do
41     user = create(:moderator_user)
42     scopes = Set.new %w[write_notes]
43     ability = ApiAbility.new user, scopes
44
45     [:destroy].each do |action|
46       assert ability.can? action, Note
47     end
48   end
49 end