1
0

invite_policy_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe InvitePolicy do
  4. subject { described_class }
  5. let(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')).account }
  6. let(:john) { Fabricate(:user).account }
  7. permissions :index? do
  8. context 'when staff?' do
  9. it 'permits' do
  10. expect(subject).to permit(admin, Invite)
  11. end
  12. end
  13. end
  14. permissions :create? do
  15. context 'with privilege' do
  16. before do
  17. UserRole.everyone.update(permissions: UserRole::FLAGS[:invite_users])
  18. end
  19. it 'permits' do
  20. expect(subject).to permit(john, Invite)
  21. end
  22. end
  23. context 'when does not have privilege' do
  24. before do
  25. UserRole.everyone.update(permissions: UserRole::Flags::NONE)
  26. end
  27. it 'denies' do
  28. expect(subject).to_not permit(john, Invite)
  29. end
  30. end
  31. end
  32. permissions :deactivate_all? do
  33. context 'when admin?' do
  34. it 'permits' do
  35. expect(subject).to permit(admin, Invite)
  36. end
  37. end
  38. context 'when not admin?' do
  39. it 'denies' do
  40. expect(subject).to_not permit(john, Invite)
  41. end
  42. end
  43. end
  44. permissions :destroy? do
  45. context 'when owner?' do
  46. it 'permits' do
  47. expect(subject).to permit(john, Fabricate(:invite, user: john.user))
  48. end
  49. end
  50. context 'when not owner?' do
  51. context 'when admin?' do
  52. it 'permits' do
  53. expect(subject).to permit(admin, Fabricate(:invite))
  54. end
  55. end
  56. context 'when not admin?' do
  57. it 'denies' do
  58. expect(subject).to_not permit(john, Fabricate(:invite))
  59. end
  60. end
  61. end
  62. end
  63. end