]> git.openstreetmap.org Git - rails.git/blob - test/abilities/abilities_test.rb
Merge remote-tracking branch 'upstream/pull/2072'
[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 end
42
43 class UserAbilityTest < AbilityTest
44   test "Diary permissions" do
45     ability = Ability.new create(:user)
46
47     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
48       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
49     end
50
51     [:hide, :hidecomment].each do |action|
52       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
53       assert ability.cannot?(action, DiaryComment), "should not be able to #{action} DiaryEntries"
54     end
55
56     [:index, :show, :resolve, :ignore, :reopen].each do |action|
57       assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
58     end
59   end
60
61   test "Note permissions" do
62     ability = Ability.new create(:user)
63
64     [:index, :create, :comment, :feed, :show, :search, :mine, :close, :reopen].each do |action|
65       assert ability.can?(action, Note), "should be able to #{action} Notes"
66     end
67
68     [:destroy].each do |action|
69       assert ability.cannot?(action, Note), "should not be able to #{action} Notes"
70     end
71   end
72 end
73
74 class ModeratorAbilityTest < AbilityTest
75   test "Issue permissions" do
76     ability = Ability.new create(:moderator_user)
77
78     [:index, :show, :resolve, :ignore, :reopen].each do |action|
79       assert ability.can?(action, Issue), "should be able to #{action} Issues"
80     end
81   end
82
83   test "Note permissions" do
84     ability = Ability.new create(:moderator_user)
85
86     [:index, :create, :comment, :feed, :show, :search, :mine, :close, :reopen, :destroy].each do |action|
87       assert ability.can?(action, Note), "should be able to #{action} Notes"
88     end
89   end
90 end
91
92 class AdministratorAbilityTest < AbilityTest
93   test "Diary for an administrator" do
94     ability = Ability.new create(:administrator_user)
95     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
96       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
97     end
98
99     [:hide, :hidecomment].each do |action|
100       assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
101     end
102   end
103 end