Changed naming from Routes to Controllers; fixed some Sinatra modular layout stuff; added RSpec for testing and some basic tests
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine
2025-08-12 16:15:43 -04:00
parent 260d0d1268
commit 40cfdcc2a3
18 changed files with 105 additions and 83 deletions

View File

@@ -0,0 +1,61 @@
# frozen_string_literal: true
require_relative 'base_controller'
require_relative '../models/benchmark'
# /benchmark routes
class BenchmarkController < BaseController
get '/benchmark' do
benchmarks = Benchmark.reverse(:updated_at).limit(10).all()
erb :'benchmark/index', locals: {
title: 'List of Benchmarks',
benchmarks: benchmarks
}
end
get '/benchmark/add' do
erb :'benchmark/add', locals: {
title: 'Add Benchmark'
}
end
post '/benchmark/add' do
benchmark = Benchmark.create(
name: params[:benchmark_name],
scoring: params[:benchmark_scoring],
description: params[:benchmark_description]
)
redirect "/benchmark/#{benchmark.id}"
end
get '/benchmark/:benchmark_id' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
erb :'benchmark/view', locals: {
title: benchmark.name,
benchmark: benchmark
}
end
get '/benchmark/:benchmark_id/edit' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
erb :'benchmark/edit', locals: {
title: "Editing: #{benchmark.name}",
benchmark: benchmark
}
end
post '/benchmark/:benchmark_id/edit' do
benchmark = Benchmark.where(id: params[:benchmark_id]).first()
benchmark.update(
name: params[:benchmark_name],
scoring: params[:benchmark_scoring],
description: params[:benchmark_description]
)
redirect "/benchmark/#{benchmark.id}"
end
end