Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
tests:
name: Rails CI Tests
runs-on: ubuntu-latest

services:
mysql-container:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: somepassword
ports:
- "3306:3306"

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3.7"
bundler-cache: true

- name: Install dependencies
run: |
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get -yqq install imagemagick yarn libzstd-dev libmysqlclient-dev
bundle install --jobs 4 --retry 3

- name: Run Tests
env:
RAILS_ENV: test
run: |
cp config/database.ci.yml config/database.yml
bundle exec rails db:prepare
bundle exec rails test
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ gem 'nested_form'
gem 'carrierwave'
gem 'mini_magick'
# compression
gem 'zstd-ruby'
gem 'zstd-ruby', '~> 1.5', '>= 1.5.6.7'
gem 'rubyzip', '~> 2', require: 'zip'

# Mathjax, can render latex equation: https://github.com/pmq20/mathjax-rails
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ GEM
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.7.2)
zstd-ruby (1.5.6.6)
zstd-ruby (1.5.7.1)

PLATFORMS
ruby
Expand Down Expand Up @@ -481,7 +481,7 @@ DEPENDENCIES
terser
tzinfo-data
web-console
zstd-ruby
zstd-ruby (~> 1.5, >= 1.5.6.7)

BUNDLED WITH
2.6.5
4 changes: 2 additions & 2 deletions app/lib/visicon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(str, seed, size=24)

def draw_image
Tempfile.create(['', '.png']) do |tmpfile|
MiniMagick::Tool::Convert.new do |img|
MiniMagick.convert do |img|
img.size "#{@img_size}x#{@img_size}"
img.xc 'white'
img << tmpfile.path
Expand Down Expand Up @@ -151,4 +151,4 @@ def rotate_points(points, rotation, modifier)
offset = @@offsets[rotation % 4] * @size + Vector.elements(modifier)
points.map {|pt| (mat * Vector.elements(pt) + offset).to_a}
end
end
end
7 changes: 7 additions & 0 deletions config/database.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test:
adapter: mysql2
username: root
password: somepassword
host: 127.0.0.1 # prevent to use socket, since the db is in docker container
encoding: utf8mb4
database: tioj_test
15 changes: 15 additions & 0 deletions scripts/db/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
mysql2:
image: mysql:8.0
container_name: tioj-db
environment:
MYSQL_ROOT_PASSWORD: somepassword
ports:
- "3306:3306"
volumes:
- mysql2_data:/var/lib/mysql
- /var/run/mysqld:/var/run/mysqld
restart: unless-stopped

volumes:
mysql2_data:
10 changes: 4 additions & 6 deletions test/controllers/problems_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ class ProblemsControllerTest < ActionDispatch::IntegrationTest
end

test "problem visibility should be correct" do
assert_raise ActionController::RoutingError do
get problem_url(@problem_invisible)
end
get problem_url(@problem_invisible)
assert_response :missing

sign_in users(:userOne)
assert_raise ActionController::RoutingError do
get problem_url(@problem_invisible)
end
get problem_url(@problem_invisible)
assert_response :missing
sign_out :user

sign_in users(:adminOne)
Expand Down
10 changes: 4 additions & 6 deletions test/controllers/submissions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ class SubmissionsControllerTest < ActionDispatch::IntegrationTest
end

test "submission visibility should be correct" do
assert_raise ActionController::RoutingError do
get submission_url(@submission_invisible)
end
get submission_url(@submission_invisible)
assert_response :missing

sign_in users(:userOne)
assert_raise ActionController::RoutingError do
get submission_url(@submission_invisible)
end
get submission_url(@submission_invisible)
assert_response :missing
sign_out :user

sign_in users(:adminOne)
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/problems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ one:
specjudge_type: none
interlib_type: none
visible_state: public
summary_type: none

invisible:
name: ProblemInvisible
Expand All @@ -69,3 +70,4 @@ invisible:
specjudge_type: none
interlib_type: none
visible_state: invisible
summary_type: none
4 changes: 2 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Selenium::WebDriver.logger.output = 'tmp/selenium.log'

class ActiveSupport::TestCase
ActiveRecord::Migration.check_pending!
ActiveRecord::Migration.check_all_pending!

# Run tests in parallel with specified workers
parallelize(workers: :number_of_processors)
Expand Down Expand Up @@ -49,4 +49,4 @@ def assert_no_permission
def assert_login_needed
assert_redirected_to '/users/sign_in'
end
end
end