1 # frozen_string_literal: true
5 class AbilityTest < ActiveSupport::TestCase
8 class GuestAbilityTest < AbilityTest
9 test "geocoder permission for a guest" do
10 ability = Ability.new nil
12 [:search, :search_latlon, :search_osm_nominatim,
13 :search_osm_nominatim_reverse].each do |action|
14 assert ability.can?(action, :geocoder), "should be able to #{action} geocoder"
18 test "diary permissions for a guest" do
19 ability = Ability.new nil
20 [:index, :rss, :show].each do |action|
21 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
24 [:index].each do |action|
25 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
28 [:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
29 assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
33 test "note permissions for a guest" do
34 ability = Ability.new nil
36 [:index].each do |action|
37 assert ability.can?(action, Note), "should be able to #{action} Notes"
41 test "user roles permissions for a guest" do
42 ability = Ability.new nil
44 [:grant, :revoke].each do |action|
45 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
50 class UserAbilityTest < AbilityTest
51 test "Diary permissions" do
52 ability = Ability.new create(:user)
54 [:index, :rss, :show, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
55 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
58 [:index].each do |action|
59 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
62 [:hide, :hidecomment].each do |action|
63 assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
66 [:index, :show, :resolve, :ignore, :reopen].each do |action|
67 assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
72 class ModeratorAbilityTest < AbilityTest
73 test "Issue permissions" do
74 ability = Ability.new create(:moderator_user)
76 [:index, :show, :resolve, :ignore, :reopen].each do |action|
77 assert ability.can?(action, Issue), "should be able to #{action} Issues"
81 test "User Roles permissions" do
82 ability = Ability.new create(:moderator_user)
84 [:grant, :revoke].each do |action|
85 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
88 [:hide, :hidecomment].each do |action|
89 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
94 class AdministratorAbilityTest < AbilityTest
95 test "Diary for an administrator" do
96 ability = Ability.new create(:administrator_user)
97 [:index, :rss, :show, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
98 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
101 [:index].each do |action|
102 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComments"
106 test "User Roles permissions for an administrator" do
107 ability = Ability.new create(:administrator_user)
109 [:grant, :revoke].each do |action|
110 assert ability.can?(action, UserRole), "should be able to #{action} UserRoles"