Skip to content

Commit 699aebb

Browse files
Merge pull request #57 from TIOJ-INFOR-Online-Judge/fix/ci-tests
Fix CI tests and add github workflows
2 parents 51ad881 + 7ba8d26 commit 699aebb

File tree

10 files changed

+84
-19
lines changed

10 files changed

+84
-19
lines changed

.github/workflows/ci.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
tests:
11+
name: Rails CI Tests
12+
runs-on: ubuntu-latest
13+
14+
services:
15+
mysql-container:
16+
image: mysql:8.0
17+
env:
18+
MYSQL_ROOT_PASSWORD: somepassword
19+
ports:
20+
- "3306:3306"
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v5
25+
26+
- name: Setup Ruby
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: "3.3.7"
30+
bundler-cache: true
31+
32+
- name: Install dependencies
33+
run: |
34+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
35+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
36+
sudo apt-get update && sudo apt-get -yqq install imagemagick yarn libzstd-dev libmysqlclient-dev
37+
bundle install --jobs 4 --retry 3
38+
39+
- name: Run Tests
40+
env:
41+
RAILS_ENV: test
42+
run: |
43+
cp config/database.ci.yml config/database.yml
44+
bundle exec rails db:prepare
45+
bundle exec rails test

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ gem 'nested_form'
4848
gem 'carrierwave'
4949
gem 'mini_magick'
5050
# compression
51-
gem 'zstd-ruby'
51+
gem 'zstd-ruby', '~> 1.5', '>= 1.5.6.7'
5252
gem 'rubyzip', '~> 2', require: 'zip'
5353

5454
# Mathjax, can render latex equation: https://github.com/pmq20/mathjax-rails

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ GEM
435435
xpath (3.2.0)
436436
nokogiri (~> 1.8)
437437
zeitwerk (2.7.2)
438-
zstd-ruby (1.5.6.6)
438+
zstd-ruby (1.5.7.1)
439439

440440
PLATFORMS
441441
ruby
@@ -481,7 +481,7 @@ DEPENDENCIES
481481
terser
482482
tzinfo-data
483483
web-console
484-
zstd-ruby
484+
zstd-ruby (~> 1.5, >= 1.5.6.7)
485485

486486
BUNDLED WITH
487487
2.6.5

app/lib/visicon.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def initialize(str, seed, size=24)
3737

3838
def draw_image
3939
Tempfile.create(['', '.png']) do |tmpfile|
40-
MiniMagick::Tool::Convert.new do |img|
40+
MiniMagick.convert do |img|
4141
img.size "#{@img_size}x#{@img_size}"
4242
img.xc 'white'
4343
img << tmpfile.path
@@ -151,4 +151,4 @@ def rotate_points(points, rotation, modifier)
151151
offset = @@offsets[rotation % 4] * @size + Vector.elements(modifier)
152152
points.map {|pt| (mat * Vector.elements(pt) + offset).to_a}
153153
end
154-
end
154+
end

config/database.ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
test:
2+
adapter: mysql2
3+
username: root
4+
password: somepassword
5+
host: 127.0.0.1 # prevent to use socket, since the db is in docker container
6+
encoding: utf8mb4
7+
database: tioj_test

scripts/db/compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
mysql2:
3+
image: mysql:8.0
4+
container_name: tioj-db
5+
environment:
6+
MYSQL_ROOT_PASSWORD: somepassword
7+
ports:
8+
- "3306:3306"
9+
volumes:
10+
- mysql2_data:/var/lib/mysql
11+
- /var/run/mysqld:/var/run/mysqld
12+
restart: unless-stopped
13+
14+
volumes:
15+
mysql2_data:

test/controllers/problems_controller_test.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@ class ProblemsControllerTest < ActionDispatch::IntegrationTest
1717
end
1818

1919
test "problem visibility should be correct" do
20-
assert_raise ActionController::RoutingError do
21-
get problem_url(@problem_invisible)
22-
end
20+
get problem_url(@problem_invisible)
21+
assert_response :missing
2322

2423
sign_in users(:userOne)
25-
assert_raise ActionController::RoutingError do
26-
get problem_url(@problem_invisible)
27-
end
24+
get problem_url(@problem_invisible)
25+
assert_response :missing
2826
sign_out :user
2927

3028
sign_in users(:adminOne)

test/controllers/submissions_controller_test.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ class SubmissionsControllerTest < ActionDispatch::IntegrationTest
2424
end
2525

2626
test "submission visibility should be correct" do
27-
assert_raise ActionController::RoutingError do
28-
get submission_url(@submission_invisible)
29-
end
27+
get submission_url(@submission_invisible)
28+
assert_response :missing
3029

3130
sign_in users(:userOne)
32-
assert_raise ActionController::RoutingError do
33-
get submission_url(@submission_invisible)
34-
end
31+
get submission_url(@submission_invisible)
32+
assert_response :missing
3533
sign_out :user
3634

3735
sign_in users(:adminOne)

test/fixtures/problems.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ one:
5757
specjudge_type: none
5858
interlib_type: none
5959
visible_state: public
60+
summary_type: none
6061

6162
invisible:
6263
name: ProblemInvisible
@@ -69,3 +70,4 @@ invisible:
6970
specjudge_type: none
7071
interlib_type: none
7172
visible_state: invisible
73+
summary_type: none

test/test_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Selenium::WebDriver.logger.output = 'tmp/selenium.log'
66

77
class ActiveSupport::TestCase
8-
ActiveRecord::Migration.check_pending!
8+
ActiveRecord::Migration.check_all_pending!
99

1010
# Run tests in parallel with specified workers
1111
parallelize(workers: :number_of_processors)
@@ -49,4 +49,4 @@ def assert_no_permission
4949
def assert_login_needed
5050
assert_redirected_to '/users/sign_in'
5151
end
52-
end
52+
end

0 commit comments

Comments
 (0)