-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcypress_controller.rb
28 lines (24 loc) · 970 Bytes
/
cypress_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Cypress
# Handles Cypress requests for interactive UI testing.
#
# The main purpose of this class is to send back errors as JSON object
# to parse them in the Cypress test UI. This way, we can display the error
# message and the stacktrace in the Cypress test.
class CypressController < ApplicationController
respond_to :json
rescue_from Exception, with: :show_errors
# This is specific to our codebase at MaMpf: https://github.com/MaMpf-HD/mampf
# We use Devise for user authentication and we want to skip that
# authentication for Cypress requests.
skip_before_action :authenticate_user!
private
# Returns the error as JSON such that it can be displayed in the Cypress test.
def show_errors(exception)
error = {
error: "#{exception.class}: #{exception}",
stacktrace: exception.backtrace.join("\n")
}
render json: error, status: :bad_request
end
end
end