tests_controller.rb 933 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TestsController < ApplicationController
  3. prepend_before_action -> { authentication_check_only }
  4. layout 'tests', except: %i[wait raised_exception]
  5. def show
  6. @filename = params[:name]
  7. if lookup_context.exists? @filename, 'tests'
  8. render @filename
  9. elsif @filename.starts_with? 'form'
  10. render 'form'
  11. else
  12. render
  13. end
  14. end
  15. # GET /tests/wait
  16. def wait
  17. sleep params[:sec].to_i
  18. result = { success: true }
  19. render json: result
  20. end
  21. # GET /tests/raised_exception
  22. def error_raised_exception
  23. origin = params.fetch(:origin)
  24. exception = params.fetch(:exception, 'StandardError')
  25. message = params.fetch(:message, 'no message provided')
  26. # Emulate the originating controller.
  27. params[:controller] = origin if origin
  28. raise exception.safe_constantize, message
  29. end
  30. end