]> git.openstreetmap.org Git - rails.git/blob - test/abilities/api_abilities_test.rb
c32300c60997297aabc7e85240f2e95dba0bf811
[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, nil
11
12     [:index, :create, :feed, :show, :search].each do |action|
13       assert ability.can?(action, Note), "should be able to #{action} Notes"
14     end
15
16     [:comment, :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     user = create(:user)
25     token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
26     ability = ApiAbility.new user, token
27
28     [:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
29       assert ability.can?(action, Note), "should be able to #{action} Notes"
30     end
31
32     [:destroy].each do |action|
33       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
34     end
35   end
36 end
37
38 class ModeratorApiAbilityTest < ApiAbilityTest
39   test "Note permissions" do
40     user = create(:moderator_user)
41     token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
42     ability = ApiAbility.new user, token
43
44     [:index, :create, :comment, :feed, :show, :search, :close, :reopen, :destroy].each do |action|
45       assert ability.can?(action, Note), "should be able to #{action} Notes"
46     end
47   end
48 end