Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 20, 2024
1 parent 5c68d9d commit dc3e0e6
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
37 changes: 22 additions & 15 deletions db/environment.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@

require 'db/client'
require 'db/mariadb'
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', host: '127.0.0.1'}
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
end

DATABASE = DB::Client.new(DB::MariaDB::Adapter.new(**CREDENTIALS))
end
4 changes: 3 additions & 1 deletion gems.locked
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-24
x86_64-linux

DEPENDENCIES
Expand All @@ -220,9 +221,10 @@ DEPENDENCIES
sus
sus-fixtures-async-http
sus-fixtures-async-webdriver (~> 0.2)
thread-local
trenni-formatters (~> 2.0)
utopia (~> 2.17)
variant

BUNDLED WITH
2.5.16
2.4.19
1 change: 1 addition & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
gem "migrate"
gem "latinum", "~> 1.0"
gem "mapping", "~> 1.0"
gem "thread-local"

gem "trenni-formatters", "~> 2.0"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/vmail/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ def account_for_email_address(email_address)

def self.transaction(&block)
Sync do
DATABASE.transaction(&block)
Database.instance.transaction(&block)
end
end

def self.schema
Sync do
DATABASE.transaction do |session|
Database.instance.transaction do |session|
yield Schema.new(session)
end
end
Expand Down
2 changes: 1 addition & 1 deletion migrate/20210527233058-schema.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../config/environment'
require 'db/migrate'

migrate(VMail::DATABASE, using: DB::Migrate) do
migrate(VMail::Database.instance, using: DB::Migrate) do
create_table :accounts, if_not_exists: true do
primary_key :id
column :local_part, "TEXT", null: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'vmail'

describe VMail::PasswordReset do
include_context "website"
include WebsiteContext
include Rack::Test::Methods

let(:new_password) {"Hello World"}

Expand All @@ -19,7 +20,7 @@

it "should be able to reset password" do
expect(@password_reset.used_at).to be_nil
expect(@password_reset.token).to_not be_nil
expect(@password_reset.token).not.to be_nil

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

Expand Down

0 comments on commit dc3e0e6

Please sign in to comment.