has_groups_permissions_examples.rb 2.0 KB

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