zammad/app/controllers/tests_controller.rb

49 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
2012-11-23 08:36:12 +00:00
class TestsController < ApplicationController
prepend_before_action -> { authentication_check_only }
layout 'tests', except: %i[wait raised_exception]
def show
@filename = params[:name]
if lookup_context.exists? @filename, 'tests'
render @filename
elsif @filename.starts_with? 'form'
render 'form'
else
render
end
end
# GET /tests/wait
2012-11-23 08:36:12 +00:00
def wait
sleep params[:sec].to_i
result = { success: true }
render json: result
2012-11-23 08:36:12 +00:00
end
# GET /tests/raised_exception
def error_raised_exception
origin = params.fetch(:origin)
exception = params.fetch(:exception, 'StandardError')
message = params.fetch(:message, 'no message provided')
# Emulate the originating controller.
params[:controller] = origin if origin
klass = exception.safe_constantize
error = if klass == Exceptions::ApplicationModel
klass.new(Ticket.first, message)
else
klass.new(message)
end
raise error
end
end