Files
grecia/spec/models/site_customization/content_block_spec.rb
Javi Martín 6de4737b70 Allow different default locales per tenant
Note that, for everything to work consistently, we need to make sure
that the default locale is one of the available locales.

Also note that we aren't overwriting the `#save ` method set by
globalize. I didn't feel too comfortable changing a monkey-patch which
ideally shouldn't be there in the first place, I haven't found a case
where `Globalize.locale` is `nil` (since it defaults to `I18n.locale`,
which should never be `nil`), so using `I18n.default_locale` probably
doesn't affect us.
2024-06-05 16:10:56 +02:00

40 lines
1.1 KiB
Ruby

require "rails_helper"
RSpec.describe SiteCustomization::ContentBlock do
let(:block) { build(:site_customization_content_block) }
it "is valid" do
expect(block).to be_valid
end
it "name is unique per locale" do
create(:site_customization_content_block, name: "top_links", locale: "en")
invalid_block = build(:site_customization_content_block, name: "top_links", locale: "en")
expect(invalid_block).not_to be_valid
expect(invalid_block.errors.full_messages).to include("Name has already been taken")
valid_block = build(:site_customization_content_block, name: "top_links", locale: "es")
expect(valid_block).to be_valid
end
it "dynamically validates the valid blocks" do
stub_const("#{SiteCustomization::ContentBlock}::VALID_BLOCKS", %w[custom])
block.name = "custom"
expect(block).to be_valid
block.name = "top_links"
expect(block).not_to be_valid
end
it "is not valid with a disabled locale" do
Setting["locales.default"] = "nl"
Setting["locales.enabled"] = "nl pt-BR"
block.locale = "en"
expect(block).not_to be_valid
end
end