online_notification_policy_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. describe OnlineNotificationPolicy do
  4. subject(:policy) { described_class.new(user, record) }
  5. let(:user) { create(:admin, groups: [Ticket.first.group]) }
  6. context 'when user is owner' do
  7. let(:record) { create(:online_notification, user: user) }
  8. it { is_expected.to permit_actions(%i[show destroy update]) }
  9. it 'returns true for show columns' do
  10. expect(policy.show?).to a_kind_of(TrueClass)
  11. end
  12. end
  13. context 'when user is owner, but has no access to related object' do
  14. let(:record) { create(:online_notification, user: user, o: ticket) }
  15. let(:ticket) { create(:ticket) }
  16. it { is_expected.to permit_actions(%i[show destroy update]) }
  17. it 'returns permitted columns' do
  18. expect(policy.show?).to a_kind_of(ApplicationPolicy::FieldScope)
  19. end
  20. end
  21. context 'when user is not owner' do
  22. let(:record) { create(:online_notification, user: create(:user)) }
  23. it { is_expected.to forbid_actions(%i[show destroy update]) }
  24. end
  25. end