Class: Inferno::Web::Controllers::TestSessions::Create

Inherits:
Controller
  • Object
show all
Defined in:
lib/inferno/apps/web/controllers/test_sessions/create.rb

Constant Summary collapse

PARAMS =
[:test_suite_id, :suite_options].freeze

Instance Method Summary collapse

Methods inherited from Controller

call, resource_class, resource_name

Instance Method Details

#create_params(params) ⇒ Object



27
28
29
# File 'lib/inferno/apps/web/controllers/test_sessions/create.rb', line 27

def create_params(params)
  params.slice(*PARAMS)
end

#handle(req, res) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/inferno/apps/web/controllers/test_sessions/create.rb', line 11

def handle(req, res)
  params = req.params.to_h
  params.merge!(JSON.parse(req.body.string).symbolize_keys) unless req.body.string.blank?

  session = repo.create(create_params(params))

  repo.apply_preset(session, params[:preset_id]) if params[:preset_id].present?

  res.body = serialize(session)
rescue Sequel::ValidationFailed, Sequel::ForeignKeyConstraintViolation => e
  halt 422, { errors: e.message }.to_json
rescue StandardError => e
  Application['logger'].error(e.full_message)
  halt 500, { errors: e.message }.to_json
end