Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
/tmp/storage/*
!/tmp/storage/.keep

# Ignore db test files.
db/test.*

# Ignore CI service files.
/.github

Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 11 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -321,6 +326,8 @@ DEPENDENCIES
brakeman
debug
kamal
minitest (~> 5.0)
minitest-reporters
pg (~> 1.1)
puma (>= 5.0)
rails (~> 8.1.1)
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/v1/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module V1
class ApplicationController < BaseController
def index
render html: "Hello, World!"
end
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/v1/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Api::V1
class BaseController < ActionController::API
end
end
9 changes: 9 additions & 0 deletions app/controllers/api/v1/health_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module V1
class HealthController < BaseController
def index
render json: { status: "ok" }, status: :ok
end
end
end
end
13 changes: 13 additions & 0 deletions app/controllers/api/v1/root_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb

This file was deleted.

19 changes: 13 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions test/integration/api/root_redirect_test.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/integration/api/v1/api_v1_health_test.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/integration/api/v1/api_v1_root_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down