diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..6f0f4d62 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,71 @@ +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: + 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:mysecretpassword@127.0.0.1:3306 + run: bin/rails db:setup test 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