We were getting a few errors when trying out Zeitwerk: ``` expected file lib/sms_api.rb to define constant SmsApi expected file app/components/layout/common_html_attributes_component.rb to define constant Layout::CommonHtmlAttributesComponent ``` In these cases, we aren't using an inflection because we also define the `Verification::SmsController` and a few migrations containing `Html` in their class name, and none of them would work if we defined the inflection. We were also getting an error regarding classes containing WYSIWYG in its name: ``` NameError: uninitialized constant WYSIWYGSanitizer Did you mean? WysiwygSanitizer ``` In this case, adding the acronym is easier, since we never use "Wysiwyg" in the code but we use "WYSIWYG" in many places.
67 lines
1.9 KiB
Ruby
67 lines
1.9 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Layout::CommonHtmlAttributesComponent do
|
|
let(:component) { Layout::CommonHtmlAttributesComponent.new }
|
|
|
|
context "with multitenancy disabled" do
|
|
before { allow(Rails.application.config).to receive(:multitenancy).and_return(false) }
|
|
|
|
it "includes the default language by default" do
|
|
render_inline component
|
|
|
|
expect(page.text).to eq 'lang="en"'
|
|
end
|
|
|
|
it "includes the current language" do
|
|
I18n.with_locale(:es) { render_inline component }
|
|
|
|
expect(page.text).to eq 'lang="es"'
|
|
end
|
|
end
|
|
|
|
context "with multitenancy enabled" do
|
|
it "includes a class with the 'public' suffix for the default tenant" do
|
|
render_inline component
|
|
|
|
expect(page.text).to eq 'lang="en" class="tenant-public"'
|
|
end
|
|
|
|
it "includes a class with the schema name as suffix for other tenants" do
|
|
allow(Tenant).to receive(:current_schema).and_return "private"
|
|
|
|
render_inline component
|
|
|
|
expect(page.text).to eq 'lang="en" class="tenant-private"'
|
|
end
|
|
end
|
|
|
|
context "RTL languages" do
|
|
let!(:default_enforce) { I18n.enforce_available_locales }
|
|
|
|
before do
|
|
I18n.enforce_available_locales = false
|
|
allow(I18n).to receive(:available_locales).and_return(%i[ar en es])
|
|
end
|
|
|
|
after { I18n.enforce_available_locales = default_enforce }
|
|
|
|
context "with multitenancy disabled" do
|
|
before { allow(Rails.application.config).to receive(:multitenancy).and_return(false) }
|
|
|
|
it "includes the dir attribute" do
|
|
I18n.with_locale(:ar) { render_inline component }
|
|
|
|
expect(page.text).to eq 'dir="rtl" lang="ar"'
|
|
end
|
|
end
|
|
|
|
context "with multitenancy enabled" do
|
|
it "includes the dir and the class attributes" do
|
|
I18n.with_locale(:ar) { render_inline component }
|
|
|
|
expect(page.text).to eq 'dir="rtl" lang="ar" class="tenant-public"'
|
|
end
|
|
end
|
|
end
|
|
end
|