Use Zeitwerk instead of the classic autoloader

In Rails 6.1, the classic autoloader is deprecated.

We were getting an error because we were using `autoload` in the
ActiveStorage plugin for CKEditor:

expected file app/lib/ckeditor/backend/active_storage.rb to define
constant Ckeditor::Backend::ActiveStorage

So we're removing the line causing the error.

Finally, we can now restore all the tests that that failed sometimes
with the classic autoloader and that we modified in commits 2af1fc72f
and 8ba37b295.
This commit is contained in:
Javi Martín
2023-07-25 04:46:53 +02:00
parent 004684efe6
commit 5f24ee9121
6 changed files with 33 additions and 42 deletions

View File

@@ -67,7 +67,5 @@ module Ckeditor
end
end
end
autoload :ActiveStorage, "ckeditor/backend/active_storage"
end
end

View File

@@ -32,10 +32,6 @@ module Consul
# in any CONSUL DEMOCRACY installations
config.active_support.use_authenticated_message_encryption = false
# Keep using the classic autoloader until we decide how custom classes
# should work with zeitwerk
config.autoloader = :classic
# Don't enable has_many_inversing because it doesn't seem to currently
# work with the _count database columns we use for caching purposes
config.active_record.has_many_inversing = false
@@ -143,6 +139,7 @@ module Consul
"app/models/custom/concerns"
].each do |path|
config.autoload_paths << Rails.root.join(path)
config.eager_load_paths << Rails.root.join(path)
end
config.paths["app/views"].unshift(Rails.root.join("app", "views", "custom"))

View File

@@ -72,6 +72,7 @@ Rails.application.configure do
# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true
config.eager_load_paths << "#{Rails.root}/spec/mailers/previews"
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
# Limit size of local logs

View File

@@ -178,16 +178,15 @@ describe "Homepage", :admin do
link_text: "Link1 text",
link_url: "consul1.dev")
# TODO: uncomment again after switching to zeitwerk
# card2 = create(:widget_card, label: "Card2 label",
# title: "Card2 text",
# description: "Card2 description",
# link_text: "Link2 text",
# link_url: "consul2.dev")
card2 = create(:widget_card, label: "Card2 label",
title: "Card2 text",
description: "Card2 description",
link_text: "Link2 text",
link_url: "consul2.dev")
visit root_path
expect(page).to have_css(".card", count: 1) # TODO: change to `count: 2 after switching to zeitwerk
expect(page).to have_css(".card", count: 2)
within("#widget_card_#{card1.id}") do
expect(page).to have_content("CARD1 LABEL")
@@ -198,15 +197,14 @@ describe "Homepage", :admin do
expect(page).to have_css("img[alt='#{card1.image.title}']")
end
# TODO: uncomment again after switching to zeitwerk
# within("#widget_card_#{card2.id}") do
# expect(page).to have_content("CARD2 LABEL")
# expect(page).to have_content("CARD2 TEXT")
# expect(page).to have_content("Card2 description")
# expect(page).to have_content("Link2 text")
# expect(page).to have_link(href: "consul2.dev")
# expect(page).to have_css("img[alt='#{card2.image.title}']")
# end
within("#widget_card_#{card2.id}") do
expect(page).to have_content("CARD2 LABEL")
expect(page).to have_content("CARD2 TEXT")
expect(page).to have_content("Card2 description")
expect(page).to have_content("Link2 text")
expect(page).to have_link(href: "consul2.dev")
expect(page).to have_css("img[alt='#{card2.image.title}']")
end
end
scenario "Recomendations" do

View File

@@ -59,16 +59,14 @@ describe "Cards", :admin do
scenario "Show" do
card_1 = create(:widget_card, title: "Card homepage large", columns: 8)
# TODO: uncomment after switching to zeitwerk
# card_2 = create(:widget_card, title: "Card homepage medium", columns: 4)
# card_3 = create(:widget_card, title: "Card homepage small", columns: 2)
card_2 = create(:widget_card, title: "Card homepage medium", columns: 4)
card_3 = create(:widget_card, title: "Card homepage small", columns: 2)
visit root_path
expect(page).to have_css("#widget_card_#{card_1.id}.medium-8")
# TODO: uncomment after switching to zeitwerk
# expect(page).to have_css("#widget_card_#{card_2.id}.medium-4")
# expect(page).to have_css("#widget_card_#{card_3.id}.medium-2")
expect(page).to have_css("#widget_card_#{card_2.id}.medium-4")
expect(page).to have_css("#widget_card_#{card_3.id}.medium-2")
end
scenario "Edit" do

View File

@@ -26,7 +26,7 @@ describe "Polls" do
end
scenario "Polls can be listed" do
polls = [create(:poll, :with_image)] # TODO: generate a list again after switching to zeitwerk
polls = create_list(:poll, 3, :with_image)
visit polls_path
@@ -210,24 +210,23 @@ describe "Polls" do
expect("Second question").to appear_before("Third question")
end
# TODO: uncomment after switching to zeitwerk
# scenario "Buttons to slide through images work back and forth" do
# question = create(:poll_question, :yes_no, poll: poll)
# create(:image, imageable: question.question_answers.last, title: "The no movement")
# create(:image, imageable: question.question_answers.last, title: "No movement planning")
scenario "Buttons to slide through images work back and forth" do
question = create(:poll_question, :yes_no, poll: poll)
create(:image, imageable: question.question_answers.last, title: "The no movement")
create(:image, imageable: question.question_answers.last, title: "No movement planning")
# visit poll_path(poll)
visit poll_path(poll)
# within(".orbit-bullets") do
# find("[data-slide='1']").click
within(".orbit-bullets") do
find("[data-slide='1']").click
# expect(page).to have_css ".is-active[data-slide='1']"
expect(page).to have_css ".is-active[data-slide='1']"
# find("[data-slide='0']").click
find("[data-slide='0']").click
# expect(page).to have_css ".is-active[data-slide='0']"
# end
# end
expect(page).to have_css ".is-active[data-slide='0']"
end
end
scenario "Non-logged in users" do
create(:poll_question, :yes_no, poll: poll)