diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 591049a..9185aa3 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -2,38 +2,35 @@ name: Linters on: - push: - branches: - - main pull_request: + branches: [main] + push: + branches: [main] jobs: reviewdog: - name: reviewdog + name: Reviewdog runs-on: ubuntu-latest - strategy: - matrix: - ruby: ['3.0'] - env: - RUBY_VERSION: ${{ matrix.ruby }} + RAILS_VERSION: 7.0 steps: - - name: Check out code + - name: Checkout repository uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: ${{ matrix.ruby }} + ruby-version: 3.0 bundler-cache: true - - uses: reviewdog/action-setup@v1 + - name: Set up Reviewdog + uses: reviewdog/action-setup@v1 with: reviewdog_version: latest - - name: Run reviewdog + - name: Run Reviewdog env: REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | diff --git a/.github/workflows/specs_rails61.yml b/.github/workflows/specs_rails61.yml index d4706c1..258909d 100644 --- a/.github/workflows/specs_rails61.yml +++ b/.github/workflows/specs_rails61.yml @@ -1,24 +1,23 @@ --- -name: Specs Rails 6.1 +name: Specs Rails 6.1 with ActiveAdmin 2.9 on: - push: - branches: - - main pull_request: - branches: - - main + branches: [main] + push: + branches: [main] jobs: - tests: + test: runs-on: ubuntu-latest strategy: matrix: - ruby: ['3.0', '3.1'] + ruby: ['3.0'] env: - RAILS_VERSION: 6.1.0 + RAILS_VERSION: 6.0 + ACTIVEADMIN_VERSION: 2.9.0 steps: - name: Checkout repository @@ -30,6 +29,9 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Database setup + run: bin/rails db:create db:migrate db:test:prepare + - name: Run tests run: bundle exec rspec --profile diff --git a/.github/workflows/specs_rails70.yml b/.github/workflows/specs_rails70.yml index 8632fed..4ca1c9f 100644 --- a/.github/workflows/specs_rails70.yml +++ b/.github/workflows/specs_rails70.yml @@ -2,23 +2,21 @@ name: Specs Rails 7.0 on: - push: - branches: - - main pull_request: - branches: - - main + branches: [main] + push: + branches: [main] jobs: - tests: + test: runs-on: ubuntu-latest strategy: matrix: - ruby: ['3.1'] + ruby: ['3.0', '3.2'] env: - RAILS_VERSION: 7.0.0 + RAILS_VERSION: 7.0 steps: - name: Checkout repository @@ -30,6 +28,9 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Database setup + run: bin/rails db:create db:migrate db:test:prepare + - name: Run tests run: bundle exec rspec --profile diff --git a/.github/workflows/specs_rails71.yml b/.github/workflows/specs_rails71.yml index 6ed29a5..6817c31 100644 --- a/.github/workflows/specs_rails71.yml +++ b/.github/workflows/specs_rails71.yml @@ -2,23 +2,21 @@ name: Specs Rails 7.1 on: - push: - branches: - - main pull_request: - branches: - - main + branches: [main] + push: + branches: [main] jobs: - tests: + test: runs-on: ubuntu-latest strategy: matrix: - ruby: ['3.2'] + ruby: ['3.2', '3.4'] env: - RAILS_VERSION: 7.1.0 + RAILS_VERSION: 7.1 steps: - name: Checkout repository @@ -30,6 +28,9 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Database setup + run: bin/rails db:create db:migrate db:test:prepare + - name: Run tests run: bundle exec rspec --profile diff --git a/.github/workflows/specs_rails72.yml b/.github/workflows/specs_rails72.yml index 5bd955d..0937f06 100644 --- a/.github/workflows/specs_rails72.yml +++ b/.github/workflows/specs_rails72.yml @@ -2,15 +2,13 @@ name: Specs Rails 7.2 on: - push: - branches: - - main pull_request: - branches: - - main + branches: [main] + push: + branches: [main] jobs: - tests: + test: runs-on: ubuntu-latest strategy: @@ -18,7 +16,7 @@ jobs: ruby: ['3.2', '3.4'] env: - RAILS_VERSION: 7.2.0 + RAILS_VERSION: 7.2 steps: - name: Checkout repository @@ -30,6 +28,9 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Database setup + run: bin/rails db:create db:migrate db:test:prepare + - name: Run tests run: bundle exec rspec --profile diff --git a/.github/workflows/specs_rails80.yml b/.github/workflows/specs_rails80.yml index 3c8c838..a40312a 100644 --- a/.github/workflows/specs_rails80.yml +++ b/.github/workflows/specs_rails80.yml @@ -2,23 +2,21 @@ name: Specs Rails 8.0 on: - push: - branches: - - main pull_request: - branches: - - main + branches: [main] + push: + branches: [main] jobs: - tests: + test: runs-on: ubuntu-latest strategy: matrix: - ruby: ['3.2', '3.3', '3.4'] + ruby: ['3.2', '3.4'] env: - RAILS_VERSION: 8.0.0 + RAILS_VERSION: 8.0 steps: - name: Checkout repository @@ -30,6 +28,9 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Database setup + run: bin/rails db:create db:migrate db:test:prepare + - name: Run tests run: bundle exec rspec --profile diff --git a/.gitignore b/.gitignore index 0056dbd..a643ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ /_misc/ /coverage/ /spec/dummy/db/*.sqlite3* +/spec/dummy/db/schema-dev.rb /spec/dummy/log/ /spec/dummy/storage/ /spec/dummy/tmp/ diff --git a/Gemfile b/Gemfile index 7fa953f..b6fe800 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,12 @@ source 'https://rubygems.org' +def eval_version(dependency, version) + return [dependency] if version.empty? + + version.count('.') < 2 ? [dependency, "~> #{version}.0"] : [dependency, version] +end + if ENV['DEVEL'] == '1' gem 'activeadmin_quill_editor', path: './' else @@ -9,20 +15,22 @@ else end ruby_ver = ENV.fetch('RUBY_VERSION', '') -rails_ver = ENV.fetch('RAILS_VERSION', '') -activeadmin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '') -rails = rails_ver.empty? ? ['rails'] : ['rails', "~> #{rails_ver}"] +rails_ver = ENV.fetch('RAILS_VERSION', '') +rails = eval_version('rails', rails_ver) gem(*rails) -activeadmin = activeadmin_ver.empty? ? ['activeadmin'] : ['activeadmin', "~> #{activeadmin_ver}"] -gem(*activeadmin) +active_admin_ver = ENV.fetch('ACTIVEADMIN_VERSION', '') +active_admin = eval_version('activeadmin', active_admin_ver) +gem(*active_admin) -ruby32 = Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2') -rails72 = Gem::Version.new(rails_ver) >= Gem::Version.new('7.2') -sqlite3 = ruby32 || rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4'] +ruby32 = ruby_ver.empty? || Gem::Version.new(ruby_ver) >= Gem::Version.new('3.2') +rails72 = rails_ver.empty? || Gem::Version.new(rails_ver) >= Gem::Version.new('7.2') +sqlite3 = ruby32 && rails72 ? ['sqlite3'] : ['sqlite3', '~> 1.4'] gem(*sqlite3) +gem 'zeitwerk', '~> 2.6.18' unless ruby32 + # NOTE: to avoid error: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger gem 'concurrent-ruby', '1.3.4' @@ -39,7 +47,6 @@ gem 'capybara' gem 'cuprite' gem 'rspec_junit_formatter' gem 'rspec-rails' -gem 'rspec-retry' gem 'simplecov', require: false # Linters diff --git a/Makefile b/Makefile index 780d3fb..7eb4207 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,14 @@ include extra/.env help: - @echo "Main targets: build / specs / up / server / specs / shell" + @echo -e "${COMPOSE_PROJECT_NAME} - Main project commands:\n\ + make up # starts the dev services (optional env vars: RUBY / RAILS / ACTIVEADMIN)\n\ + make specs # run the tests (after up)\n\ + make lint # run the linters (after up)\n\ + make server # run the server (after up)\n\ + make shell # open a shell (after up)\n\ + make down # cleanup (after up)\n\ + Example: RUBY=3.2 RAILS=7.1 ACTIVEADMIN=3.2.0 make up" # System commands @@ -10,7 +17,7 @@ build: @docker compose -f extra/docker-compose.yml build db_reset: - @docker compose -f extra/docker-compose.yml run --rm app bin/rails db:reset db:test:prepare + @docker compose -f extra/docker-compose.yml run --rm app bin/rails db:create db:migrate db:test:prepare up: build db_reset @docker compose -f extra/docker-compose.yml up @@ -23,13 +30,16 @@ down: # App commands -console: +seed: + @docker compose -f extra/docker-compose.yml exec app bin/rails db:seed + +console: seed @docker compose -f extra/docker-compose.yml exec app bin/rails console lint: @docker compose -f extra/docker-compose.yml exec app bin/rubocop -server: +server: seed @docker compose -f extra/docker-compose.yml exec app bin/rails server -b 0.0.0.0 -p ${SERVER_PORT} specs: diff --git a/extra/Dockerfile b/extra/Dockerfile index e515d1e..bea3373 100644 --- a/extra/Dockerfile +++ b/extra/Dockerfile @@ -26,6 +26,6 @@ ENV ACTIVEADMIN_VERSION=$ACTIVEADMIN_VERSION WORKDIR /app COPY . /app RUN bundle install -RUN mkdir -p /app/spec/dummy/db && chown -R app:app /app/spec/dummy/db /usr/local/bundle +RUN chown -R app:app /usr/local/bundle RUN ln -s /app/extra/.bashrc /home/app/.bashrc diff --git a/extra/dev_setup.sh b/extra/dev_setup.sh index adea0b4..a3d279a 100755 --- a/extra/dev_setup.sh +++ b/extra/dev_setup.sh @@ -4,5 +4,3 @@ export DEVEL=1 export RAILS_VERSION=7.2.2.1 export ACTIVEADMIN_VERSION=3.3.0 - -export RAILS_ENV=development diff --git a/extra/development.md b/extra/development.md index 897b504..3f8733c 100644 --- a/extra/development.md +++ b/extra/development.md @@ -1,29 +1,21 @@ ## Development -Overcommit can be used to ensure that Conventional commits are good. - ### Dev setup -There 2 ways to interact with this project: +There are 2 ways to interact with this project: 1) Using Docker: ```sh -# Run rails server on the dummy app (=> http://localhost:3000 to access to ActiveAdmin): -make up -# Enter in a Rails console (with the dummy app started): -make console -# Enter in a shell (with the dummy app started): -make shell -# Run the linter on the project (with the dummy app started): -make lint -# Run the test suite (with the dummy app started): -make specs -# Remove container and image: -make cleanup -# To try different versions of Ruby/Rails/ActiveAdmin: -RUBY=3.2 RAILS=7.1.0 ACTIVEADMIN=3.2.0 make up -# For more commands please check the Makefile +make up # starts the dev services (optional env vars: RUBY / RAILS / ACTIVEADMIN) +make specs # run the tests (after up) +make lint # run the linters (after up) +make server # run the server (after up) +make shell # open a shell (after up) +make down # cleanup (after up) + +# Example using specific versions: +RUBY=3.2 RAILS=7.1 ACTIVEADMIN=3.2.0 make up ``` 2) With a local setup: diff --git a/extra/docker-compose.yml b/extra/docker-compose.yml index 8879307..020b70f 100644 --- a/extra/docker-compose.yml +++ b/extra/docker-compose.yml @@ -4,10 +4,10 @@ services: context: .. dockerfile: extra/Dockerfile args: - ACTIVEADMIN_VERSION: ${ACTIVEADMIN:-} BUNDLER_VERSION: ${BUNDLER_VERSION} - RAILS_VERSION: ${RAILS:-} RUBY_IMAGE: ruby:${RUBY:-3.4}-slim + RAILS_VERSION: ${RAILS:-} + ACTIVEADMIN_VERSION: ${ACTIVEADMIN:-} UID: ${UID} user: ${UID}:${GID} ports: diff --git a/spec/dummy/app/admin/posts.rb b/spec/dummy/app/admin/posts.rb index 7588c96..cd7f32f 100644 --- a/spec/dummy/app/admin/posts.rb +++ b/spec/dummy/app/admin/posts.rb @@ -44,7 +44,7 @@ f.input :author f.input :title f.input :summary, as: :quill_editor, input_html: { data: { options: { modules: { toolbar: toolbar } } } } - f.input :description, as: :quill_editor, input_html: { data: { options: { modules: { toolbar: toolbar } } } } + f.input :description, as: :quill_editor # using default options f.input :category f.input :dt f.input :position diff --git a/spec/dummy/app/admin/tags.rb b/spec/dummy/app/admin/tags.rb index d4749f1..09beb57 100644 --- a/spec/dummy/app/admin/tags.rb +++ b/spec/dummy/app/admin/tags.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true ActiveAdmin.register Tag do + permit_params :name end diff --git a/spec/dummy/app/models/post.rb b/spec/dummy/app/models/post.rb index 3eb4c23..2dd30a5 100644 --- a/spec/dummy/app/models/post.rb +++ b/spec/dummy/app/models/post.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class Post < ApplicationRecord - # enum state: %i[available unavailable arriving] - belongs_to :author, inverse_of: :posts, autosave: true has_one :author_profile, through: :author, source: :profile @@ -28,12 +26,12 @@ def upper_title end class << self - def ransackable_attributes(auth_object = nil) - %w[author_id category created_at description dt id position published summary title updated_at] + def ransackable_associations(_auth_object = nil) + %w[author author_profile post_tags tags images_attachments images_blobs] end - def ransackable_associations(auth_object = nil) - %w[author author_profile images_attachments images_blobs post_tags tags] + def ransackable_attributes(_auth_object = nil) + %w[author_id category created_at description dt id position published title summary updated_at] end end end diff --git a/spec/dummy/app/models/profile.rb b/spec/dummy/app/models/profile.rb index d6f373d..5f283c6 100644 --- a/spec/dummy/app/models/profile.rb +++ b/spec/dummy/app/models/profile.rb @@ -3,14 +3,12 @@ class Profile < ApplicationRecord belongs_to :author, inverse_of: :profile, touch: true - # has_rich_text :description - - # def to_s - # description - # end + def to_s + description + end class << self - def ransackable_associations(auth_object = nil) + def ransackable_associations(_auth_object = nil) %w[author] end diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 7107cdb..2be147b 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -1,26 +1,23 @@ require_relative 'boot' require 'rails/all' -require 'sprockets/railtie' Bundler.require(*Rails.groups) module Dummy class Application < Rails::Application - # Initialize configuration defaults for originally generated Rails version. - config.load_defaults 6.0 if Rails::VERSION::MAJOR == 6 + config.load_defaults Rails::VERSION::STRING.to_f - # Settings in config/environments/* take precedence over those specified here. - # Application configuration can go into files in config/initializers - # -- all .rb files in that directory are automatically loaded after loading - # the framework and any gems in your application. + config.active_support.deprecation = :raise - ### - - config.active_record.legacy_connection_handling = false if Gem::Version.new(Rails.version) < Gem::Version.new('7.1') + if Gem::Version.new(Rails.version) < Gem::Version.new('7.1') + config.active_record.legacy_connection_handling = false + end - config.before_configuration do - ActiveSupport::Cache.format_version = 7.0 if Gem::Version.new(Rails.version) > Gem::Version.new('7.0') + if Gem::Version.new(Rails.version) > Gem::Version.new('7.0') + config.before_configuration do + ActiveSupport::Cache.format_version = 7.0 + end end end end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 58e2f54..9cf0a49 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -6,7 +6,7 @@ default: &default development: <<: *default database: db/development.sqlite3 - schema_dump: schema_development.rb + schema_dump: schema-dev.rb test: <<: *default diff --git a/spec/dummy/config/initializers/active_storage.rb b/spec/dummy/config/initializers/active_storage.rb index 1a03b5b..c32e30e 100644 --- a/spec/dummy/config/initializers/active_storage.rb +++ b/spec/dummy/config/initializers/active_storage.rb @@ -1,7 +1,9 @@ -ActiveSupport::Reloader.to_prepare do +Rails.application.reloader.to_prepare do ActiveStorage::Attachment.class_eval do - def self.ransackable_attributes(auth_object = nil) - %w[blob_id created_at id name record_id record_type] + class << self + def ransackable_attributes(auth_object = nil) + %w[blob_id created_at id name record_id record_type] + end end end end diff --git a/spec/dummy/db/schema_development.rb b/spec/dummy/db/schema_development.rb deleted file mode 100644 index 4ea933c..0000000 --- a/spec/dummy/db/schema_development.rb +++ /dev/null @@ -1,99 +0,0 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# This file is the source Rails uses to define your schema when running `bin/rails -# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to -# be faster and is potentially less error prone than running all of your -# migrations from scratch. Old migrations may fail to apply correctly if those -# migrations use external dependencies or application code. -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 2018_06_07_053739) do - create_table "active_admin_comments", force: :cascade do |t| - t.string "namespace" - t.text "body" - t.string "resource_type" - t.integer "resource_id" - t.string "author_type" - t.integer "author_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id" - t.index ["namespace"], name: "index_active_admin_comments_on_namespace" - t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id" - end - - create_table "active_storage_attachments", force: :cascade do |t| - t.string "name", null: false - t.string "record_type", null: false - t.integer "record_id", null: false - t.integer "blob_id", null: false - t.datetime "created_at", precision: nil, null: false - t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" - t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true - end - - create_table "active_storage_blobs", force: :cascade do |t| - t.string "key", null: false - t.string "filename", null: false - t.string "content_type" - t.text "metadata" - t.bigint "byte_size", null: false - t.string "checksum", null: false - t.datetime "created_at", precision: nil, null: false - t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true - end - - create_table "authors", force: :cascade do |t| - t.string "name" - t.integer "age" - t.string "email" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - end - - create_table "post_tags", force: :cascade do |t| - t.integer "post_id" - t.integer "tag_id" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.index ["post_id"], name: "index_post_tags_on_post_id" - t.index ["tag_id"], name: "index_post_tags_on_tag_id" - end - - create_table "posts", force: :cascade do |t| - t.string "title" - t.text "summary" - t.text "description" - t.integer "author_id" - t.string "category" - t.datetime "dt", precision: nil - t.float "position" - t.boolean "published" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.index ["author_id"], name: "index_posts_on_author_id" - end - - create_table "profiles", force: :cascade do |t| - t.text "description" - t.integer "author_id" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - t.index ["author_id"], name: "index_profiles_on_author_id" - end - - create_table "tags", force: :cascade do |t| - t.string "name" - t.datetime "created_at", precision: nil, null: false - t.datetime "updated_at", precision: nil, null: false - end - - add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" - add_foreign_key "post_tags", "posts" - add_foreign_key "post_tags", "tags" - add_foreign_key "posts", "authors" - add_foreign_key "profiles", "authors" -end diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb index 48a94e1..acc6e83 100644 --- a/spec/dummy/db/seeds.rb +++ b/spec/dummy/db/seeds.rb @@ -7,7 +7,8 @@ (11..20).each do |i| age = 21 + 3 * (i - 10) attrs = { name: "Author #{i}", age: age, email: "some@email#{i}.com" } - Author.find_or_create_by!(attrs) do |author| + Author.find_or_create_by!(name: "Author #{i}") do |author| + author.assign_attributes(attrs) author.profile = Profile.new(description: "Profile description for Author #{i}") if (i % 3).zero? end end @@ -19,6 +20,8 @@ title: "Post #{i}", author_id: authors.sample, position: rand(100), + summary: "

Summary for post #{i}

", + description: "

Some bold Some italic Some underline [#{i}]

", created_at: Time.now - rand(3600).seconds } attrs[:category] = 'news' if (i % 4).zero? diff --git a/spec/page_objects/admin/authors/edit_page.rb b/spec/page_objects/admin/authors/edit_page.rb index 542ed12..5564340 100644 --- a/spec/page_objects/admin/authors/edit_page.rb +++ b/spec/page_objects/admin/authors/edit_page.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../base_page' - module Admin module Authors class EditPage < BasePage diff --git a/spec/page_objects/admin/posts/edit_page.rb b/spec/page_objects/admin/posts/edit_page.rb index 2c2d49d..f42c47b 100644 --- a/spec/page_objects/admin/posts/edit_page.rb +++ b/spec/page_objects/admin/posts/edit_page.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative '../../base_page' - module Admin module Posts class EditPage < BasePage diff --git a/spec/page_objects/base_page.rb b/spec/page_objects/base_page.rb index 861d7aa..83c80d6 100644 --- a/spec/page_objects/base_page.rb +++ b/spec/page_objects/base_page.rb @@ -12,4 +12,8 @@ def initialize(path:) def load visit(path) end + + def lookup_editor(editor_container:) + @editor = Shared::QuillEditor.new(editor_container) + end end diff --git a/spec/page_objects/shared/html_editor.rb b/spec/page_objects/shared/html_editor.rb index b8233ed..d74b934 100644 --- a/spec/page_objects/shared/html_editor.rb +++ b/spec/page_objects/shared/html_editor.rb @@ -1,35 +1,35 @@ # frozen_string_literal: true -require_relative '../base_object' +module Shared + class HtmlEditor < BaseObject + def content_element + raise NotImplementedError + end -class HtmlEditor < BaseObject - def content_element - raise NotImplementedError - end - - def clear - select_all - content_element.send_keys(:delete) - self - end + def clear + select_all + content_element.send_keys(:delete) + self + end - # @return [self] - def open_dropdown - raise NotImplementedError - end + # @return [self] + def open_dropdown + raise NotImplementedError + end - def select_all - content_element.send_keys([:control, "a"]) - self - end + def select_all + content_element.send_keys([:control, "a"]) + self + end - def toolbar_control(control, ...) - send(:"toggle_#{control}", ...) - self - end + def toolbar_control(control, ...) + send(:"toggle_#{control}", ...) + self + end - def <<(content) - content_element.send_keys(content) - self + def <<(content) + content_element.send_keys(content) + self + end end end diff --git a/spec/page_objects/shared/quill_editor.rb b/spec/page_objects/shared/quill_editor.rb index cc59586..54bfe72 100644 --- a/spec/page_objects/shared/quill_editor.rb +++ b/spec/page_objects/shared/quill_editor.rb @@ -1,44 +1,46 @@ # frozen_string_literal: true -class QuillEditor < HtmlEditor - SELECTOR = '.ql-container' - TOOLBAR_SELECTOR = '.ql-toolbar' +module Shared + class QuillEditor < HtmlEditor + SELECTOR = '.ql-container' + TOOLBAR_SELECTOR = '.ql-toolbar' - attr_reader :toolbar, :toolbar_selector + attr_reader :toolbar, :toolbar_selector - def initialize(selector: SELECTOR, toolbar_selector: TOOLBAR_SELECTOR) - super(selector: selector) - @toolbar = find(toolbar_selector) - @toolbar_selector = toolbar_selector - end + def initialize(selector: SELECTOR, toolbar_selector: TOOLBAR_SELECTOR) + super(selector: selector) + @toolbar = find(toolbar_selector) + @toolbar_selector = toolbar_selector + end - def content_element - @content_element ||= find("#{selector} .ql-editor") - end + def content_element + @content_element ||= find("#{selector} .ql-editor") + end - def control_selector(control) - case control&.to_sym - when :bold then "#{toolbar_selector} button.ql-bold" - when :italic then "#{toolbar_selector} button.ql-italic" - when :underline then "#{toolbar_selector} button.ql-underline" - when :link then "#{toolbar_selector} button.ql-link" - else raise "Invalid control #{control}" + def control_selector(control) + case control&.to_sym + when :bold then "#{toolbar_selector} button.ql-bold" + when :italic then "#{toolbar_selector} button.ql-italic" + when :underline then "#{toolbar_selector} button.ql-underline" + when :link then "#{toolbar_selector} button.ql-link" + else raise "Invalid control #{control}" + end end - end - def toggle_bold - find(control_selector(:bold)).click - end + def toggle_bold + find(control_selector(:bold)).click + end - def toggle_italic - find(control_selector(:italic)).click - end + def toggle_italic + find(control_selector(:italic)).click + end - def toggle_underline - find(control_selector(:underline)).click - end + def toggle_underline + find(control_selector(:underline)).click + end - def toggle_link - find(control_selector(:link)).click + def toggle_link + find(control_selector(:link)).click + end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4679cc8..72a7e92 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,6 +2,11 @@ require_relative 'spec_helper' +require 'zeitwerk' +loader = Zeitwerk::Loader.new +loader.push_dir("#{__dir__}/page_objects") +loader.setup + ENV['RAILS_ENV'] = 'test' require 'simplecov' @@ -13,13 +18,8 @@ require 'rspec/rails' require 'capybara/rails' -require 'rspec/retry' - -Rails.root.glob("../support/**/*.rb").each { |f| require_relative f } -Rails.root.glob("../page_objects/**/*.rb").each { |f| require_relative f } -# Force deprecations to raise an exception. -# ActiveSupport::Deprecation.behavior = :raise +Dir[File.expand_path('support/**/*.rb', __dir__)].each { |f| require_relative f } # Checks for pending migrations and applies them before tests are run. # If you are not using ActiveRecord, you can remove these lines. @@ -31,6 +31,12 @@ end RSpec.configure do |config| + if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1') + config.fixture_paths = [Rails.root.join('spec/fixtures')] + else + config.fixture_path = Rails.root.join('spec/fixtures') + end + config.infer_spec_type_from_file_location! config.filter_rails_from_backtrace! @@ -38,8 +44,6 @@ config.use_instantiated_fixtures = false config.render_views = false - config.default_retry_count = 2 - config.before(:suite) do intro = ('-' * 80) intro << "\n" diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 15060c4..121f474 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -9,10 +9,10 @@ Capybara::Cuprite::Driver.new( app, - window_size: [1600, 1280], + window_size: [1600, 1024], browser_options: browser_options, - process_timeout: 20, - timeout: 20, + process_timeout: 30, + timeout: 30, inspector: true, headless: !ENV['CUPRITE_HEADLESS'].in?(%w[n 0 no false]) ) diff --git a/spec/system/quill_editor_spec.rb b/spec/system/quill_editor_spec.rb index 5d34984..e853eb9 100644 --- a/spec/system/quill_editor_spec.rb +++ b/spec/system/quill_editor_spec.rb @@ -2,9 +2,9 @@ RSpec.describe 'Quill editor' do def lookup_editor(field:) - selector = ["##{field}_input.quill_editor", QuillEditor::SELECTOR].join(' ') - toolbar_selector = ["##{field}_input.quill_editor", QuillEditor::TOOLBAR_SELECTOR].join(' ') - QuillEditor.new(selector: selector, toolbar_selector: toolbar_selector) + selector = ["##{field}_input.quill_editor", Shared::QuillEditor::SELECTOR].join(' ') + toolbar_selector = ["##{field}_input.quill_editor", Shared::QuillEditor::TOOLBAR_SELECTOR].join(' ') + Shared::QuillEditor.new(selector: selector, toolbar_selector: toolbar_selector) end let(:author) { Author.create!(email: 'some_email@example.com', name: 'John Doe', age: 30) }