knowledge_base_policy_examples.rb 681 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_context 'with KB policy check' do |editor:, reader:, none:, method:, access_method: :access|
  3. let(:access_method) { access_method }
  4. it 'returns true if editor' do
  5. mock_permission 'editor'
  6. expect(policy.send(method)).to be editor
  7. end
  8. it 'returns true if reader' do
  9. mock_permission 'reader'
  10. expect(policy.send(method)).to be reader
  11. end
  12. it 'returns false if none' do
  13. mock_permission 'none'
  14. expect(policy.send(method)).to be none
  15. end
  16. def mock_permission(access)
  17. allow(policy)
  18. .to receive(access_method)
  19. .and_return(access)
  20. end
  21. end