make sure there is a default_locale when calling the __with_default_locale__ method

did committed Nov 22, 2015
commit 8b8fe8c344d3176ed4550002887114e9e85c886c
Showing 2 changed files with 17 additions and 1 deletions
locomotive/steam/decorators/i18n_decorator.rb b/lib/locomotive/steam/decorators/i18n_decorator.rb +5 -1
@@ @@ -52,7 +52,11 @@ module Locomotive
end
def __with_default_locale__(&block)
- __with_locale__(self.__default_locale__, &block)
+ if self.__default_locale__
+ __with_locale__(self.__default_locale__, &block)
+ else
+ yield
+ end
end
def __freeze_locale__
spec/unit/decorators/i18n_decorator_spec.rb +12 -0
@@ @@ -67,6 +67,18 @@ describe Locomotive::Steam::Decorators::I18nDecorator do
expect(decorated.__locale__).to eq :fr
end
+ context 'default_locale is nil' do
+
+ let(:default_locale) { nil }
+
+ it 'yields the block if no default locale' do
+ decorated.__with_default_locale__ do
+ expect(decorated.title).to eq 'Bonjour monde'
+ end
+ end
+
+ end
+
end
end