]> git.openstreetmap.org Git - rails.git/blob - test/models/abilities_test.rb
add test helper to set oauth tokens
[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
20   test "Diary permissions for a normal user" do
21     ability = Ability.new(create(:user), [])
22
23     [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action|
24       assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
25     end
26
27     [:hide, :hidecomment].each do |action|
28       assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries"
29       assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries"
30     end
31   end
32
33   test "Diary for an administrator" do
34     ability = Ability.new(create(:administrator_user), [])
35     [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].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.can?(action, DiaryComment), "should be able to #{action} DiaryComment"
41     end
42   end
43 end