Skip to content

Commit 71a3431

Browse files
authored
feat: move to rails dummy app to test multidb setup (#115)
1 parent 26fd427 commit 71a3431

File tree

18 files changed

+153
-32
lines changed

18 files changed

+153
-32
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.PHONY: test-pg test-mysql
22

33
test-pg:
4-
docker compose up -d pg
5-
sleep 10 # give some time for the service to start
6-
DATABASE_URL=postgres://with_advisory:with_advisory_pass@localhost/with_advisory_lock_test appraisal rake test
4+
docker compose up -d pg
5+
sleep 10 # give some time for the service to start
6+
DATABASE_URL_PG=postgres://with_advisory:with_advisory_pass@localhost/with_advisory_lock_test appraisal rake test
77

88
test-mysql:
9-
docker compose up -d mysql
10-
sleep 10 # give some time for the service to start
11-
DATABASE_URL=mysql2://with_advisory:[email protected]:3306/with_advisory_lock_test appraisal rake test
9+
docker compose up -d mysql
10+
sleep 10 # give some time for the service to start
11+
DATABASE_URL_MYSQL=mysql2://with_advisory:[email protected]:3306/with_advisory_lock_test appraisal rake test
1212

1313

1414
test: test-pg test-mysql

bin/console

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'bundler/setup'
5+
require 'no_fly_list'
6+
7+
# You can add fixtures and/or initialization code here to make experimenting
8+
# with your gem easier. You can also use a different console, if you like.
9+
10+
require 'irb'
11+
IRB.start(__FILE__)

bin/rails

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
# This command will automatically be run when you run "rails" with Rails gems
5+
# installed from the root of your application.
6+
7+
ENGINE_ROOT = File.expand_path('../test/dummy', __dir__)
8+
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
9+
10+
# Set up gems listed in the Gemfile.
11+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
12+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
13+
14+
require 'rails/all'
15+
require 'rails/engine/commands'

bin/setup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
bin/rails db:setup
8+
bin/rails db:migrate

test/dummy/Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# Add your own tasks in files placed in lib/tasks ending in .rake,
4+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
5+
6+
require_relative "config/application"
7+
8+
Rails.application.load_tasks
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class ApplicationController < ActionController::Base
4+
# Prevent CSRF attacks by raising an exception.
5+
# For APIs, you may want to use :null_session instead.
6+
protect_from_forgery with: :exception
7+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
class ApplicationRecord < ActiveRecord::Base
4+
self.abstract_class = true
5+
end

test/dummy/app/models/label.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class Label < ApplicationRecord
4+
end

test/dummy/app/models/tag.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
class Tag < ApplicationRecord
4+
after_save do
5+
TagAudit.create(tag_name: name)
6+
Label.create(name: name)
7+
end
8+
end

test/dummy/app/models/tag_audit.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class TagAudit < ApplicationRecord
4+
end

0 commit comments

Comments
 (0)