[Issue #16] - Finished updating Test controller routes that used to reference Benchmarks
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine
2025-10-09 15:43:53 -04:00
parent b19c95187b
commit 2884b94b7f
7 changed files with 24 additions and 17 deletions

View File

@@ -59,10 +59,11 @@ RSpec.describe(TestController) do
before do before do
@hardware = Hardware.create(name: 'Test Hardware', type: 'gpu') @hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
@benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps') @benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps')
@benchmark_profile = BenchmarkProfile.create(label: 'Test Benchmark Profile', settings: '{}', benchmark_id: @benchmark.id)
request_data = { request_data = {
test_name: 'Test Test', test_name: 'Test Test',
test_hardware: @hardware.id, test_hardware: @hardware.id,
'test_benchmarks[]': [@benchmark.id], 'test_benchmarks[]': [@benchmark_profile.id],
test_description: 'Test for testing' test_description: 'Test for testing'
} }
post '/test/add', request_data post '/test/add', request_data
@@ -93,11 +94,11 @@ RSpec.describe(TestController) do
end end
it 'Test add POST route created test has benchmarks.' do it 'Test add POST route created test has benchmarks.' do
expect(Test.first.benchmarks.length).to(eq(1)) expect(Test.first.benchmark_profiles.length).to(eq(1))
end end
it 'Test add POST route created test\'s benchmark can be read.' do it 'Test add POST route created test\'s benchmark can be read.' do
expect(Test.first.benchmarks[0].id).to(eq(@benchmark.id)) expect(Test.first.benchmark_profiles[0].id).to(eq(@benchmark.id))
end end
it 'Test add POST route created test has description.' do it 'Test add POST route created test has description.' do
@@ -110,12 +111,13 @@ RSpec.describe(TestController) do
before do before do
@hardware = Hardware.create(name: 'Test Hardware', type: 'gpu') @hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
@benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps') @benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps')
@benchmark_profile = BenchmarkProfile.create(label: 'Test Benchmark Profile', settings: '{}', benchmark_id: @benchmark.id)
@test = Test.create( @test = Test.create(
name: 'Test Test', name: 'Test Test',
hardware_id: @hardware.id, hardware_id: @hardware.id,
description: 'Test for testing' description: 'Test for testing'
) )
@test.add_benchmark(@benchmark) @test.add_benchmark_profile(@benchmark_profile)
get "/test/#{@test.id}" get "/test/#{@test.id}"
end end
@@ -141,12 +143,13 @@ RSpec.describe(TestController) do
before do before do
@hardware = Hardware.create(name: 'Test Hardware', type: 'gpu') @hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
@benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps') @benchmark = Benchmark.create(name: 'Test Benchmark', scoring: 'fps')
@benchmark_profile = BenchmarkProfile.create(label: 'Test Benchmark Profile', settings: '{}', benchmark_id: @benchmark.id)
@test = Test.create( @test = Test.create(
name: 'Test Test', name: 'Test Test',
hardware_id: @hardware.id, hardware_id: @hardware.id,
description: 'Test for testing' description: 'Test for testing'
) )
@test.add_benchmark(@benchmark) @test.add_benchmark_profile(@benchmark_profile)
get "/test/#{@test.id}/edit" get "/test/#{@test.id}/edit"
end end

View File

@@ -42,7 +42,7 @@ class TestController < BaseController
benchmarks = Array(params[:test_benchmarks]) benchmarks = Array(params[:test_benchmarks])
# associate the benchmarks to the test # associate the benchmarks to the test
benchmarks.each do |b| benchmarks.each do |b|
tst.add_benchmark(b) tst.add_benchmark_profile(b)
end end
redirect "/test/#{tst.id}" redirect "/test/#{tst.id}"
@@ -81,13 +81,13 @@ class TestController < BaseController
selected_benchmarks = Array(params[:test_benchmarks]) selected_benchmarks = Array(params[:test_benchmarks])
# remove benchmarks no longer associated with the test # remove benchmarks no longer associated with the test
tst.benchmarks.dup.each do |b| tst.benchmark_profiles.dup.each do |b|
tst.remove_benchmark(b.id) unless selected_benchmarks.include?(b.id) tst.remove_benchmark_profile(b.id) unless selected_benchmarks.include?(b.id)
end end
# associate the benchmarks to the test # associate the benchmarks to the test
selected_benchmarks.each do |b| selected_benchmarks.each do |b|
tst.add_benchmark(b) unless tst.benchmark?(b) tst.add_benchmark_profile(b) unless tst.benchmark?(b)
end end
redirect "/test/#{tst.id}" redirect "/test/#{tst.id}"

View File

@@ -7,8 +7,8 @@ class Test < Sequel::Model
many_to_one :hardware many_to_one :hardware
many_to_many :benchmark_profiles many_to_many :benchmark_profiles
def benchmark?(benchmark_id) def benchmark?(benchmark_profile_id)
return benchmark_profiles_dataset.where(Sequel[:benchmark][:id] => benchmark_id).any? return benchmark_profiles_dataset.where(Sequel[:benchmark_profiles][:id] => benchmark_profile_id).any?
end end
end end

View File

@@ -28,7 +28,9 @@
<label for="test_benchmarks">Benchmarks</label> <label for="test_benchmarks">Benchmarks</label>
<select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple> <select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple>
<% for b in benchmarks %> <% for b in benchmarks %>
<option value="<%= b.id %>"><%= b.name %></option> <% for bp in b.benchmark_profiles %>
<option value="<%= bp.id %>"><%= b.display_name() %></option>
<% end %>
<% end %> <% end %>
</select> </select>
</div> </div>

View File

@@ -28,7 +28,9 @@
<label for="test_benchmarks">Benchmarks</label> <label for="test_benchmarks">Benchmarks</label>
<select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple> <select id="test_benchmarks" class="form-select" name="test_benchmarks[]" multiple>
<% for b in benchmarks %> <% for b in benchmarks %>
<option value="<%= b.id %>" <% if test.benchmark?(b.id) %>selected<% end %>><%= b.name %></option> <% for bp in b.benchmark_profiles %>
<option value="<%= bp.id %>" <% if test.benchmark?(bp.id) %>selected<% end %>><%= bp.display_name %></option>
<% end %>
<% end %> <% end %>
</select> </select>
</div> </div>

View File

@@ -26,7 +26,7 @@
<% tests.each do |t| %> <% tests.each do |t| %>
<tr> <tr>
<td><a href="/test/<%= t.id %>"><%= t.name %></a></td> <td><a href="/test/<%= t.id %>"><%= t.name %></a></td>
<td><%= t.benchmarks.length %></td> <td><%= t.benchmark_profiles.length %></td>
<td><%= date_format(t.created_at) %></td> <td><%= date_format(t.created_at) %></td>
<td><%= date_format(t.updated_at) %></td> <td><%= date_format(t.updated_at) %></td>
</tr> </tr>

View File

@@ -28,8 +28,8 @@
<div class="col-12 col-md-5 mb-3 mb-md-0"> <div class="col-12 col-md-5 mb-3 mb-md-0">
<label for="result_benchmark">Add benchmark result:</label> <label for="result_benchmark">Add benchmark result:</label>
<select class="form-select" id="result_benchmark" name="result_benchmark"> <select class="form-select" id="result_benchmark" name="result_benchmark">
<% test.benchmarks.each do |b| %> <% test.benchmark_profiles.each do |b| %>
<option value="<%= b.id %>"><%= b.name %></option> <option value="<%= b.id %>"><%= b.display_name %></option>
<% end %> <% end %>
</select> </select>
</div> </div>
@@ -71,7 +71,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% test.benchmarks.each do |benchmark| %> <% test.benchmark_profiles.each do |benchmark| %>
<tr data-benchmark-id="<%= benchmark.id %>"></tr> <tr data-benchmark-id="<%= benchmark.id %>"></tr>
<% end %> <% end %>
</tbody> </tbody>