issue_2541_fix_notification_email_without_body_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. require 'rails_helper'
  2. RSpec.describe Issue2541FixNotificationEmailWithoutBody, type: :db_migration do
  3. describe '"body" attribute management' do
  4. # We use #update_columns to bypass callbacks
  5. # that would prevent the record from being saved with an empty body
  6. before { subject.update_columns(perform: perform) }
  7. let(:perform) do
  8. {
  9. type => {
  10. 'body' => '',
  11. 'recipient' => 'article_last_sender',
  12. 'subject' => 'Thanks for your inquiry (#{ticket.title})', # rubocop:disable Lint/InterpolationCheck
  13. },
  14. }
  15. end
  16. context 'when migrating Triggers' do
  17. subject(:trigger) { create(:trigger) }
  18. context 'for email' do
  19. let(:type) { 'notification.email' }
  20. it "updates empty perform['notification.email']['body'] attribute" do
  21. expect { migrate }.to change { trigger.reload.perform['notification.email']['body'] }.from('').to('-')
  22. end
  23. end
  24. context 'for SMS' do
  25. let(:type) { 'notification.sms' }
  26. it "updates empty perform['notification.sms']['body'] attribute" do
  27. expect { migrate }.to change { trigger.reload.perform['notification.sms']['body'] }.from('').to('-')
  28. end
  29. end
  30. end
  31. context 'when migrating Jobs' do
  32. subject(:job) { create(:job) }
  33. let(:type) { 'notification.email' }
  34. it "updates empty perform['notification.email']['body'] attribute" do
  35. expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
  36. end
  37. context 'when selector contains current_user.id' do
  38. subject(:job) do
  39. UserInfo.ensure_current_user_id do
  40. create(:job, condition: { 'ticket.owner_id' => { 'operator' => 'is', 'pre_condition' => 'current_user.id', 'value' => '', 'value_completion' => '' } } )
  41. end
  42. end
  43. let(:type) { 'notification.email' }
  44. it "updates empty perform['notification.email']['body'] attribute" do
  45. expect { migrate }.to change { job.reload.perform['notification.email']['body'] }.from('').to('-')
  46. end
  47. end
  48. end
  49. end
  50. describe 'scheduler management' do
  51. let(:scheduler) { Scheduler.find_by(method: 'Job.run') }
  52. before { scheduler.update!(active: false) }
  53. it "re-enables 'Job.run' Scheduler" do
  54. expect { migrate }.to change { scheduler.reload.active }.to(true)
  55. end
  56. end
  57. end