Files
nairobi/spec/models/concerns/globalizable.rb
Javi Martín 2db8c80633 Simplify globalizable specs
We don't need `before` blocks because we've removed the `after` blocks,
and we don't need to define available locales because we already do so
in the test environment file.
2019-09-23 18:01:44 +02:00

42 lines
1.2 KiB
Ruby

require "spec_helper"
shared_examples_for "globalizable" do |factory_name|
let(:record) { create(factory_name) }
let(:fields) { record.translated_attribute_names }
let(:attribute) { fields.sample }
describe "Fallbacks" do
before do
record.update_attribute(attribute, "In English")
{ es: "En español", de: "Deutsch" }.each do |locale, text|
Globalize.with_locale(locale) do
fields.each do |field|
record.update_attribute(field, record.send(field))
end
record.update_attribute(attribute, text)
end
end
end
it "Falls back to a defined fallback" do
allow(I18n.fallbacks).to receive(:[]).and_return([:fr, :es])
Globalize.set_fallbacks_to_all_available_locales
Globalize.with_locale(:fr) do
expect(record.send(attribute)).to eq "En español"
end
end
it "Falls back to the first available locale without a defined fallback" do
allow(I18n.fallbacks).to receive(:[]).and_return([:fr])
Globalize.set_fallbacks_to_all_available_locales
Globalize.with_locale(:fr) do
expect(record.send(attribute)).to eq "Deutsch"
end
end
end
end