Skip to content

Commit 73aa223

Browse files
author
Alec Clarke
committed
Create Github Action for running CI tests
This adds CI Github Action that will run the RSpec test suite against all `gemfiles`/ supported Rails versions when pull requests are opened against the `master` branch or commits are pushed to the `master` branch. This will help ensure we don't merge breaking changes + make it easier to review pull requests from all contributors.
1 parent 46db818 commit 73aa223

File tree

11 files changed

+48
-11
lines changed

11 files changed

+48
-11
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
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+
gemfile:
16+
- Gemfile.rails-5.0-stable
17+
- Gemfile.rails-5.1-stable
18+
- Gemfile.rails-5.2-stable
19+
- Gemfile.rails-6.0-stable
20+
env:
21+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Set up Ruby
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
ruby-version: "2.6"
28+
bundler-cache: true
29+
- name: Run tests
30+
run: bundle exec rspec

spec/spec_helper.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717
RSpec.configure do |config|
1818
config.before(:suite) do
1919
database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml"))
20+
migrations_path = "#{File.dirname(__FILE__)}/support/migrations"
21+
active_record_version = Gem::Version.new(ActiveRecord::VERSION::STRING)
22+
2023
ActiveRecord::Base.establish_connection(database_config)
2124

22-
if Gem::Version.new(ActiveRecord::VERSION::STRING) == Gem::Version.new("5.2.0")
23-
ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate
25+
if active_record_version < Gem::Version.new("5.2")
26+
ActiveRecord::Migrator.migrate(migrations_path)
27+
end
28+
29+
if active_record_version >= Gem::Version.new("5.2") && active_record_version < Gem::Version.new("6.0")
30+
ActiveRecord::MigrationContext.new(migrations_path).migrate
2431
end
2532

26-
if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("6.0")
27-
ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations", ActiveRecord::SchemaMigration).migrate
33+
if active_record_version >= Gem::Version.new("6.0")
34+
ActiveRecord::MigrationContext.new(migrations_path, ActiveRecord::SchemaMigration).migrate
2835
end
2936
end
3037

spec/support/migrations/1_create_link_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateLinkTable < ActiveRecord::Migration[5.2]
1+
class CreateLinkTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :links do |t|

spec/support/migrations/2_create_animal_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateAnimalTable < ActiveRecord::Migration[5.2]
1+
class CreateAnimalTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :animals do |t|

spec/support/migrations/3_create_person_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreatePersonTable < ActiveRecord::Migration[5.2]
1+
class CreatePersonTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :people do |t|

spec/support/migrations/4_create_food_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateFoodTable < ActiveRecord::Migration[5.2]
1+
class CreateFoodTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :foods do |t|

spec/support/migrations/5_create_drink_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreateDrinkTable < ActiveRecord::Migration[5.2]
1+
class CreateDrinkTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :drinks do |t|

spec/support/migrations/6_create_plant_table.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class CreatePlantTable < ActiveRecord::Migration[5.2]
1+
class CreatePlantTable < ActiveRecord::Migration[5.0]
22

33
def up
44
create_table :plants do |t|

0 commit comments

Comments
 (0)