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.
46 lines
1.2 KiB
Ruby
46 lines
1.2 KiB
Ruby
require "rails_helper"
|
|
|
|
describe Budget::ContentBlock do
|
|
let(:block) { build(:heading_content_block) }
|
|
|
|
it "is valid" do
|
|
expect(block).to be_valid
|
|
end
|
|
|
|
it "Heading is unique per locale" do
|
|
heading_content_block_en = create(:heading_content_block, locale: "en")
|
|
invalid_block = build(:heading_content_block,
|
|
heading: heading_content_block_en.heading, locale: "en")
|
|
|
|
expect(invalid_block).not_to be_valid
|
|
expect(invalid_block.errors.full_messages).to include("Heading has already been taken")
|
|
|
|
valid_block = build(:heading_content_block,
|
|
heading: heading_content_block_en.heading, locale: "es")
|
|
expect(valid_block).to be_valid
|
|
end
|
|
|
|
it "is not valid with a disabled locale" do
|
|
Setting["locales.default"] = "pt-BR"
|
|
Setting["locales.enabled"] = "nl pt-BR"
|
|
|
|
block.locale = "en"
|
|
|
|
expect(block).not_to be_valid
|
|
end
|
|
|
|
describe "#name" do
|
|
it "uses the heading name" do
|
|
block = Budget::ContentBlock.new(heading: Budget::Heading.new(name: "Central"))
|
|
|
|
expect(block.name).to eq "Central"
|
|
end
|
|
|
|
it "returns nil on new records without heading" do
|
|
block = Budget::ContentBlock.new
|
|
|
|
expect(block.name).to be nil
|
|
end
|
|
end
|
|
end
|