mirror of https://github.com/Evolix/chexpire.git
Updated factory & policies for new notification template
This commit is contained in:
parent
9c35dbc7a6
commit
54d3dbad12
|
@ -86,7 +86,7 @@ FactoryBot.define do
|
|||
|
||||
trait :with_notifications do
|
||||
after :create do |check|
|
||||
create_list :notification, 2, check: check
|
||||
create_list :check_notification, 2, check: check
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# 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 CheckNotificationPolicyTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@owner, @other = create_list(:user, 2)
|
||||
@check_notification = create(:check_notification, check: build(:check, user: @owner))
|
||||
end
|
||||
|
||||
test "permit to check user" do
|
||||
assert_permit @owner, @check_notification, :destroy
|
||||
end
|
||||
|
||||
test "disallow to anonymous and other user" do
|
||||
refute_permit @other, @check_notification, :destroy
|
||||
refute_permit nil, @check_notification, :destroy
|
||||
end
|
||||
|
||||
test "scope only to user checks" do
|
||||
other_notifications = create_list(:check_notification, 2, check: build(:check, user: @other))
|
||||
|
||||
assert_empty Pundit.policy_scope!(nil, CheckNotification)
|
||||
assert_equal [@check_notification], Pundit.policy_scope!(@owner, CheckNotification)
|
||||
assert_equal other_notifications, Pundit.policy_scope!(@other, CheckNotification)
|
||||
end
|
||||
|
||||
test "disabled actions" do
|
||||
refute_permit @owner, @check_notification, :update
|
||||
refute_permit @owner, @check_notification, :edit
|
||||
refute_permit @owner, @check_notification, :create
|
||||
refute_permit @owner, @check_notification, :index
|
||||
end
|
||||
end
|
|
@ -6,30 +6,32 @@ require "test_helper"
|
|||
class NotificationPolicyTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@owner, @other = create_list(:user, 2)
|
||||
@notification = create(:notification, check: build(:check, user: @owner))
|
||||
@notification = create(:notification, user: @owner)
|
||||
end
|
||||
|
||||
test "permit to check user" do
|
||||
test "create" do
|
||||
assert_permit @other, Notification, :create
|
||||
assert_permit @other, Notification, :new
|
||||
end
|
||||
|
||||
test "permit to owner" do
|
||||
assert_permit @owner, @notification, :edit
|
||||
assert_permit @owner, @notification, :update
|
||||
assert_permit @owner, @notification, :destroy
|
||||
end
|
||||
|
||||
test "disallow to anonymous and other user" do
|
||||
refute_permit @other, @notification, :destroy
|
||||
refute_permit nil, @notification, :destroy
|
||||
%i[update edit destroy].each do |action|
|
||||
refute_permit @other, @notification, action
|
||||
refute_permit nil, @notification, action
|
||||
end
|
||||
end
|
||||
|
||||
test "scope only to user checks" do
|
||||
other_notifications = create_list(:notification, 2, check: build(:check, user: @other))
|
||||
test "scope only to owners" do
|
||||
other_notifications = create_list(:notification, 2, 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
|
||||
|
|
Loading…
Reference in New Issue