From 4ba729647223583e6725ad7a7e9018225deafeb5 Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 11:39:57 -0600 Subject: [PATCH 1/7] Add basic smoke tests to verify cms content is being rendered --- .gitignore | 52 ++++++++++++++++++++++++++++++++---- config/routes.rb | 1 - test/integration/cms_test.rb | 27 +++++++++++++++++++ test/test_helper.rb | 8 ++++++ 4 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 test/integration/cms_test.rb diff --git a/.gitignore b/.gitignore index b25ca088..f3b25338 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,54 @@ -tmp/ -.DS_Store -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 diff --git a/config/routes.rb b/config/routes.rb index a46011a3..74b3f210 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,5 +7,4 @@ match '/500', to: 'errors#internal_server_error', via: :all # Ensure that this route is defined last comfy_route :cms, path: "/" - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/test/integration/cms_test.rb b/test/integration/cms_test.rb new file mode 100644 index 00000000..028e1f85 --- /dev/null +++ b/test/integration/cms_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "test_helper" + +class CmsTest < ActionDispatch::IntegrationTest + 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/ + 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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 3ab84e3d..490d5e14 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 +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 From bf9426048a16326e5ca70bdcb028f4aa605737b0 Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 14:28:36 -0600 Subject: [PATCH 2/7] Add github actions to run tests in CI --- .github/workflows/ci.yml | 53 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..beee275c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,53 @@ +name: CI + +on: + pull_request: + push: + branches: [ main ] + +jobs: + # lint: + # 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: + MYSQL_ALLOW_EMPTY_PASSWORD: true + 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 postgresql-client libpq-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 + + - name: Run tests + env: + RAILS_ENV: test + DATABASE_URL: mysql2://127.0.0.1:3306 + run: bin/rails db:setup test From 25fa3cf0ed88abcddd7fa098c596493db2ec8106 Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 14:31:57 -0600 Subject: [PATCH 3/7] Fix packages for the right database --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index beee275c..6fef8578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: steps: - name: Install packages - run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libvips postgresql-client libpq-dev + 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 From 7629132975e2ee3ce2da2d3304501a4f1b0011b3 Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 14:36:40 -0600 Subject: [PATCH 4/7] Mariadb uses different env var for passwordless --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6fef8578..f944a59d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: mysql: image: mariadb:10.11 env: - MYSQL_ALLOW_EMPTY_PASSWORD: true + MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 From 6d2bb1c6a420bab8a8946468fb0613d09610e8dc Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 14:48:20 -0600 Subject: [PATCH 5/7] Try to fix username/password for mariadb --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f944a59d..616554cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: mysql: image: mariadb:10.11 env: - MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true + MARIADB_ROOT_PASSWORD: mysecretpassword ports: - 3306:3306 options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 @@ -49,5 +49,5 @@ jobs: - name: Run tests env: RAILS_ENV: test - DATABASE_URL: mysql2://127.0.0.1:3306 + DATABASE_URL: mysql2://root:mysecretpassword@localhost:3306 run: bin/rails db:setup test From c7a75f22f2a16ed0d1389ef4dab4eca71e24989a Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 15:18:49 -0600 Subject: [PATCH 6/7] Change localhost --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 616554cc..d41d59f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,5 +49,5 @@ jobs: - name: Run tests env: RAILS_ENV: test - DATABASE_URL: mysql2://root:mysecretpassword@localhost:3306 + DATABASE_URL: mysql2://root:mysecretpassword@127.0.0.1:3306 run: bin/rails db:setup test From 48f0c18ca96e7d1e9631214ebcef8546f2980cdb Mon Sep 17 00:00:00 2001 From: murny <1930474+murny@users.noreply.github.com> Date: Mon, 6 May 2024 15:25:26 -0600 Subject: [PATCH 7/7] Add Yarn/Node to CI --- .github/workflows/ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d41d59f0..6f0f4d62 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,24 @@ jobs: 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