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"
19 test "Diary permissions for a normal user" do
20 ability = Ability.new(create(:user), [])
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"
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"
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"
38 [:hide, :hidecomment].each do |action|
39 assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment"