rename_notification_sender_spec.rb 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe RenameNotificationSender, type: :db_migration do
  4. before do
  5. Setting.find_by(name: 'notification_sender')&.destroy
  6. # Default value of Zammad 4.1
  7. Setting.create(
  8. title: 'Notification Sender',
  9. name: 'notification_sender',
  10. area: 'Email::Base',
  11. description: 'Defines the sender of email notifications.',
  12. options: {
  13. form: [
  14. {
  15. display: '',
  16. null: false,
  17. name: 'notification_sender',
  18. tag: 'input',
  19. },
  20. ],
  21. },
  22. state: 'Notification Master <noreply@#{config.fqdn}>', # rubocop:disable Lint/InterpolationCheck
  23. preferences: {
  24. online_service_disable: true,
  25. permission: ['admin.channel_email'],
  26. },
  27. frontend: false
  28. )
  29. end
  30. context 'when migrating unchanged default setting' do
  31. it 'sets new value' do
  32. expect { migrate }
  33. .to change { Setting.find_by(name: 'notification_sender').state_current }
  34. .to({ 'value' => '#{config.product_name} <noreply@#{config.fqdn}>' }) # rubocop:disable Lint/InterpolationCheck
  35. end
  36. it 'sets #state_initial' do
  37. expect { migrate }
  38. .to change { Setting.find_by(name: 'notification_sender').state_initial }
  39. .to({ 'value' => '#{config.product_name} <noreply@#{config.fqdn}>' }) # rubocop:disable Lint/InterpolationCheck
  40. end
  41. end
  42. context 'when migrating locally changed setting' do
  43. before do
  44. Setting.set('notification_sender', 'My Custom Sender <sender@local.domain>')
  45. end
  46. it 'does not change the current value' do
  47. expect { migrate }
  48. .not_to change { Setting.find_by(name: 'notification_sender').state_current }
  49. end
  50. it 'sets #state_initial' do
  51. expect { migrate }
  52. .to change { Setting.find_by(name: 'notification_sender').state_initial }
  53. .to({ 'value' => '#{config.product_name} <noreply@#{config.fqdn}>' }) # rubocop:disable Lint/InterpolationCheck
  54. end
  55. end
  56. end