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_ca_postcode, :search_osm_nominatim,
13 :search_geonames, :search_osm_nominatim_reverse, :search_geonames_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"
26 assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
30 test "note permissions for a guest" do
31 ability = Ability.new nil
33 [:mine].each do |action|
34 assert ability.can?(action, Note), "should be able to #{action} Notes"
38 test "user roles permissions for a guest" do
39 ability = Ability.new nil
41 [:grant, :revoke].each do |action|
42 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
47 class UserAbilityTest < AbilityTest
48 test "Diary permissions" do
49 ability = Ability.new create(:user)
51 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
52 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
55 [:hide, :hidecomment].each do |action|
56 assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
57 assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
60 [:index, :show, :resolve, :ignore, :reopen].each do |action|
61 assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
66 class ModeratorAbilityTest < AbilityTest
67 test "Issue permissions" do
68 ability = Ability.new create(:moderator_user)
70 [:index, :show, :resolve, :ignore, :reopen].each do |action|
71 assert ability.can?(action, Issue), "should be able to #{action} Issues"
75 test "User Roles permissions" do
76 ability = Ability.new create(:moderator_user)
78 [:grant, :revoke].each do |action|
79 assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
84 class AdministratorAbilityTest < AbilityTest
85 test "Diary for an administrator" do
86 ability = Ability.new create(:administrator_user)
87 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
88 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
91 [:hide, :hidecomment].each do |action|
92 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
96 test "User Roles permissions for an administrator" do
97 ability = Ability.new create(:administrator_user)
99 [:grant, :revoke].each do |action|
100 assert ability.can?(action, UserRole), "should be able to #{action} UserRoles"