mention_init_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. require 'rails_helper'
  2. RSpec.describe MentionInit, type: :db_migration do
  3. let(:mocked_table_actions) do
  4. lambda { |migration|
  5. # mock DB connection with null object to "null" all connection actions
  6. allow(migration).to receive(:connection).and_return(double('ActiveRecord::ConnectionAdapters::*').as_null_object) # rubocop:disable RSpec/VerifiedDoubles
  7. }
  8. end
  9. context 'when agent is present' do
  10. subject(:user) do
  11. agent = create(:agent)
  12. agent.preferences['notification_config'] = notification_config
  13. agent.tap(&:save!)
  14. end
  15. context 'when matrix misses type key' do
  16. let(:notification_config) do
  17. {
  18. 'matrix' => {
  19. 'create' => {
  20. 'criteria' => {
  21. 'subscribed' => true
  22. }
  23. },
  24. 'update' => {
  25. # 'criteria' => {
  26. # 'subscribed' => true
  27. # }
  28. },
  29. 'reminder_reached' => {
  30. 'criteria' => {
  31. 'subscribed' => false
  32. }
  33. },
  34. 'escalation' => {
  35. 'criteria' => {
  36. 'subscribed' => false
  37. }
  38. },
  39. }
  40. }
  41. end
  42. it 'adds type' do # rubocop:disable RSpec/ExampleLength
  43. expect do
  44. migrate(&mocked_table_actions)
  45. end
  46. .to change {
  47. user.reload.preferences['notification_config']['matrix']['update']
  48. }
  49. .from({})
  50. .to(
  51. {
  52. 'criteria' => {
  53. 'subscribed' => true
  54. }
  55. }
  56. )
  57. end
  58. end
  59. end
  60. end