Skip to content

Commit 684ddb8

Browse files
author
Mattia Roccoberton
committed
Var env for Rails version
1 parent 6666c79 commit 684ddb8

8 files changed

Lines changed: 20 additions & 13 deletions

File tree

.github/workflows/mysql_rails7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
MYSQL_DB_HOST: 127.0.0.1
2323
MYSQL_DB_USERNAME: root
2424
MYSQL_DB_PASSWORD: root
25-
RAILS_7: true
25+
RAILS: '7.0'
2626

2727
services:
2828
mysql:

.github/workflows/postgres_rails7.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
PG_DB_HOST: 127.0.0.1
2323
PG_DB_USERNAME: postgres
2424
PG_DB_PASSWORD: postgres
25-
RAILS_7: true
25+
RAILS: '7.0'
2626

2727
services:
2828
postgres:

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
1616
rdoc.rdoc_files.include('lib/**/*.rb')
1717
end
1818

19-
dummy_app = ENV['RAILS_7'] ? 'dummy7' : 'dummy'
19+
dummy_app = (ENV['RAILS'] == '7.0' ? 'dummy7' : 'dummy')
2020
APP_RAKEFILE = File.expand_path("spec/#{dummy_app}/Rakefile", __dir__)
2121
load 'rails/tasks/engine.rake'
2222

bin/rails

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
ENV['DB_TEST'] ||= 'postgres'
66
ENV['RAILS_ENV'] ||= 'test'
77

8-
dummy_app = ENV['RAILS_7'] ? 'dummy7' : 'dummy'
8+
dummy_app = (ENV['RAILS'] == '7.0' ? 'dummy7' : 'dummy')
99

1010
ENGINE_ROOT = File.expand_path('..', __dir__)
1111
ENGINE_PATH = File.expand_path('../lib/active_storage_db/engine', __dir__)

extra/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
# Development
22

33
```sh
4+
# Running tests on Rails 6.0:
5+
DB_TEST=postgres RAILS=6.0 bin/appraisal rails-6_0-postgres rails db:drop db:create db:migrate
6+
DB_TEST=postgres RAILS=6.0 bin/appraisal rails-6_0-postgres rspec
7+
48
# Running tests on Rails 6.1:
5-
DB_TEST=postgres bin/appraisal rails-6_1-postgres rspec
9+
DB_TEST=postgres RAILS=6.1 bin/appraisal rails-6_1-postgres rails db:drop db:create db:migrate
10+
DB_TEST=postgres RAILS=6.1 bin/appraisal rails-6_1-postgres rspec
11+
612
# Running tests on Rails 7.0:
7-
DB_TEST=postgres RAILS_7=1 bin/appraisal rails-7_0-postgres rspec
13+
DB_TEST=postgres RAILS=7.0 bin/appraisal rails-7_0-postgres rails db:drop db:create db:migrate
14+
DB_TEST=postgres RAILS=7.0 bin/appraisal rails-7_0-postgres rspec
815
```
916

1017
## Tests using Docker

spec/dummy/config/database.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test: &test
44
adapter: mysql2
55
host: <%= ENV.fetch('MYSQL_DB_HOST') { '127.0.0.1' } %>
66
# port: <%= ENV.fetch('MYSQL_DB_PORT') { 3306 } %>
7-
database: <%= ENV.fetch('MYSQL_DB_NAME') { 'active_storage_db-test' } %>
7+
database: <%= ENV.fetch('MYSQL_DB_NAME') { "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-test" } %>
88
username: <%= ENV.fetch('MYSQL_DB_USERNAME') { '' } %>
99
password: <%= ENV.fetch('MYSQL_DB_PASSWORD') { '' } %>
1010
encoding: utf8
@@ -13,7 +13,7 @@ test: &test
1313
test: &test
1414
adapter: postgresql
1515
host: <%= ENV.fetch('PG_DB_HOST') { '127.0.0.1' } %>
16-
database: <%= ENV.fetch('PG_DB_NAME') { 'active_storage_db-test' } %>
16+
database: <%= ENV.fetch('PG_DB_NAME') { "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-test" } %>
1717
username: <%= ENV.fetch('PG_DB_USERNAME') { '' } %>
1818
password: <%= ENV.fetch('PG_DB_PASSWORD') { '' } %>
1919
encoding: utf8
@@ -25,4 +25,4 @@ test: &test
2525

2626
development:
2727
<<: *test
28-
database: active_storage_db-dev
28+
database: "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-dev"

spec/dummy7/config/database.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ test: &test
44
adapter: mysql2
55
host: <%= ENV.fetch('MYSQL_DB_HOST') { '127.0.0.1' } %>
66
# port: <%= ENV.fetch('MYSQL_DB_PORT') { 3306 } %>
7-
database: <%= ENV.fetch('MYSQL_DB_NAME') { 'active_storage_db-test' } %>
7+
database: <%= ENV.fetch('MYSQL_DB_NAME') { "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-test" } %>
88
username: <%= ENV.fetch('MYSQL_DB_USERNAME') { '' } %>
99
password: <%= ENV.fetch('MYSQL_DB_PASSWORD') { '' } %>
1010
encoding: utf8
@@ -13,7 +13,7 @@ test: &test
1313
test: &test
1414
adapter: postgresql
1515
host: <%= ENV.fetch('PG_DB_HOST') { '127.0.0.1' } %>
16-
database: <%= ENV.fetch('PG_DB_NAME') { 'active_storage_db-test' } %>
16+
database: <%= ENV.fetch('PG_DB_NAME') { "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-test" } %>
1717
username: <%= ENV.fetch('PG_DB_USERNAME') { '' } %>
1818
password: <%= ENV.fetch('PG_DB_PASSWORD') { '' } %>
1919
encoding: utf8
@@ -25,4 +25,4 @@ test: &test
2525

2626
development:
2727
<<: *test
28-
database: active_storage_db-dev
28+
database: "active_storage_db_#{ENV['RAILS']&.tr('.', '')}-dev"

spec/rails_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
require 'spec_helper'
1212
ENV['RAILS_ENV'] ||= 'test'
1313

14-
dummy_app = ENV['RAILS_7'] ? 'dummy7' : 'dummy'
14+
dummy_app = (ENV['RAILS'] == '7.0' ? 'dummy7' : 'dummy')
1515
require File.expand_path("#{dummy_app}/config/environment.rb", __dir__)
1616

1717
abort('The Rails environment is running in production mode!') if Rails.env.production?

0 commit comments

Comments
 (0)