has_groups_permissions_examples.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. RSpec.shared_examples 'HasGroups and Permissions' do |group_access_no_permission_factory:|
  3. context 'group' do
  4. subject { build(group_access_no_permission_factory) }
  5. let(:group_read) { create(:group) }
  6. before do
  7. subject.group_names_access_map = {
  8. group_read.name => 'read',
  9. }
  10. end
  11. describe '#group_access?' do
  12. it 'prevents instances without permissions' do
  13. expect(subject.group_access?(group_read, 'read')).to be false
  14. end
  15. end
  16. describe '#group_ids_access' do
  17. it 'prevents instances without permissions' do
  18. expect(subject.group_ids_access('read')).to be_empty
  19. end
  20. end
  21. describe '#groups_access' do
  22. it 'prevents instances without permissions' do
  23. expect(subject.groups_access('read')).to be_empty
  24. end
  25. end
  26. describe '#group_names_access_map' do
  27. it 'prevents instances without permissions' do
  28. expect(subject.group_names_access_map).to be_empty
  29. end
  30. end
  31. describe '#group_ids_access_map' do
  32. it 'prevents instances without permissions' do
  33. expect(subject.group_ids_access_map).to be_empty
  34. end
  35. end
  36. describe '#attributes_with_association_ids' do
  37. it 'prevents instances without permissions' do
  38. expect(subject.attributes_with_association_ids['group_ids']).to be_empty
  39. end
  40. end
  41. describe '#attributes_with_association_names' do
  42. it 'prevents instances without permissions' do
  43. expect(subject.attributes_with_association_names['group_ids']).to be_empty
  44. end
  45. end
  46. describe '.group_access' do
  47. it 'prevents instances without permissions' do
  48. result = described_class.group_access(group_read.id, 'read')
  49. expect(result).not_to include(subject)
  50. end
  51. end
  52. describe '.group_access_ids' do
  53. it 'prevents instances without permissions' do
  54. result = described_class.group_access(group_read.id, 'read')
  55. expect(result).not_to include(subject.id)
  56. end
  57. end
  58. end
  59. end