has_ticket_create_screen_impact_examples.rb 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. RSpec.shared_examples 'User::HasTicketCreateScreenImpact' do
  2. describe '#push_ticket_create_screen', performs_jobs: true do
  3. shared_examples 'relevant User Role' do |role|
  4. context "relevant User Role is '#{role}'" do
  5. subject { create(:user, roles: Role.where(name: role)) }
  6. context 'creating a record' do
  7. it 'enqueues TicketCreateScreenJob' do
  8. expect { subject }.to have_enqueued_job(TicketCreateScreenJob)
  9. end
  10. end
  11. context 'record exists' do
  12. before do
  13. subject
  14. clear_jobs
  15. end
  16. context 'attribute updated' do
  17. it 'enqueues TicketCreateScreenJob' do
  18. expect { subject.update!(firstname: 'new firstname') }.to have_enqueued_job(TicketCreateScreenJob)
  19. end
  20. context 'permission association changes' do
  21. context 'Group' do
  22. let!(:group) { create(:group) }
  23. before { clear_jobs }
  24. it 'enqueues TicketCreateScreenJob' do
  25. expect do
  26. subject.group_names_access_map = {
  27. group.name => ['full'],
  28. }
  29. end.to have_enqueued_job(TicketCreateScreenJob)
  30. end
  31. end
  32. context 'Role' do
  33. context 'to relevant' do
  34. let!(:roles) { create_list(:agent_role, 1) }
  35. before { clear_jobs }
  36. it 'enqueues TicketCreateScreenJob' do
  37. expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
  38. end
  39. end
  40. context 'to irrelevant' do
  41. let!(:roles) { create_list(:role, 3) }
  42. before { clear_jobs }
  43. it 'enqueues TicketCreateScreenJob' do
  44. expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
  45. end
  46. end
  47. end
  48. end
  49. end
  50. context 'record is deleted' do
  51. it 'enqueues TicketCreateScreenJob' do
  52. expect { subject.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
  53. end
  54. end
  55. end
  56. end
  57. end
  58. shared_examples 'irrelevant User Role' do |role|
  59. context "irrelevant User Role is '#{role}'" do
  60. subject { create(:user, roles: Role.where(name: role)) }
  61. context 'creating a record' do
  62. it 'does not enqueue TicketCreateScreenJob job' do
  63. expect { subject }.not_to have_enqueued_job(TicketCreateScreenJob)
  64. end
  65. end
  66. context 'record exists' do
  67. before do
  68. subject
  69. clear_jobs
  70. end
  71. context 'attribute updated' do
  72. it 'enqueues no TicketCreateScreenJob job' do
  73. expect { subject.update!(firstname: 'new firstname') }.not_to have_enqueued_job(TicketCreateScreenJob)
  74. end
  75. context 'permission association changes', last_admin_check: false do
  76. context 'Group' do
  77. let!(:group) { create(:group) }
  78. before { clear_jobs }
  79. it 'enqueues TicketCreateScreenJob' do
  80. expect do
  81. subject.group_names_access_map = {
  82. group.name => ['full'],
  83. }
  84. end.to have_enqueued_job(TicketCreateScreenJob)
  85. end
  86. end
  87. context 'Role' do
  88. context 'to relevant' do
  89. let!(:roles) { create_list(:agent_role, 3) }
  90. before { clear_jobs }
  91. it 'enqueues TicketCreateScreenJob' do
  92. expect { subject.update!(roles: roles) }.to have_enqueued_job(TicketCreateScreenJob)
  93. end
  94. end
  95. context 'to irrelevant' do
  96. let!(:roles) { create_list(:role, 3) }
  97. before { clear_jobs }
  98. it 'does not enqueue TicketCreateScreenJob' do
  99. expect { subject.update!(roles: roles) }.not_to have_enqueued_job(TicketCreateScreenJob)
  100. end
  101. end
  102. end
  103. end
  104. end
  105. context 'record is deleted' do
  106. it 'enqueues TicketCreateScreenJob job' do
  107. expect { subject.destroy! }.to have_enqueued_job(TicketCreateScreenJob)
  108. end
  109. end
  110. end
  111. end
  112. end
  113. include_examples 'relevant User Role', 'Agent'
  114. include_examples 'irrelevant User Role', 'Customer'
  115. include_examples 'irrelevant User Role', 'Admin'
  116. end
  117. end