Skip to content

Commit

Permalink
housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
simonneutert committed Jan 6, 2024
1 parent cfbfe2d commit 1157d63
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:
run: bundle exec rubocop

- name: Run tests
run: bundle exec ruby test/run_test.rb
run: bundle exec rake test
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.3
3.3.0
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ RUN bundle install

COPY . /app

ENV RUBY_YJIT_ENABLE=1

CMD ["rackup", "-o", "0", "-p", "3000"]
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ source 'https://rubygems.org'

ruby '3.2.2'

gem 'pg', '~> 1.5'
gem 'puma'

gem 'activerecord'
gem 'activesupport', '>= 6.0.3.1'
gem 'bcrypt'
gem 'coffee-script'
gem 'erubi', '~> 1.12'
gem 'haml'
gem 'pg', '~> 1.5'
gem 'rack', '~> 2.2'
gem 'rake'
gem 'sass'
gem 'sassc'
gem 'sinatra', '~> 3.1'
gem 'sinatra', '3.2'
gem 'sinatra-activerecord'
gem 'sinatra-contrib', '~> 3.1'
gem 'sinatra-flash'
gem 'sprockets'
gem 'thin'
gem 'turbolinks'
gem 'uglifier'
gem 'warden'
Expand All @@ -30,5 +32,5 @@ group :test, :development do
gem 'rack-test', '~> 2.1'
gem 'rubocop', require: false
gem 'solargraph', require: false
gem 'test-unit', '~> 3.6'
gem 'test-unit', '~> 3.6', require: false
end
56 changes: 31 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,19 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
benchmark (0.3.0)
bigdecimal (3.1.4)
bigdecimal (3.1.5)
coderay (1.1.3)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
daemons (1.4.1)
diff-lcs (1.5.0)
drb (2.2.0)
ruby2_keywords
e2mmap (0.1.0)
erubi (1.12.0)
eventmachine (1.2.7)
execjs (2.9.1)
ffi (1.16.3)
haml (6.3.0)
Expand All @@ -53,31 +51,39 @@ GEM
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
mini_portile2 (2.8.5)
minitest (5.20.0)
multi_json (1.15.0)
mustermann (3.0.0)
ruby2_keywords (~> 0.0.1)
mutex_m (0.2.0)
nokogiri (1.15.5)
mini_portile2 (~> 2.8.2)
nio4r (2.7.0)
nokogiri (1.16.0-aarch64-linux)
racc (~> 1.4)
nokogiri (1.15.5-arm64-darwin)
nokogiri (1.16.0-arm-linux)
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
nokogiri (1.16.0-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.0-x86-linux)
racc (~> 1.4)
nokogiri (1.16.0-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.0-x86_64-linux)
racc (~> 1.4)
parallel (1.24.0)
parser (3.2.2.4)
parser (3.3.0.0)
ast (~> 2.4.1)
racc
pg (1.5.4)
power_assert (2.0.3)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
puma (6.4.1)
nio4r (~> 2.0)
racc (1.7.3)
rack (2.2.8)
rack-protection (3.1.0)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rack-test (2.1.0)
rack (>= 1.3)
Expand Down Expand Up @@ -113,19 +119,19 @@ GEM
rb-inotify (~> 0.9, >= 0.9.7)
sassc (2.4.0)
ffi (~> 1.9)
sinatra (3.1.0)
sinatra (3.2.0)
mustermann (~> 3.0)
rack (~> 2.2, >= 2.2.4)
rack-protection (= 3.1.0)
rack-protection (= 3.2.0)
tilt (~> 2.0)
sinatra-activerecord (2.0.27)
activerecord (>= 4.1)
sinatra (>= 1.0)
sinatra-contrib (3.1.0)
multi_json
sinatra-contrib (3.2.0)
multi_json (>= 0.0.2)
mustermann (~> 3.0)
rack-protection (= 3.1.0)
sinatra (= 3.1.0)
rack-protection (= 3.2.0)
sinatra (= 3.2.0)
tilt (~> 2.0)
sinatra-flash (0.3.0)
sinatra (>= 1.0.0)
Expand All @@ -151,10 +157,6 @@ GEM
temple (0.10.3)
test-unit (3.6.1)
power_assert
thin (1.8.2)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thor (1.3.0)
tilt (2.3.0)
timeout (0.4.1)
Expand All @@ -172,8 +174,11 @@ GEM
yui-compressor (0.12.0)

PLATFORMS
arm64-darwin-21
ruby
aarch64-linux
arm-linux
arm64-darwin
x86-linux
x86_64-darwin
x86_64-linux

DEPENDENCIES
Expand All @@ -185,19 +190,20 @@ DEPENDENCIES
haml
pg (~> 1.5)
pry
puma
rack (~> 2.2)
rack-test (~> 2.1)
rake
rubocop
sass
sassc
sinatra (~> 3.1)
sinatra (= 3.2)
sinatra-activerecord
sinatra-contrib (~> 3.1)
sinatra-flash
solargraph
sprockets
test-unit (~> 3.6)
thin
turbolinks
uglifier
warden
Expand All @@ -207,4 +213,4 @@ RUBY VERSION
ruby 3.2.2p53

BUNDLED WITH
2.4.20
2.5.4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You need **Ruby (>= 3.2)** and **Bundler** (of course).
* `$ bundle install`
* edit __config/database.yml__
* `$ rake db:setup`
* `$ thin start` or `rerun rackup` ([rerun](https://github.com/alexch/rerun) gem - _not included by default!_)
* `$ bundle exec rackup` or `rerun rackup` ([rerun](https://github.com/alexch/rerun) gem - _not included by default!_)
* edit titles in __views/layout.erb__ and __views/nav.erb__
* check/set timezone __config/timezone.rb__

Expand Down
14 changes: 14 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
# read more about what rake does
# https://github.com/ruby/rake

require 'rake/testtask'
require 'sinatra'
require 'sinatra/base'
require 'sinatra/activerecord'
require 'sinatra/activerecord/rake'

require 'pry' unless ENV['APP_ENV'] == 'production'

require_relative 'app'

Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end

desc 'This a sample rake task'
# $ rake cron_rake_task
task :cron_rake_task do
puts 'Run!'
end

task default: :test
27 changes: 14 additions & 13 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

# require gems and libs
require 'bundler/setup'

require 'sinatra'
require 'sinatra/base'
require 'sinatra/flash'
Expand All @@ -11,23 +12,12 @@
require 'coffee-script'
require 'execjs'
require 'sinatra/activerecord'
require 'warden'
require 'bcrypt'
require 'rack/protection'
require 'warden'

require 'pry' unless ENV['APP_ENV'] == 'production'

# require libs
Dir['./lib/*.rb'].each { |file| require_relative file }
# require configurations
Dir['./config/*.rb'].each { |file| require_relative file }
# require models
Dir['./models/*.rb'].each { |file| require_relative file }
# require controllers
Dir['./controllers/*.rb'].each { |file| require_relative file }
# require routes
Dir['./routes/*.rb'].each { |file| require_relative file }

# modular Sinatra app inherit from Sinatra::Base
class MyApp < Sinatra::Base
# Boolean specifying whether the HTTP POST _method parameter
Expand Down Expand Up @@ -60,3 +50,14 @@ class MyApp < Sinatra::Base
# always add protection last!
use Rack::Protection
end

# require libs
Dir['./lib/*.rb'].each { |file| require_relative file }
# require configurations
Dir['./config/*.rb'].each { |file| require_relative file }
# require models
Dir['./models/*.rb'].each { |file| require_relative file }
# require controllers
Dir['./controllers/*.rb'].each { |file| require_relative file }
# require routes
Dir['./routes/*.rb'].each { |file| require_relative file }
4 changes: 2 additions & 2 deletions config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# this file kicks up the app!
# run: "thin start"
require "#{File.dirname(__FILE__)}/app"
require_relative 'app'

run MyApp
6 changes: 3 additions & 3 deletions lib/warden.rb → lib/warden_setup.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class MyApp < Sinatra::Base
use Warden::Manager do |config|
use ::Warden::Manager do |config|
# Tell Warden how to save our User info into a session.
# Sessions can only take strings, not Ruby code, we'll store
# the User's `id`
Expand All @@ -23,7 +23,7 @@ class MyApp < Sinatra::Base
config.failure_app = self
end

Warden::Manager.before_failure do |env, _opts|
::Warden::Manager.before_failure do |env, _opts|
# Because authentication failure can happen on any request but
# we handle it only under "post '/auth/unauthenticated'", we need
# to change request to POST
Expand All @@ -35,7 +35,7 @@ class MyApp < Sinatra::Base
env[key]['_method'] = String.new('post') if key == 'rack.request.form_hash'
end
end
Warden::Strategies.add(:password) do
::Warden::Strategies.add(:password) do
def valid?
params['user'] && params['user']['username'] && params['user']['password']
end
Expand Down
16 changes: 5 additions & 11 deletions test/homepage_test.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
# frozen_string_literal: true

require 'test/unit'
require 'rack/test'
require 'json'
require 'test_helper'

OUTER_APP = Rack::Builder.parse_file('config.ru').first

class HomepageTest < Test::Unit::TestCase
include Rack::Test::Methods

def app
->(_env) { [200, { 'content-type' => 'text/plain' }, ['All responses are OK']] }
OUTER_APP
end

def test_response_is_ok
# Optionally set headers used for all requests in this spec:
# header 'accept-charset', 'utf-8'

# First argument is treated as the path
def test_root
get '/'

assert last_response.ok?
assert_equal 'All responses are OK', last_response.body
end
end
12 changes: 0 additions & 12 deletions test/run_test.rb

This file was deleted.

10 changes: 10 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'test/unit'
require 'rack/test'
require 'active_support'

require 'rack/builder'
require 'json'

$LOAD_PATH.unshift File.expand_path('../lib', __dir__)

0 comments on commit 1157d63

Please sign in to comment.