From 85cefc2f5dd8c321a8b823a5b4b50cf6419bd8f6 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Sun, 21 Dec 2025 21:56:28 +0000 Subject: [PATCH 1/3] chore: added api versioning, namespaces and default routes --- .../api/v1/application_controller.rb | 9 +++++++++ app/controllers/api/v1/base_controller.rb | 4 ++++ app/controllers/api/v1/health_controller.rb | 9 +++++++++ app/controllers/api/v1/root_controller.rb | 13 +++++++++++++ app/controllers/application_controller.rb | 5 ----- config/routes.rb | 19 +++++++++++++------ 6 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 app/controllers/api/v1/application_controller.rb create mode 100644 app/controllers/api/v1/base_controller.rb create mode 100644 app/controllers/api/v1/health_controller.rb create mode 100644 app/controllers/api/v1/root_controller.rb delete mode 100644 app/controllers/application_controller.rb diff --git a/app/controllers/api/v1/application_controller.rb b/app/controllers/api/v1/application_controller.rb new file mode 100644 index 0000000..6c24637 --- /dev/null +++ b/app/controllers/api/v1/application_controller.rb @@ -0,0 +1,9 @@ +module Api + module V1 + class ApplicationController < BaseController + def index + render html: "Hello, World!" + end + end + end +end diff --git a/app/controllers/api/v1/base_controller.rb b/app/controllers/api/v1/base_controller.rb new file mode 100644 index 0000000..817a2d4 --- /dev/null +++ b/app/controllers/api/v1/base_controller.rb @@ -0,0 +1,4 @@ +module Api::V1 + class BaseController < ActionController::API + end +end diff --git a/app/controllers/api/v1/health_controller.rb b/app/controllers/api/v1/health_controller.rb new file mode 100644 index 0000000..57757c4 --- /dev/null +++ b/app/controllers/api/v1/health_controller.rb @@ -0,0 +1,9 @@ +module Api + module V1 + class HealthController < BaseController + def index + render json: { status: "ok" }, status: :ok + end + end + end +end diff --git a/app/controllers/api/v1/root_controller.rb b/app/controllers/api/v1/root_controller.rb new file mode 100644 index 0000000..5e715ce --- /dev/null +++ b/app/controllers/api/v1/root_controller.rb @@ -0,0 +1,13 @@ +module Api + module V1 + class RootController < BaseController + def index + render json: { + name: "SimpleSave API", + version: "v1", + status: "ok" + } + end + end + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb deleted file mode 100644 index db06a2c..0000000 --- a/app/controllers/application_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ApplicationController < ActionController::API - def hello - render html: "Hello, World!" - end -end diff --git a/config/routes.rb b/config/routes.rb index b6ce685..c7e7197 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,10 +1,17 @@ Rails.application.routes.draw do - # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + namespace :api do + namespace :v1 do + # Health + resources :health - # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. - # Can be used by load balancers and uptime monitors to verify that the app is live. - get "health" => "rails/health#show", as: :rails_health_check + # Application + resources :application - # Defines the root path route ("/") - root "application#hello" + # Root + root to: "root#index" + end + end + + # Redirect Root to current API version root + root to: redirect("/api/v1") end From 66e74b21a161556335c1771a0c28dfcd641d8f87 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Tue, 23 Dec 2025 21:05:39 +0000 Subject: [PATCH 2/3] chore: added some tests and fixed test setup --- .dockerignore | 3 +++ Gemfile | 4 ++++ Gemfile.lock | 15 +++++++++++---- db/schema.rb | 2 +- test/test_helper.rb | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.dockerignore b/.dockerignore index 9355f68..70c04c1 100644 --- a/.dockerignore +++ b/.dockerignore @@ -30,6 +30,9 @@ /tmp/storage/* !/tmp/storage/.keep +# Ignore db test files. +db/test.* + # Ignore CI service files. /.github diff --git a/Gemfile b/Gemfile index e3f6d54..6d7d1b4 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,10 @@ group :development, :test do # Static analysis for security vulnerabilities [https://brakemanscanner.org/] gem "brakeman", require: false + # Testing Framework + gem "minitest", "~> 5.0" + gem "minitest-reporters" + # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] gem "rubocop-rails-omakase", require: false end diff --git a/Gemfile.lock b/Gemfile.lock index 5cd26de..78a8e95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -75,6 +75,7 @@ GEM securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) + ansi (1.5.0) ast (2.4.3) base64 (0.3.0) bcrypt_pbkdf (1.1.2) @@ -103,7 +104,7 @@ GEM raabro (~> 1.4) globalid (1.3.0) activesupport (>= 6.1) - i18n (1.14.7) + i18n (1.14.8) concurrent-ruby (~> 1.0) io-console (0.8.2) irb (1.16.0) @@ -136,8 +137,12 @@ GEM net-smtp marcel (1.1.0) mini_mime (1.1.5) - minitest (6.0.0) - prism (~> 1.5) + minitest (5.27.0) + minitest-reporters (1.7.1) + ansi + builder + minitest (>= 5.0) + ruby-progressbar msgpack (1.8.0) net-imap (0.6.2) date @@ -227,7 +232,7 @@ GEM zeitwerk (~> 2.6) rainbow (3.1.1) rake (13.3.1) - rdoc (7.0.1) + rdoc (7.0.2) erb psych (>= 4.0.0) tsort @@ -321,6 +326,8 @@ DEPENDENCIES brakeman debug kamal + minitest (~> 5.0) + minitest-reporters pg (~> 1.1) puma (>= 5.0) rails (~> 8.1.1) diff --git a/db/schema.rb b/db/schema.rb index 4d004c3..f8be1d3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 0) do +ActiveRecord::Schema[8.1].define(version: 0) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" diff --git a/test/test_helper.rb b/test/test_helper.rb index 6a78b6f..90dbd23 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,6 +2,8 @@ ActiveRecord::Migration.maintain_test_schema! require_relative "../config/environment" require "rails/test_help" +require "minitest/reporters" +Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new module ActiveSupport class TestCase From f59fc1666319378684e21ba511b4cf41eb094c41 Mon Sep 17 00:00:00 2001 From: Azuna <36605286+azunaVT@users.noreply.github.com> Date: Tue, 23 Dec 2025 21:26:23 +0000 Subject: [PATCH 3/3] chore: added missing test classes --- test/integration/api/root_redirect_test.rb | 9 +++++++++ test/integration/api/v1/api_v1_health_test.rb | 8 ++++++++ .../api/v1/api_v1_root_controller_test.rb | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 test/integration/api/root_redirect_test.rb create mode 100644 test/integration/api/v1/api_v1_health_test.rb create mode 100644 test/integration/api/v1/api_v1_root_controller_test.rb diff --git a/test/integration/api/root_redirect_test.rb b/test/integration/api/root_redirect_test.rb new file mode 100644 index 0000000..fc665e1 --- /dev/null +++ b/test/integration/api/root_redirect_test.rb @@ -0,0 +1,9 @@ +require "test_helper" + +class RootRedirectTest < ActionDispatch::IntegrationTest + test "GET / redirects to /api/v1" do + get "/" + assert_response :redirect + assert_redirected_to "/api/v1" + end +end diff --git a/test/integration/api/v1/api_v1_health_test.rb b/test/integration/api/v1/api_v1_health_test.rb new file mode 100644 index 0000000..642438d --- /dev/null +++ b/test/integration/api/v1/api_v1_health_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class ApiV1HealthTest < ActionDispatch::IntegrationTest + test "GET /api/v1/health returns ok" do + get "/api/v1/health" + assert_response :success + end +end diff --git a/test/integration/api/v1/api_v1_root_controller_test.rb b/test/integration/api/v1/api_v1_root_controller_test.rb new file mode 100644 index 0000000..012c6f2 --- /dev/null +++ b/test/integration/api/v1/api_v1_root_controller_test.rb @@ -0,0 +1,13 @@ +require "test_helper" + +class ApiV1RootTest < ActionDispatch::IntegrationTest + test "GET /api/v1 returns metadata" do + get "/api/v1" + assert_response :success + + json = JSON.parse(response.body) + # Keep these assertions aligned with your actual payload. + assert json.is_a?(Hash) + assert_equal "v1", json["version"] if json.key?("version") + end +end