-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#567 add test suite #573
#567 add test suite #573
Changes from all commits
4ba7296
bf94260
25fa3cf
7629132
6d2bb1c
c7a75f2
48f0c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
# lint: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will like to add rubocop to the project later, so just stubbing this out for now |
||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - name: Checkout code | ||
# uses: actions/checkout@v4 | ||
|
||
# - name: Set up Ruby | ||
# uses: ruby/setup-ruby@v1 | ||
# with: | ||
# ruby-version: .ruby-version | ||
# bundler-cache: true | ||
|
||
# - name: Lint code for consistent style | ||
# run: bin/rubocop -f github | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
mysql: | ||
image: mariadb:10.11 | ||
env: | ||
MARIADB_ROOT_PASSWORD: mysecretpassword | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
|
||
steps: | ||
- name: Install packages | ||
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libvips libjemalloc2 default-mysql-client default-libmysqlclient-dev | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: .ruby-version | ||
bundler-cache: true | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16 | ||
|
||
- name: Get yarn cache | ||
id: yarn-cache | ||
run: echo "::set-output name=dir::$(yarn cache dir)" | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.yarn-cache.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
|
||
- name: Install Node modules | ||
run: yarn install | ||
|
||
- name: Run tests | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_URL: mysql2://root:[email protected]:3306 | ||
run: bin/rails db:setup test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
tmp/ | ||
.DS_Store | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We weren't gitignoring |
||
log/development.log | ||
config/initializers/comfortable_mexican_sofa.rb | ||
storage/ | ||
# See https://help.github.com/articles/ignoring-files for more about ignoring files. | ||
# | ||
# If you find yourself ignoring temporary files generated by your text editor | ||
# or operating system, you probably want to add a global ignore instead: | ||
# git config --global core.excludesfile '~/.gitignore_global' | ||
|
||
# Ignore bundler config. | ||
/.bundle | ||
|
||
# Ignore all environment files (except templates). | ||
/.env* | ||
!/.env*.erb | ||
|
||
# Ignore all logfiles and tempfiles. | ||
/log/* | ||
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
|
||
# Ignore pidfiles, but keep the directory. | ||
/tmp/pids/* | ||
!/tmp/pids/ | ||
!/tmp/pids/.keep | ||
|
||
# Ignore storage (uploaded files in development and any SQLite databases). | ||
/storage/* | ||
!/storage/.keep | ||
/tmp/storage/* | ||
!/tmp/storage/ | ||
!/tmp/storage/.keep | ||
|
||
/public/assets | ||
|
||
# Ignore master key for decrypting credentials and more. | ||
/config/master.key | ||
|
||
/app/assets/builds/* | ||
!/app/assets/builds/.keep | ||
|
||
# Ignore for Build | ||
/vendor/bundle | ||
|
||
# Webpacker stuff | ||
/public/packs | ||
/public/packs-test | ||
/node_modules | ||
/yarn-error.log | ||
yarn-debug.log* | ||
.yarn-integrity | ||
|
||
# Our custom ignores | ||
.DS_Store | ||
# This is ignored due to Ansible I assume: | ||
config/initializers/comfortable_mexican_sofa.rb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume too. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class CmsTest < ActionDispatch::IntegrationTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be done later, but it would be good to cover the features noted in the readme:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that sounds like a good idea, especially Staff as this is custom (not part of the CMS) 👍. So will add a note to add more tests for this here #567 |
||
test "homepage" do | ||
get comfy_cms_render_page_path(cms_path: "") | ||
|
||
assert_response :success | ||
assert_select "h2", "Search the Library" | ||
end | ||
|
||
test "hours and locations page" do | ||
get comfy_cms_render_page_path(cms_path: 'hours-locations') | ||
|
||
assert_response :success | ||
assert_select "h1", /Hours & Locations/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The H1 tag on these pages has a lot of extra information in it, such as links and other things. So for example for the "About us" page, you can see in this photo the links on the right is actually inside the So using a regex to just extract and assert the actual header content here. This could probably be improved by moving the extra info outside of the header tag. |
||
end | ||
|
||
test "about us page" do | ||
get comfy_cms_render_page_path(cms_path: 'about-us') | ||
|
||
assert_response :success | ||
assert_select "h1", /About Us/ | ||
assert_select "h2", "A Message from our Chief Librarian" | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,14 @@ | |
require_relative '../config/environment' | ||
require 'rails/test_help' | ||
|
||
# Seed the database with our CMS seed data, if it's not already there | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some notes here: This will seed the test DB with our CMS data BEFORE the tests run, so it's technically outside the transactions that normally happen in the test suite. This is good because, every time we run tests, we don't need to reseed the DB (as this seeding is expensive, and takes a good ~30 seconds as we have many, many pages). It's bad in the case of what happens when the seed data changes? These changes won't be available right away, and will likely require someone to manually drop the test DB. But I assume changing the seed data is a rare occurrence. I also tried to move this to a rake task but was having issues with Typically, we should be using fixtures here and following Comfy best practice here, which is to have a minimal version of our website for testing: Or we can parse down the amount of CMS pages we have? As it appears, we have a ton of redundant/old pages or multiple versions (sandbox/french) of our CMS. The less we have, the faster the seeding can take place, which means we could in theory just use fixtures and seed the CMS every time before the tests run, which means we could get the best of both worlds. |
||
if Rake::Task.tasks.empty? && Comfy::Cms::Site.count.zero? | ||
HomeCms::Application.load_tasks | ||
|
||
Comfy::Cms::Site.create!(identifier: 'ualberta-libraries', hostname: 'localhost') | ||
Rake::Task['comfy:cms_seeds:import'].invoke('library-cms-seeds', 'ualberta-libraries') | ||
end | ||
|
||
class ActiveSupport::TestCase | ||
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. | ||
fixtures :all | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mostly adapted from Jupiter's CI and Rails default generated CI https://github.com/rails/rails/blob/9ad3685538d9820dafadb70de9e2809486cdf91e/railties/lib/rails/generators/rails/app/templates/github/ci.yml.tt