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, :comments].each do |action|
21 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
24 [:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
25 assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
29 test "note permissions for a guest" do
30 ability = Ability.new nil
32 [:index].each do |action|
33 assert ability.can?(action, Note), "should be able to #{action} Notes"
37 test "user roles permissions for a guest" do
38 ability = Ability.new nil
40 [:grant, :revoke].each do |action|
41 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
46 class UserAbilityTest < AbilityTest
47 test "Diary permissions" do
48 ability = Ability.new create(:user)
50 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
51 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
54 [:hide, :hidecomment].each do |action|
55 assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
58 [:index, :show, :resolve, :ignore, :reopen].each do |action|
59 assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
64 class ModeratorAbilityTest < AbilityTest
65 test "Issue permissions" do
66 ability = Ability.new create(:moderator_user)
68 [:index, :show, :resolve, :ignore, :reopen].each do |action|
69 assert ability.can?(action, Issue), "should be able to #{action} Issues"
73 test "User Roles permissions" do
74 ability = Ability.new create(:moderator_user)
76 [:grant, :revoke].each do |action|
77 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
80 [:hide, :hidecomment].each do |action|
81 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
86 class AdministratorAbilityTest < AbilityTest
87 test "Diary for an administrator" do
88 ability = Ability.new create(:administrator_user)
89 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
90 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
94 test "User Roles permissions for an administrator" do
95 ability = Ability.new create(:administrator_user)
97 [:grant, :revoke].each do |action|
98 assert ability.can?(action, UserRole), "should be able to #{action} UserRoles"