Skip to content

Commit

Permalink
perform model version run
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwwhiterabbit committed Aug 20, 2024
1 parent 9aad231 commit f553f3b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
20 changes: 20 additions & 0 deletions app/controllers/test_model_version_runs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ def show
@test_results = @test_model_version_run.test_results.includes(:assertion_results).decorate
end

# POST /test_runs/1/test_model_version_runs/2/perform or /test_runs/1/test_model_version_runs/2/perform.json
def perform
respond_to do |format|
if @test_model_version_run.state == 'pending'
perform_all_test_model_version_run_jobs

notice = "Test model version run was successfully performed."
format.html { redirect_to perform_test_run_test_model_version_run_path(@test_run, @test_model_version_run), notice: }
format.json { render :show, status: :created }
else
# TODO: render errors
end
end
end

private

# Use callbacks to share common setup or constraints between actions.
Expand All @@ -19,4 +34,9 @@ def set_test_model_version_run
def set_test_run
@test_run = current_user.test_runs.find(params[:test_run_id])
end

def perform_all_test_model_version_run_jobs
jobs = Array.new(@test_run.calls) { TestModelVersionRunJob.new(@test_model_version_run.id) }
ActiveJob.perform_all_later(jobs)
end
end
5 changes: 4 additions & 1 deletion app/views/test_model_version_runs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

<%= render @test_model_version_run %>

<%= link_to "Back to test run", test_run_path(@test_run), class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium w-56" %>
<div class="flex">
<%= button_to 'Run', perform_test_run_test_model_version_run_path(@test_run, @test_model_version_run), method: :post, class: 'rounded-lg py-3 px-5 bg-blue-500 text-white font-medium mr-2' %>
<%= button_to "Back to test run", test_run_path(@test_run), class: "rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
</div>

<div class="w-full w-full mx-auto mt-10 overflow-hidden rounded-lg shadow-xs">
<h1 class="font-bold text-4xl">Test Results</h1>
Expand Down
6 changes: 5 additions & 1 deletion app/views/test_runs/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
<th class="px-4 py-3">Model Version</th>
<th class="px-4 py-3">State</th>
<th class="px-4 py-3">Created at</th>
<th class="w-1"></th>
</tr>
</thead>
<tbody
class="bg-white divide-y dark:divide-gray-700 dark:bg-gray-800"
>
<% if @test_model_version_runs.empty? %>
<tr>
<td colspan="7" class="px-4 py-3 text-center">
<td colspan="8" class="px-4 py-3 text-center">
<p class="text-gray-500">No model versions runs found.</p>
</td>
</tr>
Expand All @@ -52,6 +53,9 @@
<td class="px-4 py-3 text-sm">
<%= time_ago_in_words(test_model_version_run.created_at) %> ago
</td>
<td class="px-4 py-2">
<%= button_to 'Run', perform_test_run_test_model_version_run_path(@test_run, test_model_version_run), method: :post, class: 'bg-blue-500 text-white font-bold py-2 px-4 rounded' %>
</td>
</tr>
<% end %>
<% end %>
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
end

resources :test_runs, except: %i[edit update destroy] do
resources :test_model_version_runs, only: %i[show]
resources :test_model_version_runs, only: %i[show] do
post :perform, on: :member
end
end

resources :compare, only: [:index] do
Expand Down
14 changes: 14 additions & 0 deletions spec/controllers/test_model_version_runs_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@
expect(assigns(:test_run)).to eq(test_run)
end
end

describe 'POST #perform' do
subject(:perform!) { post :run, params: { test_run_id: test_run.id, id: test_model_version_run.id } }

before do
allow(ActiveJob).to receive(:perform_all_later)
end

context 'with pending test_model_version_run' do
it 'enqueues a TestModelVersionRunJob' do
expect { perform! }.to change(TestModelVersionRunJob, :count).by(3)
end
end
end
end

0 comments on commit f553f3b

Please sign in to comment.