]> git.openstreetmap.org Git - rails.git/blob - test/abilities/abilities_test.rb
erblint: fix remaining single quoted strings
[rails.git] / test / abilities / 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
30   test "note permissions for a guest" do
31     ability = Ability.new nil
32
33     [:index, :create, :comment, :feed, :show, :search, :mine].each do |action|
34       assert ability.can?(action, Note), "should be able to #{action} Notes"
35     end
36
37     [:close, :reopen, :destroy].each do |action|
38       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
39     end
40   end
41
42   test "user roles permissions for a guest" do
43     ability = Ability.new nil
44
45     [:grant, :revoke].each do |action|
46       assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
47     end
48   end
49 end
50
51 class UserAbilityTest < AbilityTest
52   test "Diary permissions" do
53     ability = Ability.new create(:user)
54
55     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
56       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
57     end
58
59     [:hide, :hidecomment].each do |action|
60       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
61       assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
62     end
63
64     [:index, :show, :resolve, :ignore, :reopen].each do |action|
65       assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
66     end
67   end
68
69   test "Note permissions" do
70     ability = Ability.new create(:user)
71
72     [:index, :create, :comment, :feed, :show, :search, :mine, :close, :reopen].each do |action|
73       assert ability.can?(action, Note), "should be able to #{action} Notes"
74     end
75
76     [:destroy].each do |action|
77       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
78     end
79   end
80 end
81
82 class ModeratorAbilityTest < AbilityTest
83   test "Issue permissions" do
84     ability = Ability.new create(:moderator_user)
85
86     [:index, :show, :resolve, :ignore, :reopen].each do |action|
87       assert ability.can?(action, Issue), "should be able to #{action} Issues"
88     end
89   end
90
91   test "Note permissions" do
92     ability = Ability.new create(:moderator_user)
93
94     [:index, :create, :comment, :feed, :show, :search, :mine, :close, :reopen, :destroy].each do |action|
95       assert ability.can?(action, Note), "should be able to #{action} Notes"
96     end
97   end
98
99   test "User Roles permissions" do
100     ability = Ability.new create(:moderator_user)
101
102     [:grant, :revoke].each do |action|
103       assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
104     end
105   end
106 end
107
108 class AdministratorAbilityTest < AbilityTest
109   test "Diary for an administrator" do
110     ability = Ability.new create(:administrator_user)
111     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
112       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
113     end
114
115     [:hide, :hidecomment].each do |action|
116       assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
117     end
118   end
119
120   test "User Roles permissions for an administrator" do
121     ability = Ability.new create(:administrator_user)
122
123     [:grant, :revoke].each do |action|
124       assert ability.can?(action, UserRole), "should be able to #{action} UserRoles"
125     end
126   end
127 end