]> git.openstreetmap.org Git - rails.git/blob - test/models/abilities_test.rb
Use cancancan to authorize user_preference_controller
[rails.git] / test / models / abilities_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class AbilityTest < ActiveSupport::TestCase
6
7   test "diary permissions for a guest" do
8     ability = Ability.new(nil, [])
9     [:list, :rss, :view, :comments].each do |action|
10       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
11     end
12
13     [:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
14       assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
15       assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries"
16     end
17   end
18
19   test "Diary permissions for a normal user" do
20     ability = Ability.new(create(:user), [])
21
22     [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
23       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
24     end
25
26     [:hide, :hidecomment].each do |action|
27       assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
28       assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries"
29     end
30   end
31
32   test "Diary for an administrator" do
33     ability = Ability.new(create(:administrator_user), [])
34     [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action|
35       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
36     end
37
38     [:hide, :hidecomment].each do |action|
39       assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
40     end
41   end
42 end