Sha256: 47f1d42c1a032b36b7b2bf9498f047725b073670f59f2edc08c114445e8bee56

Contents?: true

Size: 1 KB

Versions: 7

Compression:

Stored size: 1 KB

Contents

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

          def call(raw_params)
            params = raw_params.to_h
            params.merge!(JSON.parse(request.body.string).symbolize_keys) unless request.body.string.blank?

            session = repo.create(create_params(params))

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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
inferno_core-0.3.12 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.11 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.10 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.9 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.8 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.7 lib/inferno/apps/web/controllers/test_sessions/create.rb
inferno_core-0.3.6 lib/inferno/apps/web/controllers/test_sessions/create.rb