]> git.openstreetmap.org Git - rails.git/blob - test/models/abilities_test.rb
fc37b0e7df9ab034f731057d298a339f408e716a
[rails.git] / test / models / abilities_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class AbilityTest < ActiveSupport::TestCase
6 end
7
8 class GuestAbilityTest < AbilityTest
9   test "geocoder permission for a guest" do
10     ability = Ability.new nil
11
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"
15     end
16   end
17
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"
22     end
23
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"
27     end
28   end
29 end
30
31 class UserAbilityTest < AbilityTest
32   test "Diary permissions" do
33     ability = Ability.new create(:user)
34
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"
37     end
38
39     [:hide, :hidecomment].each do |action|
40       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
41       assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
42     end
43
44     [:index, :show, :resolve, :ignore, :reopen].each do |action|
45       assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
46     end
47   end
48 end
49
50 class ModeratorAbilityTest < AbilityTest
51   test "Issue permissions" do
52     ability = Ability.new create(:moderator_user)
53
54     [:index, :show, :resolve, :ignore, :reopen].each do |action|
55       assert ability.can?(action, Issue), "should be able to #{action} Issues"
56     end
57   end
58 end
59
60 class AdministratorAbilityTest < AbilityTest
61   test "Diary for an administrator" do
62     ability = Ability.new create(:administrator_user)
63     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
64       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
65     end
66
67     [:hide, :hidecomment].each do |action|
68       assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
69     end
70   end
71 end