notification_spec.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe TriggerWebhookJob::CustomPayload::Track::Notification do
  4. let(:ticket) { create(:ticket) }
  5. let(:article) { create(:ticket_article, body: "Text with\nnew line.") }
  6. let(:event) do
  7. {
  8. type: 'info',
  9. execution: 'trigger',
  10. changes: { 'state' => %w[open closed] },
  11. user_id: 1,
  12. }
  13. end
  14. matcher :render_without_errors do
  15. match do
  16. folder_name = File.basename(File.dirname(actual))
  17. event_name = folder_name.sub(%r{^ticket_}, '')
  18. locale = File.basename(actual, '.md.erb')
  19. Setting.set('locale_default', locale)
  20. event[:type] = event_name
  21. described_class.generate({ ticket:, article: }, { event: })
  22. rescue => e
  23. @error = e
  24. false
  25. end
  26. failure_message do
  27. "Expected #{actual.relative_path_from(Rails.root)} to render without errors, but it failed with error: #{@error}"
  28. end
  29. end
  30. it 'notification templates without syntax errors', :aggregate_failures do
  31. Rails.root.join('app/views').glob('messaging/*/*.erb').each do |file| # rubocop:disable RSpec/IteratedExpectation
  32. expect(file).to render_without_errors
  33. end
  34. end
  35. end