Skip to content

Commit

Permalink
add manual_execution param to test runs controller
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwwhiterabbit committed Aug 19, 2024
1 parent e8e0e0f commit 9aad231
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/controllers/test_runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create

respond_to do |format|
if @test_run.save
TestRunJob.perform_later(@test_run.id)
TestRunJob.perform_later(@test_run.id) unless @test_run.manual_execution?
format.html { redirect_to test_run_url(@test_run), notice: 'Test model version run was successfully created.' }
format.json { render :show, status: :created, location: @test_run }
else
Expand All @@ -51,7 +51,7 @@ def set_test_run

# Only allow a list of trusted parameters through.
def test_run_params
params.require(:test_run).permit(:name, :prompt_id, :calls, :passing_threshold, assertion_ids: []).tap do |permited|
params.require(:test_run).permit(:name, :prompt_id, :calls, :passing_threshold, :manual_execution, assertion_ids: []).tap do |permited|
model_version_ids = params[:test_run][:model_version_ids]&.select(&:present?)
if model_version_ids.present?
permited[:test_model_version_runs_attributes] = model_version_ids.map do |model_version_id|
Expand Down
4 changes: 4 additions & 0 deletions app/views/test_runs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<%= form.label 'Passing threshold in %' %>
<%= form.number_field :passing_threshold, step: '0.01', max: 100, class: "block shadow rounded-md border border-gray-400 outline-none px-3 py-2 mt-2 w-full" %>
</div>
<div class="my-5">
<%= form.check_box :manual_execution %>
<%= form.label :manual_execution %>
</div>

<div class="inline">
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20240819134918_add_manual_execution_to_test_run.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddManualExecutionToTestRun < ActiveRecord::Migration[7.1]
def change
add_column :test_runs, :manual_execution, :boolean, null: false, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions spec/controllers/test_runs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@
expect(response.content_type).to eq('application/json; charset=utf-8')
expect(response.location).to eq(test_run_url(TestRun.reorder(:created_at).last))
end

context 'with manual_execution param' do
before do
valid_attributes[:manual_execution] = '1'
allow(SolidQueue::Job).to receive(:enqueue)
end

it 'does not enqueue a TestRunJob' do
post :create, params: { test_run: valid_attributes }
expect(SolidQueue::Job).not_to have_received(:enqueue)
end
end
end
end
end

0 comments on commit 9aad231

Please sign in to comment.