Commit 31aebce7 authored by charlie-ablett's avatar charlie-ablett
Browse files

API slight shuffle of parameters

parent 12d2be7f
......@@ -6,6 +6,15 @@ GIT
capistrano (~> 3.1)
sshkit (~> 1.3)
GIT
remote: https://gitlab.coko.foundation/INK/ink-step.git
revision: 016222c8dab9c0c377d7dddf06b613e19d029d45
specs:
ink_step (2.0.0)
awesome_print
httparty
rubyzip
GIT
remote: https://gitlab.coko.foundation/INK/inkstep_coko_conversion.git
revision: 6cb33e4f6f15c30cb5467a96d3afc69557801067
......@@ -24,14 +33,6 @@ GIT
specs:
inkstep_development (1.0.5)
PATH
remote: ../ink-step
specs:
ink_step (1.3.3)
awesome_print
httparty
rubyzip
GEM
remote: https://rubygems.org/
specs:
......@@ -80,7 +81,7 @@ GEM
addressable (2.5.1)
public_suffix (~> 2.0, >= 2.0.2)
arel (7.1.4)
awesome_print (1.7.0)
awesome_print (1.8.0)
bcrypt (3.1.11)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
......
......@@ -15,9 +15,11 @@ module Api
end
def create
new_single_step_execution[:execution_parameters] = params[:single_step_execution][:execution_parameters]
new_single_step_execution.description = single_step_execution_param["description"]
new_single_step_execution.step_class_name = single_step_execution_param["step_class_name"]
new_single_step_execution.execution_parameters = execution_params
new_single_step_execution.save!
new_single_step_execution.start_execution!(input_files: input_file_param, code: params[:single_step_execution][:code])
new_single_step_execution.start_execution!(input_files: input_file_param, code: code_param)
render json: new_single_step_execution
rescue => e
ap e.message
......@@ -67,11 +69,33 @@ module Api
private
def input_file_param
params.require(:single_step_execution).require(:input_file_list)
params.require(:input_files)
end
def single_step_execution_params
params.require(:single_step_execution).permit(:description, :step_class_name, :execution_parameters, :input_file_list)
params.require(:single_step_execution)
end
def single_step_execution_param
the_params = params[:single_step_execution]
if the_params.is_a?(String)
JSON.parse(the_params)
else
the_params
end
end
def code_param
params[:code]
end
def execution_params
ex_params = single_step_execution_param["execution_parameters"] || {}
if ex_params.is_a?(String)
JSON.parse(ex_params)
else
ex_params
end
end
def relative_path_param
......@@ -87,7 +111,12 @@ module Api
end
def new_single_step_execution
@single_step_execution ||= current_entity.account.single_step_executions.new(single_step_execution_params)
@single_step_execution ||= current_entity.account.single_step_executions.new
# @single_step_execution ||= current_entity.account.single_step_executions.new(
# description: params[:single_step_execution][:description],
# step_class_name: params[:single_step_execution][:step_class_name],
# execution_parameters: params[:single_step_execution][:execution_parameters]
# )# single_step_execution_params
end
def authorise_account!
......
......@@ -2,3 +2,4 @@
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register "application/vnd.api+json", :json
\ No newline at end of file
......@@ -68,6 +68,9 @@ Rails.application.routes.draw do
end
resources :single_step_executions do
collection do
post 'create'
end
member do
get 'download_output_file'
get 'download_output_zip'
......
......@@ -38,9 +38,9 @@ describe Api::V1::SingleStepExecutionsController, type: :controller do
description: description,
step_class_name: step_class_name,
execution_parameters: execution_parameters,
input_file_list: [html_file],
code: klass_file
}
},
code: klass_file,
input_files: [html_file],
}
}
......@@ -63,9 +63,24 @@ describe Api::V1::SingleStepExecutionsController, type: :controller do
context 'if the single_step_execution is invalid' do
context 'if the code supplied is missing' do
before do
single_step_execution_params[:code] = nil
end
specify do
request_with_auth(account.new_jwt) do
perform_create_request(single_step_execution_params)
end
expect(response.status).to eq 422
expect(body_as_json['errors']).to eq ["That file does not define the class InkStep::AwesomeClass"]
end
end
context 'if the code supplied is blank' do
before do
single_step_execution_params[:single_step_execution][:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/blank_file.rb'))
single_step_execution_params[:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/blank_file.rb'))
end
specify do
......@@ -80,7 +95,7 @@ describe Api::V1::SingleStepExecutionsController, type: :controller do
context 'if the code supplied does not contain a class' do
before do
single_step_execution_params[:single_step_execution][:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/valid_not_a_class.rb'))
single_step_execution_params[:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/valid_not_a_class.rb'))
end
specify do
......@@ -94,7 +109,7 @@ describe Api::V1::SingleStepExecutionsController, type: :controller do
context 'if the code supplied is not valid syntax' do
before do
single_step_execution_params[:single_step_execution][:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/rubbish_class'))
single_step_execution_params[:code] = File.read(Rails.root.join('spec/fixtures/files/standalone/rubbish_class'))
end
specify do
......
......@@ -13,4 +13,5 @@ module InkStep
"An exciting test"
end
end
end
\ No newline at end of file
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment