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