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 be able to #{action} DiaryEntries"
26 assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries"
31 class UserAbilityTest < AbilityTest
32 test "Diary permissions" do
33 ability = Ability.new create(:user)
35 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
36 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
39 [:hide, :hidecomment].each do |action|
40 assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
41 assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries"
46 class AdministratorAbilityTest < AbilityTest
47 test "Diary for an administrator" do
48 ability = Ability.new create(:administrator_user)
49 [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
50 assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
53 [:hide, :hidecomment].each do |action|
54 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"