]> git.openstreetmap.org Git - rails.git/blob - test/abilities/api_abilities_test.rb
Defer deletion of avatars to a background job
[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     ability = ApiAbility.new nil
11
12     [:index, :create, :comment, :feed, :show, :search].each do |action|
13       assert ability.can?(action, Note), "should be able to #{action} Notes"
14     end
15
16     [:close, :reopen, :destroy].each do |action|
17       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
18     end
19   end
20 end
21
22 class UserApiAbilityTest < ApiAbilityTest
23   test "Note permissions" do
24     ability = ApiAbility.new create(:user)
25
26     [:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
27       assert ability.can?(action, Note), "should be able to #{action} Notes"
28     end
29
30     [:destroy].each do |action|
31       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
32     end
33   end
34 end
35
36 class ModeratorApiAbilityTest < ApiAbilityTest
37   test "Note permissions" do
38     ability = ApiAbility.new create(:moderator_user)
39
40     [:index, :create, :comment, :feed, :show, :search, :close, :reopen, :destroy].each do |action|
41       assert ability.can?(action, Note), "should be able to #{action} Notes"
42     end
43   end
44 end