Fixed a logic error with removing benchmarks from a test; cleaned up some linter errors
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine
2025-08-12 12:19:25 -04:00
parent 0a1037e79a
commit c74ca114d8
3 changed files with 7 additions and 10 deletions

View File

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

View File

@@ -69,19 +69,16 @@ class GameData < Sinatra::Base
description: params[:test_description] description: params[:test_description]
) )
# create an array of the selected benchmarks
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.each do |b| tst.benchmarks.dup.each do |b|
if not selected_benchmarks.include?(b) tst.remove_benchmark(b.id) unless selected_benchmarks.include?(b.id)
tst.remove_benchmark(b)
end
end end
# associate the benchmarks to the test # associate the benchmarks to the test
selected_benchmarks.each do |b| selected_benchmarks.each do |b|
if not tst.has_benchmark(b) tst.add_benchmark(b) unless tst.benchmark?(b)
tst.add_benchmark(b)
end
end end
redirect "/test/#{tst.id}" redirect "/test/#{tst.id}"

View File

@@ -28,7 +28,7 @@
<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.has_benchmark(b.id) %>selected<% end %>><%= b.name %></option> <option value="<%= b.id %>" <% if test.benchmark?(b.id) %>selected<% end %>><%= b.name %></option>
<% end %> <% end %>
</select> </select>
</div> </div>