]> git.openstreetmap.org Git - rails.git/blob - test/abilities/abilities_test.rb
Merge branch 'master' into patch/view_migration
[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     end
27   end
28
29   test "note permissions for a guest" do
30     ability = Ability.new nil
31
32     [:mine].each do |action|
33       assert ability.can?(action, Note), "should be able to #{action} Notes"
34     end
35   end
36
37   test "user roles permissions for a guest" do
38     ability = Ability.new nil
39
40     [:grant, :revoke].each do |action|
41       assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
42     end
43   end
44 end
45
46 class UserAbilityTest < AbilityTest
47   test "Diary permissions" do
48     ability = Ability.new create(:user)
49
50     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
51       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
52     end
53
54     [:hide, :hidecomment].each do |action|
55       assert ability.cannot?(action, DiaryEntry), "should not be able to #{action} DiaryEntries"
56     end
57
58     [:index, :show, :resolve, :ignore, :reopen].each do |action|
59       assert ability.cannot?(action, Issue), "should not be able to #{action} Issues"
60     end
61   end
62 end
63
64 class ModeratorAbilityTest < AbilityTest
65   test "Issue permissions" do
66     ability = Ability.new create(:moderator_user)
67
68     [:index, :show, :resolve, :ignore, :reopen].each do |action|
69       assert ability.can?(action, Issue), "should be able to #{action} Issues"
70     end
71   end
72
73   test "User Roles permissions" do
74     ability = Ability.new create(:moderator_user)
75
76     [:grant, :revoke].each do |action|
77       assert ability.cannot?(action, UserRole), "should not be able to #{action} UserRoles"
78     end
79
80     [:hide, :hidecomment].each do |action|
81       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
82     end
83   end
84 end
85
86 class AdministratorAbilityTest < AbilityTest
87   test "Diary for an administrator" do
88     ability = Ability.new create(:administrator_user)
89     [:index, :rss, :show, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
90       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
91     end
92   end
93
94   test "User Roles permissions for an administrator" do
95     ability = Ability.new create(:administrator_user)
96
97     [:grant, :revoke].each do |action|
98       assert ability.can?(action, UserRole), "should be able to #{action} UserRoles"
99     end
100   end
101 end