Skip to content

Commit 522de58

Browse files
bf4Physium
andauthored
test(ci): github (#2447)
* test(ci): github * test: try to mimic travis a bit * Change ci ruby 2.5 matrix to use rails-version 4.2 instead * Update gemfile to lock loofah gem version to be less than 2.21 for older ruby versions * Add backwards compatibility for rails-controller-testing on initialization * Add new ci matrix for ruby 2.5 and rails 5.2 * Fix failing test due to mismatch test output * Remove rails version older than 4.2 from ci matrix * Add ruby 2.7 and 2.6 to ci matrix --------- Co-authored-by: Loh Wei Jun <[email protected]>
1 parent 3a1dc44 commit 522de58

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

.github/workflows/ci.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
3+
name: CI
4+
5+
on: [push, pull_request]
6+
7+
jobs:
8+
test:
9+
name: Ruby ${{ matrix.ruby-version }} Rails ${{ matrix.rails-version }}
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
include:
15+
# Recent Rubies and Rails
16+
# - ruby-version: '3.1'
17+
# rails-version: '7.0'
18+
# - ruby-version: '3.0'
19+
# rails-version: '7.0'
20+
# - ruby-version: '2.7'
21+
# rails-version: '7.0'
22+
# - ruby-version: '2.6'
23+
# rails-version: '6.1'
24+
# - ruby-version: '2.6'
25+
# rails-version: '6.0'
26+
# - ruby-version: '2.7'
27+
# rails-version: '6.0'
28+
# - ruby-version: '2.6'
29+
# rails-version: '5.2'
30+
# Old Rubies and Rails
31+
- ruby-version: '2.7'
32+
rails-version: '5.2'
33+
- ruby-version: '2.6'
34+
rails-version: '5.2'
35+
- ruby-version: '2.5'
36+
rails-version: '5.2'
37+
- ruby-version: '2.5'
38+
rails-version: '4.2'
39+
bundler: '1'
40+
- ruby-version: '2.4'
41+
rails-version: '5.2'
42+
bundler: '1'
43+
- ruby-version: '2.4'
44+
rails-version: '4.2'
45+
bundler: '1'
46+
# - ruby-version: '2.4'
47+
# rails-version: '4.1'
48+
# bundler: '1'
49+
# - ruby-version: '2.4'
50+
# rails-version: '4.0'
51+
# bundler: '1'
52+
53+
continue-on-error: "${{ endsWith(matrix.ruby-version, 'head') }}"
54+
55+
env:
56+
CI: "1"
57+
BUNDLE_JOBS: 4
58+
BUNDLE_RETRY: 3
59+
60+
steps:
61+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
62+
- uses: actions/checkout@v3
63+
64+
- name: "Build Ruby"
65+
uses: ruby/setup-ruby@v1
66+
with:
67+
ruby-version: "${{ matrix.ruby-version }}"
68+
bundler: "${{ matrix.bundler || 2 }}"
69+
bundler-cache: true
70+
env:
71+
RAILS_VERSION: ${{ matrix.rails-version }}
72+
73+
- name: "Run tests"
74+
run: |
75+
bundle exec rake
76+
env:
77+
RAILS_VERSION: ${{ matrix.rails-version }}

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ if RUBY_VERSION < '2'
3636
end
3737

3838
if ENV['CI']
39+
# loofah has a breaking change 2.21 onwards which does not work with < 2.5 ruby
40+
gem 'loofah', '< 2.21' if RUBY_VERSION < '2.5'
41+
3942
if RUBY_VERSION < '2.4'
4043
# Windows: An error occurred while installing nokogiri (1.8.0)
4144
gem 'nokogiri', '< 1.7', platforms: @windows_platforms

test/test_helper.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
require 'minitest/autorun'
33
require 'active_model_serializers'
44
require 'fixtures/poro'
5-
require 'rails-controller-testing'
6-
Rails::Controller::Testing.install
5+
begin
6+
require 'rails-controller-testing'
7+
Rails::Controller::Testing.install
8+
rescue LoadError
9+
false # Rails 5 < backward compatibility
10+
end
11+
712

813
# Ensure backward compatibility with Minitest 4
914
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test)

test/unit/active_model/array_serializer/serialization_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def test_namespace
6666
serializer = ArraySerializer.new(array)
6767

6868
expected = [
69-
{ name: 'Test 1', email: '[email protected]', sub_test: { name: 'Name 1', description: 'Description 1' }},
70-
{ name: 'Test 1', email: '[email protected]', sub_test: { name: 'Name 2', description: 'Description 2' }}
69+
{ name: 'Test 1', email: '[email protected]', sub_test: { name: 'Name 1', description: 'Description 1' } },
70+
{ name: 'Test 2', email: '[email protected]', sub_test: { name: 'Name 2', description: 'Description 2' } }
7171
]
7272

7373
assert_equal expected, serializer.serializable_array

0 commit comments

Comments
 (0)