1 # frozen_string_literal: true
5 class AbilityTest < ActiveSupport::TestCase
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"
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"
20 test "Diary permissions for a normal user" do
21 ability = Ability.new(create(:user), [])
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"
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"
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"
39 [:hide, :hidecomment].each do |action|
40 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"