mirror of
https://github.com/Evolix/chexpire.git
synced 2024-06-25 10:41:00 +02:00
36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
# Copyright (C) 2018 Colin Darie <colin@darie.eu>, 2018 Evolix <info@evolix.fr>
|
|
# License: GNU AGPL-3+ (see full text in LICENSE file)
|
|
|
|
require "test_helper"
|
|
|
|
class NotificationPolicyTest < ActiveSupport::TestCase
|
|
setup do
|
|
@owner, @other = create_list(:user, 2)
|
|
@notification = create(:notification, check: build(:check, user: @owner))
|
|
end
|
|
|
|
test "permit to check user" do
|
|
assert_permit @owner, @notification, :destroy
|
|
end
|
|
|
|
test "disallow to anonymous and other user" do
|
|
refute_permit @other, @notification, :destroy
|
|
refute_permit nil, @notification, :destroy
|
|
end
|
|
|
|
test "scope only to user checks" do
|
|
other_notifications = create_list(:notification, 2, check: build(:check, user: @other))
|
|
|
|
assert_empty Pundit.policy_scope!(nil, Notification)
|
|
assert_equal [@notification], Pundit.policy_scope!(@owner, Notification)
|
|
assert_equal other_notifications, Pundit.policy_scope!(@other, Notification)
|
|
end
|
|
|
|
test "disabled actions" do
|
|
refute_permit @owner, @notification, :update
|
|
refute_permit @owner, @notification, :edit
|
|
refute_permit @owner, @notification, :create
|
|
refute_permit @owner, @notification, :index
|
|
end
|
|
end
|