Skip to content

Commit cad070d

Browse files
committed
Setup Github Action for specs
1 parent 9b9b742 commit cad070d

9 files changed

Lines changed: 107 additions & 94 deletions

File tree

.circleci/config.yml

Lines changed: 0 additions & 61 deletions
This file was deleted.

.github/workflows/mysql.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Specs - MySQL
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
ruby: ['2.5', '2.6', '2.7']
16+
17+
env:
18+
DB_TEST: mysql
19+
MYSQL_DB_HOST: 127.0.0.1
20+
MYSQL_DB_USERNAME: root
21+
MYSQL_DB_PASSWORD: root
22+
23+
services:
24+
mysql:
25+
image: mysql:5.7
26+
env:
27+
MYSQL_USER: root
28+
MYSQL_PASSWORD: root
29+
ports:
30+
- 3306:3306
31+
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
- name: Set up Ruby
36+
uses: ruby/setup-ruby@v1
37+
with:
38+
ruby-version: ${{ matrix.ruby }}
39+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
40+
- name: Start database service
41+
run: sudo /etc/init.d/mysql start
42+
- name: Set up database
43+
run: bundle exec rails db:setup
44+
- name: Run tests
45+
run: bundle exec rake

.github/workflows/postgres.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Specs - Postgres
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
ruby: ['2.5', '2.6', '2.7']
16+
17+
env:
18+
DB_TEST: postgres
19+
PG_DB_HOST: 127.0.0.1
20+
PG_DB_USERNAME: postgres
21+
PG_DB_PASSWORD: postgres
22+
23+
services:
24+
postgres:
25+
image: postgres:latest
26+
env:
27+
POSTGRES_USER: postgres
28+
POSTGRES_PASSWORD: postgres
29+
options: >-
30+
--health-cmd pg_isready
31+
--health-interval 10s
32+
--health-timeout 5s
33+
--health-retries 5
34+
ports:
35+
- 5432:5432
36+
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v2
40+
- name: Set up Ruby
41+
uses: ruby/setup-ruby@v1
42+
with:
43+
ruby-version: ${{ matrix.ruby }}
44+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
45+
- name: Set up database
46+
run: bundle exec rails db:setup
47+
- name: Run tests
48+
run: bundle exec rake

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Active Storage DB [![Gem Version](https://badge.fury.io/rb/active_storage_db.svg)](https://badge.fury.io/rb/active_storage_db) [![CircleCI](https://circleci.com/gh/blocknotes/active_storage_db.svg?style=svg)](https://circleci.com/gh/blocknotes/active_storage_db)
1+
# Active Storage DB [![Gem Version](https://badge.fury.io/rb/active_storage_db.svg)](https://badge.fury.io/rb/active_storage_db) [![Specs - Postgres](https://github.com/blocknotes/active_storage_db/actions/workflows/postgres.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/postgres.yml) [![Specs - MySQL](https://github.com/blocknotes/active_storage_db/actions/workflows/mysql.yml/badge.svg)](https://github.com/blocknotes/active_storage_db/actions/workflows/mysql.yml)
22
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database.
33

44
Main features:

bin/rails

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# This command will automatically be run when you run "rails" with Rails gems
33
# installed from the root of your application.
44

5-
ENV['DB'] ||= 'postgres'
5+
ENV['DB_TEST'] ||= 'postgres'
66
ENV['RAILS_ENV'] ||= 'test'
77

88
ENGINE_ROOT = File.expand_path('..', __dir__)

spec/dummy/config/database.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
<% case ENV['DB']
1+
<% case ENV['DB_TEST']
22
when 'mysql' %>
33
test:
44
adapter: mysql2
55
host: <%= ENV.fetch('MYSQL_DB_HOST') { '127.0.0.1' } %>
6-
database: <%= ENV.fetch('MYSQL_DB_NAME') { 'active_storage_db_dummy_test' } %>
6+
port: <%= ENV.fetch('MYSQL_DB_PORT') { 3306 } %>
7+
database: <%= ENV.fetch('MYSQL_DB_NAME') { 'active_storage_db-test' } %>
78
username: <%= ENV.fetch('MYSQL_DB_USERNAME') { 'root' } %>
89
password: <%= ENV.fetch('MYSQL_DB_PASSWORD') { '' } %>
910
encoding: utf8
@@ -12,12 +13,12 @@ test:
1213
test:
1314
adapter: postgresql
1415
host: <%= ENV.fetch('PG_DB_HOST') { '127.0.0.1' } %>
15-
database: <%= ENV.fetch('PG_DB_NAME') { 'active_storage_db_dummy_test' } %>
16+
database: <%= ENV.fetch('PG_DB_NAME') { 'active_storage_db-test' } %>
1617
username: <%= ENV.fetch('PG_DB_USERNAME') { '' } %>
1718
password: <%= ENV.fetch('PG_DB_PASSWORD') { '' } %>
1819
encoding: utf8
1920
min_messages: warning
2021
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
2122
<% else %>
22-
<% raise "Invalid or empty env DB #{ENV['DB']}" %>
23+
<% raise "Invalid or empty env DB_TEST #{ENV['DB_TEST']}" %>
2324
<% end %>

spec/dummy/db/migrate/20200702202022_create_active_storage_db_files.active_storage_db.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

spec/rails_helper.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
require 'rspec/rails'
1616
require 'factory_bot_rails'
1717

18-
Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
18+
support_files = File.expand_path('support/**/*.rb', __dir__)
19+
Dir[support_files].sort.each { |f| require f }
1920

2021
begin
2122
ActiveRecord::Migration.maintain_test_schema!
@@ -26,14 +27,7 @@
2627

2728
RSpec.configure do |config|
2829
config.fixture_path = "#{::Rails.root}/spec/fixtures"
29-
30-
config.use_transactional_fixtures = true
31-
30+
# config.use_transactional_fixtures = true
3231
config.infer_spec_type_from_file_location!
33-
3432
config.filter_rails_from_backtrace!
35-
36-
###
37-
38-
config.include FactoryBot::Syntax::Methods
3933
end

spec/support/database_cleaner.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
MSG
2020
end
2121

22-
DatabaseCleaner.clean_with(:truncation, except: %w[spree_preferences])
22+
DatabaseCleaner.clean_with(:truncation)
2323
end
2424

2525
config.before do
2626
DatabaseCleaner.strategy = :transaction
2727
end
2828

2929
config.before(:example, type: :with_truncation_strategy) do
30-
DatabaseCleaner.strategy = :truncation, { except: %w[spree_preferences] }
30+
DatabaseCleaner.strategy = :truncation
3131
end
3232

3333
config.before(:each, type: :feature) do
@@ -39,7 +39,7 @@
3939
# Driver is probably for an external browser with an app
4040
# under test that does *not* share a database connection with the
4141
# specs, so use truncation strategy.
42-
DatabaseCleaner.strategy = :truncation, { except: %w[spree_preferences] }
42+
DatabaseCleaner.strategy = :truncation
4343
end
4444
end
4545

@@ -52,6 +52,6 @@
5252
end
5353

5454
config.append_after(:suite) do
55-
DatabaseCleaner.clean_with(:truncation, only: %w[spree_preferences])
55+
DatabaseCleaner.clean_with(:truncation)
5656
end
5757
end

0 commit comments

Comments
 (0)