Skip to content

Commit

Permalink
Merge pull request #124 from maii-chgk/capybara
Browse files Browse the repository at this point in the history
run capybara tests in CI
  • Loading branch information
razumau authored Mar 2, 2024
2 parents ef0f00d + bdcfa53 commit 0bd59b2
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 2 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,48 @@ name: CI
on: push

jobs:
ci:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v4
- name: Install PostgreSQL client
run: sudo apt-get -yqq install postgresql-client
- name: Create schema
run: psql -h localhost -U postgres -d test_db -c "DROP SCHEMA public CASCADE;"
env:
PGPASSWORD: postgres
- name: Restore database from backup
run: pg_restore --no-owner -h localhost -U postgres -d test_db test/test_db.backup
env:
PGPASSWORD: postgres
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Install Bun
run: |
curl -fsSL https://bun.sh/install | bash -s "bun-v1.0.20"
echo "${HOME}/.bun/bin" >> $GITHUB_PATH
- name: Compile frontend assets
run: bundle exec rake assets:precompile
- name: Run tests
env:
RAILS_ENV: test
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db
run: bundle exec rake test

linter:
runs-on: ubuntu-latest
steps:
- name: Check out
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ group :development do
gem "web-console", ">= 4.1.0"
end

group :test do
gem "capybara"
gem "minitest"
end

gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
19 changes: 18 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.6)
Expand All @@ -83,6 +85,15 @@ GEM
msgpack (~> 1.2)
builder (3.2.4)
byebug (11.1.3)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
crass (1.0.6)
Expand Down Expand Up @@ -120,6 +131,7 @@ GEM
net-pop
net-smtp
marcel (1.0.4)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.22.2)
Expand Down Expand Up @@ -156,6 +168,7 @@ GEM
railties (>= 7.0.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
Expand Down Expand Up @@ -276,6 +289,8 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.13)

PLATFORMS
Expand All @@ -287,11 +302,13 @@ PLATFORMS
DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
capybara
cssbundling-rails (~> 1.1)
hiredis
honeybadger (~> 5.0)
jsbundling-rails (~> 1.0)
lograge
minitest
newrelic_rpm
nokogiri (>= 1.13.6)
pg (< 2)
Expand All @@ -315,4 +332,4 @@ DEPENDENCIES
web-console (>= 4.1.0)

BUNDLED WITH
2.5.0
2.5.5
3 changes: 3 additions & 0 deletions config/cable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# we only load action_cable as a workaround (https://github.com/maii-chgk/rating-ui/commit/a87d74163bd1af171131eef05d7e7e6f92b89a9a)
# and don’t actually use it (or need any config for it)
# however, if this file does not exist, action_cable’s test helper crashes
7 changes: 7 additions & 0 deletions lib/tasks/minitest.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "minitest/test_task"

Minitest::TestTask.create(:test) do |t|
t.libs << "test"
t.warning = false
t.test_globs = ["test/system/*_test.rb"]
end
17 changes: 17 additions & 0 deletions test/system/team_release_page_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "test_helper"
require "minitest/autorun"

class VisitMainPageTest < ActionDispatch::IntegrationTest
include Capybara::DSL

test "latest release is shown with correct data" do
visit "/"

assert_selector "table"

within "table" do
assert_selector "tr", text: "Борский корабел"
assert_selector "tr", text: "14825"
end
end
end
Binary file added test/test_db.backup
Binary file not shown.
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

ENV["RAILS_ENV"] = "test"

require "minitest"
require_relative "../config/environment"
require "capybara/rails"
Capybara.default_driver = :rack_test
66 changes: 66 additions & 0 deletions test/trim.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
--This trims a full Postgres backup to leave only data used in tests

drop table auth_group_permissions cascade;
drop table auth_user_groups cascade;
drop table auth_group cascade;
drop table auth_user_user_permissions cascade;
drop table auth_permission cascade;
drop table django_admin_log cascade;
drop table django_content_type cascade;
drop table django_migrations cascade;
drop table django_session cascade;
drop table auth_user cascade;
drop table b.team_lost_heredity cascade;
drop table b.team_rating_by_player cascade;
drop table ndcg cascade;
drop table rosters cascade;
drop table rating_individual_old;
drop table rating_individual_old_details;

delete from b.player_rating
where release_id not in (131, 132);

delete from b.team_rating
where release_id not in (131, 132);

delete from b.tournament_in_release
where release_id not in (131, 132);

delete from b.tournament_result
where tournament_id not in (10294);

delete from tournament_results
where tournament_id not in (10294);

delete from true_dls
where tournament_id not in (10294);

delete from tournament_rosters
where tournament_id not in (10294);

delete from tournaments
where id not in (10294);

delete from base_rosters
where team_id not in (49804);

delete from b.release where id not in (131, 132);

delete from teams
where id not in (select team_id from tournament_rosters where tournament_id = 10294);
delete from teams
where id not in (select team_id from b.team_ranking where release_id in (131, 132) and place <= 1000);

delete from players
where id not in (select player_id from tournament_rosters where tournament_id = 10294);
delete from players
where id not in (select player_id from b.player_ranking where release_id in (131, 132) and place <= 1000);

delete from b.player_rating_by_tournament
where release_id not in (131, 132);

delete from b.player_rating_by_tournament
where player_id not in (select id from players);

refresh materialized view b.player_ranking;
refresh materialized view b.team_ranking;
Binary file added vendor/cache/addressable-2.8.6.gem
Binary file not shown.
Binary file added vendor/cache/capybara-3.40.0.gem
Binary file not shown.
Binary file added vendor/cache/matrix-0.4.2.gem
Binary file not shown.
Binary file added vendor/cache/public_suffix-5.0.4.gem
Binary file not shown.
Binary file added vendor/cache/xpath-3.2.0.gem
Binary file not shown.

0 comments on commit 0bd59b2

Please sign in to comment.