X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/6da3ece68354f77f626de8963770c0217048e19d..060c686c1923534d2899ee129cc740e0f2fa7c9f:/test/models/abilities_test.rb diff --git a/test/models/abilities_test.rb b/test/models/abilities_test.rb index ab8458531..bc8e24781 100644 --- a/test/models/abilities_test.rb +++ b/test/models/abilities_test.rb @@ -4,4 +4,39 @@ require "test_helper" class AbilityTest < ActiveSupport::TestCase + test "diary permissions for a guest" do + ability = Ability.new(nil, []) + [:list, :rss, :view, :comments].each do |action| + assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries" + end + + [:create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action| + assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries" + assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries" + end + end + + test "Diary permissions for a normal user" do + ability = Ability.new(create(:user), []) + + [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe].each do |action| + assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries" + end + + [:hide, :hidecomment].each do |action| + assert ability.cannot?(action, DiaryEntry), "should be able to #{action} DiaryEntries" + assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries" + end + end + + test "Diary for an administrator" do + ability = Ability.new(create(:administrator_user), []) + [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action| + assert ability.can?(action, DiaryEntry), "should be able to #{action} DiaryEntries" + end + + [:hide, :hidecomment].each do |action| + assert ability.can?(action, DiaryComment), "should be able to #{action} DiaryComment" + end + end end