]> git.openstreetmap.org Git - rails.git/blob - test/abilities/api_abilities_test.rb
Merge pull request #5691 from tomhughes/system-test-clear-deliveries
[rails.git] / test / abilities / api_abilities_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class ApiAbilityTest < ActiveSupport::TestCase
6 end
7
8 class GuestApiAbilityTest < ApiAbilityTest
9   test "note permissions for a guest" do
10     scopes = Set.new
11     ability = ApiAbility.new nil, scopes
12
13     [:index, :create, :feed, :show, :search].each do |action|
14       assert ability.can?(action, Note), "should be able to #{action} Notes"
15     end
16
17     [:comment, :close, :reopen, :destroy].each do |action|
18       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
19     end
20   end
21 end
22
23 class UserApiAbilityTest < ApiAbilityTest
24   test "Note permissions" do
25     user = create(:user)
26     scopes = Set.new %w[write_notes]
27     ability = ApiAbility.new user, scopes
28
29     [:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
30       assert ability.can?(action, Note), "should be able to #{action} Notes"
31     end
32
33     [:destroy].each do |action|
34       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
35     end
36   end
37 end
38
39 class ModeratorApiAbilityTest < ApiAbilityTest
40   test "Note permissions" do
41     user = create(:moderator_user)
42     scopes = Set.new %w[write_notes]
43     ability = ApiAbility.new user, scopes
44
45     [:index, :create, :comment, :feed, :show, :search, :close, :reopen, :destroy].each do |action|
46       assert ability.can?(action, Note), "should be able to #{action} Notes"
47     end
48   end
49 end