Skip to content

Commit

Permalink
Minor fixes/improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 22, 2024
1 parent dc3e0e6 commit f7b92bb
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 76 deletions.
30 changes: 15 additions & 15 deletions db/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
require 'thread/local'

module VMail
case Variant.default
when :production
MAIL_ROOT = "/srv/mail"
DOMAIN = 'https://mail.oriontransfer.net'
CREDENTIALS = {username: 'http', database: 'vmail'}
when :development
MAIL_ROOT = "db/mail"
DOMAIN = 'https://localhost'
CREDENTIALS = {username: 'test', password: 'test', database: 'vmail_development'}
when :testing
MAIL_ROOT = "db/mail"
DOMAIN = 'https://localhost'
CREDENTIALS = {username: 'test', password: 'test', database: 'test'}
end

module Database
extend Thread::Local

case Variant.default
when :production
MAIL_ROOT = "/srv/mail"
DOMAIN = 'https://mail.oriontransfer.net'
CREDENTIALS = {username: 'http', database: 'vmail'}
when :development
MAIL_ROOT = "db/mail"
DOMAIN = 'https://localhost'
CREDENTIALS = {username: 'test', password: 'test', database: 'vmail_development'}
when :testing
MAIL_ROOT = "db/mail"
DOMAIN = 'https://localhost'
CREDENTIALS = {username: 'test', password: 'test', database: 'test', unix_socket: "/opt/local/var/run/mariadb-10.11/mysqld.sock"}
end

def self.local
DB::Client.new(DB::MariaDB::Adapter.new(**CREDENTIALS))
end
Expand Down
4 changes: 2 additions & 2 deletions fixtures/website_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def app
end

def middleware
Falcon::Middleware::Verbose.new(
# Falcon::Middleware::Verbose.new(
Protocol::Rack::Adapter.new(app)
)
# )
end
end
66 changes: 36 additions & 30 deletions gems.locked
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
GIT
remote: https://github.com/socketry/db-migrate
revision: c0d46eb1934aa056a024e6a7677bc4afea3a172c
specs:
db-migrate (0.1.0)
db
migrate (~> 0.3)

GIT
remote: https://github.com/socketry/db-model
revision: c369a05d33086bed21964dd70402d378fbf55e53
specs:
db-model (0.4.0)
db (~> 0.10.0)

GEM
remote: https://rubygems.org/
specs:
Expand All @@ -26,7 +11,7 @@ GEM
async
async-container (0.18.3)
async (~> 2.10)
async-http (0.77.0)
async-http (0.78.0)
async (>= 2.10.2)
async-pool (~> 0.7)
io-endpoint (~> 0.11)
Expand Down Expand Up @@ -79,13 +64,17 @@ GEM
console (~> 1.0)
msgpack (~> 1.0)
date (3.3.4)
db (0.10.3)
async-io
db (0.12.0)
async-pool
db-mariadb (0.11.2)
async-pool
bigdecimal
ffi-module (~> 0.3.0)
db-migrate-x (0.2.0)
db
migrate (~> 0.3)
db-model (0.5.0)
db (~> 0.11)
falcon (0.48.0)
async
async-container (~> 0.18)
Expand All @@ -99,8 +88,17 @@ GEM
protocol-http (~> 0.31)
protocol-rack (~> 0.7)
samovar (~> 2.3)
ffi (1.17.0)
ffi (1.17.0-aarch64-linux-gnu)
ffi (1.17.0-aarch64-linux-musl)
ffi (1.17.0-arm-linux-gnu)
ffi (1.17.0-arm-linux-musl)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86-linux-gnu)
ffi (1.17.0-x86-linux-musl)
ffi (1.17.0-x86_64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
ffi (1.17.0-x86_64-linux-musl)
ffi-module (0.3.0)
ffi
fiber-annotation (0.2.0)
Expand Down Expand Up @@ -149,7 +147,7 @@ GEM
protocol-http2 (0.18.0)
protocol-hpack (~> 1.4)
protocol-http (~> 0.18)
protocol-rack (0.8.0)
protocol-rack (0.9.0)
protocol-http (~> 0.27)
rack (>= 1.0)
protocol-websocket (0.17.0)
Expand All @@ -174,10 +172,6 @@ GEM
thread-local (1.1.0)
timeout (0.4.1)
traces (0.13.1)
trenni (3.14.0)
trenni-formatters (2.13.1)
mapping (~> 1.1)
trenni (~> 3.12)
utopia (2.25.0)
bake (~> 0.20)
concurrent-ruby (~> 1.2)
Expand All @@ -195,23 +189,35 @@ GEM
variant (0.1.1)
thread-local
xrb (0.6.1)
xrb-formatters (0.1.0)
mapping (~> 1.1)
xrb (~> 0.6)
xrb-sanitize (0.7.1)
xrb (~> 0.3)

PLATFORMS
arm64-darwin-22
arm64-darwin-24
x86_64-linux
aarch64-linux-gnu
aarch64-linux-musl
arm-linux-gnu
arm-linux-musl
arm64-darwin
ruby
x86-linux-gnu
x86-linux-musl
x86_64-darwin
x86_64-linux-gnu
x86_64-linux-musl

DEPENDENCIES
async-http (~> 0.78.0)
bake
benchmark-http
bundler
covered
db
db-mariadb
db-migrate!
db-model!
db-migrate-x
db-model
falcon
latinum (~> 1.0)
mapping (~> 1.0)
Expand All @@ -222,9 +228,9 @@ DEPENDENCIES
sus-fixtures-async-http
sus-fixtures-async-webdriver (~> 0.2)
thread-local
trenni-formatters (~> 2.0)
utopia (~> 2.17)
variant
xrb-formatters

BUNDLED WITH
2.4.19
2.5.16
7 changes: 4 additions & 3 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@

gem "db"
gem "db-mariadb"
gem "db-model", git: "https://github.com/socketry/db-model"
gem "db-migrate", git: "https://github.com/socketry/db-migrate"
gem "db-model"
gem "db-migrate-x"

gem "migrate"
gem "latinum", "~> 1.0"
gem "mapping", "~> 1.0"
gem "thread-local"

gem "trenni-formatters", "~> 2.0"
gem "xrb-formatters"
end

gem 'bake'
gem 'bundler'
gem 'rack-test'
gem "async-http", "~> 0.78.0"

group :test do
gem "sus"
Expand Down
11 changes: 10 additions & 1 deletion lib/vmail/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'securerandom'
require 'digest/sha1'
require 'base64'
require 'open3'

module VMail
class Account
Expand Down Expand Up @@ -53,7 +54,15 @@ def home_path
end

def disk_usage_string
`sudo -n du -hs #{home_path.dump}`.split(/\s+/).first
command = ["sudo", "-n", "du", "-hs", home_path]

stdout, stderr, status = Open3.capture3(*command)

if status.success?
stdout.split(/\s+/).first
else
"Unknown: #{stderr}"
end
end

def email_address
Expand Down
14 changes: 7 additions & 7 deletions lib/vmail/formatters.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

require 'trenni/formatters'
require 'trenni/formatters/html/definition_list_form'
require 'trenni/formatters/html/option_select'
require 'xrb/formatters'
require 'xrb/formatters/html/definition_list_form'
require 'xrb/formatters/html/option_select'

module VMail
class Attributes
Expand Down Expand Up @@ -52,7 +52,7 @@ def assign(parameters, object)
end
end

class ViewFormatter < Trenni::Formatters::Formatter
class ViewFormatter < XRB::Formatters::Formatter
map(Time) do |object, options|
# Ensure we display the time in localtime, and show the year if it is different:
if object.localtime.year != Time.now.year
Expand All @@ -71,7 +71,7 @@ def approximate_number(object, **options)
end

def mailto(email_address)
Trenni::Builder.fragment do |builder|
XRB::Builder.fragment do |builder|
builder.inline(:a, :href => "mailto:#{email_address}") { builder.text email_address }
end
end
Expand Down Expand Up @@ -109,14 +109,14 @@ def self.time_ago_in_words(timestamp)
end

class FormFormatter < ViewFormatter
include Trenni::Formatters::HTML::DefinitionListForm
include XRB::Formatters::HTML::DefinitionListForm

map(Time) do |object, options|
object.httpdate
end

def select(**options, &block)
element(Trenni::Formatters::HTML::OptionSelect, **options, &block)
element(XRB::Formatters::HTML::OptionSelect, **options, &block)
end
end
end
4 changes: 2 additions & 2 deletions lib/vmail/password_reset.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

require_relative 'domain'

require 'trenni/uri'
require 'xrb/uri'

module VMail
module TimestampWithoutTimeZone
Expand Down Expand Up @@ -44,7 +44,7 @@ def flatten!
end

def url(domain = DOMAIN)
Trenni::URI("#{domain}/password-reset/index", id: self.id, token: self.token)
XRB::URI("#{domain}/password-reset/index", id: self.id, token: self.token)
end

EXPIRES_AFTER = (60 * 60 * 24 * 2)
Expand Down
4 changes: 2 additions & 2 deletions test/pages/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
session.fill_in "password", password

session.click_button "Login"
rescue => error
pp error: error.inspect
expect(session).to have_element(xpath: "//table[@class='listing']//td[text()='test@localhost']")
end
end
6 changes: 3 additions & 3 deletions test/vmail/password_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
expect(@password_reset.used_at).to be_nil
expect(@password_reset.token).not.to be_nil

get Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token)
get XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token)

expect(last_response.status).to be == 200

post Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token), {
post XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token), {
password_plaintext: new_password
}

Expand All @@ -37,7 +37,7 @@
end

it "should be fail to reset password if token is invalid" do
get Trenni::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token + 'bad')
get XRB::URI("/password-reset/index", id: @password_reset.id, token: @password_reset.token + 'bad')

expect(last_response.status).to be == 404
end
Expand Down
11 changes: 0 additions & 11 deletions test/website.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,4 @@
expect(statistics.samples).to be(:any?)
expect(statistics.failed).to be(:zero?)
end

with "interactive session" do
include WebDriverContext

it "can visit the front page" do
visit "/"

elements = find_elements(xpath: "//*[contains(text(), 'Seamless Scalability for Ruby')]")
expect(elements).to be(:any?)
end
end
end

0 comments on commit f7b92bb

Please sign in to comment.