make sure we already have a non blank locales attribute
did
committed Oct 01, 2015
commit 3a1fd5dc4917e56111bbfddfffc3fb91bf49fdd0
Showing 2
changed files with
24 additions
and 8 deletions
locomotive/steam/entities/site.rb b/lib/locomotive/steam/entities/site.rb
+2
-2
| @@ | @@ -19,11 +19,11 @@ module Locomotive::Steam |
| end | |
| def default_locale | |
| - | locales.try(:first) || :en |
| + | locales.first || :en |
| end | |
| def locales | |
| - | self[:locales].map(&:to_sym) |
| + | (self[:locales] || [:en]).map(&:to_sym) |
| end | |
| def timezone_name | |
spec/unit/entities/site_spec.rb
+22
-6
| @@ | @@ -23,19 +23,35 @@ describe Locomotive::Steam::Site do |
| describe '#locales' do | |
| - | let(:attributes) { { locales: %w(en fr) } } |
| - | |
| subject { site.locales } | |
| - | it { is_expected.to eq [:en, :fr] } |
| + | |
| + | context 'without locales' do |
| + | it { is_expected.to eq [:en] } |
| + | end |
| + | |
| + | context 'with locales' do |
| + | |
| + | let(:attributes) { { locales: %w(en fr) } } |
| + | it { is_expected.to eq [:en, :fr] } |
| + | |
| + | end |
| end | |
| describe '#default_locale' do | |
| - | let(:attributes) { { locales: %w(en fr) } } |
| - | |
| subject { site.default_locale } | |
| - | it { is_expected.to eq :en } |
| + | |
| + | context 'without locales' do |
| + | it { is_expected.to eq :en } |
| + | end |
| + | |
| + | context 'with locales' do |
| + | |
| + | let(:attributes) { { locales: %w(en fr) } } |
| + | it { is_expected.to eq :en } |
| + | |
| + | end |
| end | |