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
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
24 token = create(:oauth_access_token, :scopes => %w[write_notes])
25 ability = ApiAbility.new token
27 [:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
28 assert ability.can?(action, Note), "should be able to #{action} Notes"
31 [:destroy].each do |action|
32 assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
37 class ModeratorApiAbilityTest < ApiAbilityTest
38 test "Note permissions" do
39 token = create(:oauth_access_token, :scopes => %w[write_notes], :resource_owner_id => create(:moderator_user).id)
40 ability = ApiAbility.new token
42 [:index, :create, :comment, :feed, :show, :search, :close, :reopen, :destroy].each do |action|
43 assert ability.can?(action, Note), "should be able to #{action} Notes"