notification_templates_spec.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'NotificationFactory::Renderer > Notification Templates' do # rubocop:disable RSpec/DescribeClass
  4. matcher :render_without_errors do
  5. match do
  6. NotificationFactory::Renderer.new(
  7. objects: { changes: { field: 'value' }, article:, ticket:, recipient:, current_user: },
  8. template: actual.read,
  9. trusted: true,
  10. ).render
  11. rescue => e
  12. @error = e
  13. false
  14. end
  15. failure_message do
  16. "Expected #{actual.relative_path_from(Rails.root)} to render without errors, but it failed with error: #{@error}"
  17. end
  18. end
  19. # Cache the objects to speed the tests up.
  20. let(:current_user) { create(:agent) }
  21. let(:recipient) { create(:customer) }
  22. let(:ticket) { create(:ticket) }
  23. let(:article) { create(:ticket_article, ticket:) }
  24. it 'renders English and translated notification templates without syntax errors', :aggregate_failures do
  25. Rails.root.join('app/views').glob('{mailer,messaging}/*/*.erb').each do |file| # rubocop:disable RSpec/IteratedExpectation
  26. expect(file).to render_without_errors
  27. end
  28. end
  29. end