Sha256: 816e1f59f75a69d3dddb9048da5500dbd9d52231c07efdc4f79d57f4ab26842b

Contents?: true

Size: 1.01 KB

Versions: 12

Compression:

Stored size: 1.01 KB

Contents

require_relative '../controller'
require_relative '../../serializers/test_session'

module Inferno
  module Web
    module Controllers
      module TestSessions
        class Create < Controller
          PARAMS = [:test_suite_id, :suite_options].freeze

          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.id, 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

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
inferno_core-0.4.7 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.7.pre lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.6 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.5 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.4 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.3 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.2 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.2.pre lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.1 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.1.pre2 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.1.pre lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.4.0 lib/inferno/apps/web/controllers/test_sessions/create.rb