Skip to content

Commit

Permalink
Allow creation of a failure object through api
Browse files Browse the repository at this point in the history
This allows the creation of a failure object which contains file, line
number, test name and the test failure message
  • Loading branch information
bitscraps committed Feb 26, 2021
1 parent 5680783 commit 5a70273
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/controllers/failures_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class FailuresController < ApplicationController
skip_before_action :verify_authenticity_token

def create
failure = Failure.new(failure_params)

if failure.save
render json: failure
else
render json: { error: 'Unable to create failure' }
end
end

private

def failure_params
params.permit(:test_file, :test_name, :line_number, :failure)
end
end
2 changes: 2 additions & 0 deletions app/models/failure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Failure < ApplicationRecord
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html

resource :failures, only: :create
end
12 changes: 12 additions & 0 deletions db/migrate/20210226202757_create_failures.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateFailures < ActiveRecord::Migration[6.1]
def change
create_table :failures do |t|
t.string :test_file
t.string :test_name
t.integer :line_number
t.text :failure

t.timestamps
end
end
end

0 comments on commit 5a70273

Please sign in to comment.