1 # frozen_string_literal: true
5 class ApiAbilityTest < ActiveSupport::TestCase
8 class GuestApiAbilityTest < ApiAbilityTest
9 test "note permissions for a guest" do
10 ability = ApiAbility.new nil, nil
12 [:index, :create, :feed, :show, :search].each do |action|
13 assert ability.can?(action, Note), "should be able to #{action} Notes"
16 [:comment, :close, :reopen, :destroy].each do |action|
17 assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
22 class UserApiAbilityTest < ApiAbilityTest
23 test "Note permissions" do
25 token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
26 ability = ApiAbility.new user, token
28 [:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
29 assert ability.can?(action, Note), "should be able to #{action} Notes"
32 [:destroy].each do |action|
33 assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
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
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"