Skip to content

Commit

Permalink
fix test inconsistencies and add github action test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
amtuannguyen committed Apr 1, 2024
1 parent b97cb45 commit 2c62e2f
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 44 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Ruby on Rails CI"
on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]
jobs:
build_and_run_tests:
name: Build and run tests
runs-on: ubuntu-latest
services:
mysql:
image: mysql
ports:
- 3306:3306
env:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
# Set health checks to wait until mysql has started
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1 -u root -p$$MYSQL_ROOT_PASSWORD"
--health-interval 10s
--health-timeout 5s
--health-retries 5
chrome-server:
image: selenium/standalone-chrome:96.0
ports:
- 4444:4444

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Ruby and gems
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run tests with sqlite3
env:
RAILS_ENV: test
DATABASE_URL: sqlite3:db/test.sqlite3
SELENIUM_SERVER: 127.0.0.1
run: |
bundle exec rake db:reset
bundle exec rake test
bundle exec rake test:system
- name: Run tests with mysql
env:
RAILS_ENV: test
DATABASE_URL: mysql2://test:[email protected]:3306/test
SELENIUM_SERVER: 127.0.0.1
run: |
bundle exec rake db:reset
bundle exec rake test
bundle exec rake test:system
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default: &default
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 10000
variables:
sql_mode: "NO_ENGINE_SUBSTITUTION"
sql_mode: "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

development:
<<: *default
Expand Down
14 changes: 11 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ services:
- RAILS_ENV=${RAILS_ENV:-development}
- SECRET_KEY_BASE=${SECRET_KEY_BASE}
- DATABASE_URL=mysql2://root:mypasswd@db/${COMPOSE_PROJECT_NAME}_${RAILS_ENV:-development}
- TEST_DATABASE_URL=sqlite3:db/test.sqlite3
- RAILS_SERVE_STATIC_FILES=true
- NODE_OPTIONS=--openssl-legacy-provider
- ALMA_API_KEY=${ALMA_API_KEY}
- PRIMO_API_KEY=${PRIMO_API_KEY}
- WORLDCAT_API_KEY=${WORLDCAT_API_KEY}
- SELENIUM_SERVER=chrome-server
env_file:
- path: ./override.env
required: false

db:
image: mysql
command: --sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Expand All @@ -38,3 +41,8 @@ services:
ports:
- ${MAILCATCHER_HTTP:-4084}:1080

chrome-server:
image: selenium/standalone-chrome:96.0
ports:
- ${VNC_HTTP:-7904}:7900

2 changes: 1 addition & 1 deletion lib/papyrus/student_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def from_list(students_list, options = nil)
students_list.shift if @options[:ignore_first_line]

## GET COORDINATOR LIST, for later processing
coordinator_list = User.active.coordinators.collect { |u| u.id }
coordinator_list = User.active.coordinators.order(id: :desc).collect { |u| u.id }
## ENSURE first id in the list is not the most recent assigned coordinator
if Student.most_recent_students(1).size > 0
last_assigned_coordinator_id = Student.most_recent_students(1).first.details.transcription_coordinator_id
Expand Down
20 changes: 0 additions & 20 deletions test/database_cleaner.rb
Original file line number Diff line number Diff line change
@@ -1,20 +0,0 @@
# frozen_string_literal: true

DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)

module Minitest
module Rails
module ActionController
class TestCase
def setup
DatabaseCleaner.start
end

def teardown
DatabaseCleaner.clean
end
end
end
end
end
24 changes: 14 additions & 10 deletions test/integration/bib_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@ class BibSearchTest < ActionDispatch::IntegrationTest
# end

should 'search WOLRDCAT for Multiple Items' do
search_string = 'Caesar'
record = BibRecord.new
results = record.search_items(search_string, BibRecord::WORLDCAT)
if !ENV['WORLDCAT_API_KEY'].nil?
search_string = 'Caesar'
record = BibRecord.new
results = record.search_items(search_string, BibRecord::WORLDCAT)

assert results.size.positive?, 'At least one result should happen'
assert results.size.positive?, 'At least one result should happen'
end
end

should 'search WORLDCAT for single item' do
item_id = '671660984' # Julius Caesar by Shakespear
record = BibRecord.new
item = record.find_item(item_id, BibRecord::WORLDCAT)

assert_not_nil item
assert_equal item_id, item.id
if !ENV['WORLDCAT_API_KEY'].nil?
item_id = '671660984' # Julius Caesar by Shakespear
record = BibRecord.new
item = record.find_item(item_id, BibRecord::WORLDCAT)

assert_not_nil item
assert_equal item_id, item.id
end
end
end
24 changes: 15 additions & 9 deletions test/lib/papyrus/student_loader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,13 @@ class StudentLoaderTest < ActiveSupport::TestCase
PapyrusSettings.import_auto_assign_coordinator = PapyrusSettings::TRUE
@loader.from_list(sample_data)

students = Student.all.to_ary
assert_equal c1.id, students.at(0).details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, students.at(1).details.transcription_coordinator.id, 'Should be second coordinator'
assert_equal c1.id, students.at(2).details.transcription_coordinator.id, 'Should be first coordinator'
student1 = Student.find_by_username '111111'
student2 = Student.find_by_username '222222'
student3 = Student.find_by_username '333333'

assert_equal c1.id, student1.details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, student2.details.transcription_coordinator.id, 'Should be second coordinator'
assert_equal c1.id, student3.details.transcription_coordinator.id, 'Should be first coordinator'
end

should 'not assign coordinaor first, if it was last assigned' do
Expand All @@ -102,11 +105,14 @@ class StudentLoaderTest < ActiveSupport::TestCase
PapyrusSettings.import_auto_assign_coordinator = PapyrusSettings::TRUE
@loader.from_list(sample_data)

students = Student.all.to_ary
assert_equal c1.id, students.at(0).details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, students.at(1).details.transcription_coordinator.id, 'Should be second coordinator'
assert_equal c1.id, students.at(2).details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, students.at(3).details.transcription_coordinator.id, 'Should be second coordinator'
student1 = Student.find_by_username '111111'
student2 = Student.find_by_username '222222'
student3 = Student.find_by_username '333333'

assert_equal c1.id, student.details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, student1.details.transcription_coordinator.id, 'Should be second coordinator'
assert_equal c1.id, student2.details.transcription_coordinator.id, 'Should be first coordinator'
assert_equal c2.id, student3.details.transcription_coordinator.id, 'Should be second coordinator'
end

should 'send an welcome email to student upon creation if setting is enabled' do
Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
require 'capybara/rails'
require 'capybara/minitest'

DatabaseCleaner.strategy = :truncation

Capybara.server_host = '0.0.0.0'
Capybara.app_host = "http://#{Socket.gethostname}:#{Capybara.server_port}"

Expand All @@ -20,6 +22,7 @@ class TestCase

setup do
Rails.configuration.is_authentication_method = :header
DatabaseCleaner.start
end

teardown do
Expand All @@ -39,6 +42,7 @@ class TestCase
end
CarrierWave.clean_cached_files! 0
PapyrusSettings.clear_cache
DatabaseCleaner.clean
end

include FactoryGirl::Syntax::Methods
Expand Down

0 comments on commit 2c62e2f

Please sign in to comment.