spec/models/locomotive/site_spec.rb in locomotive_cms-2.1.4 vs spec/models/locomotive/site_spec.rb in locomotive_cms-2.2.0

- old
+ new

@@ -105,57 +105,77 @@ site.domains_without_subdomain.should == %w{www.acme.net www.acme.com} end describe 'once created' do - before(:each) do - @site = FactoryGirl.create(:site) - end + let(:site) { FactoryGirl.create(:site, locales: locales) } - it 'should create index and 404 pages' do - @site.pages.size.should == 2 - @site.pages.map(&:fullpath).sort.should == %w{404 index} - end + context 'the default locale is fr' do - it 'translates the index/404 pages if a new locale is added' do - @site.update_attributes locales: %w(en fr) + let(:locales) { ['fr'] } - @site.errors.should be_empty + it 'creates the index and 404 pages' do + site.pages.size.should == 2 - ::Mongoid::Fields::I18n.with_locale('fr') do - @site.pages.root.first.tap do |page| - page.title.should == "Page d'accueil" - page.slug.should == 'index' - end + site.pages.map(&:fullpath).sort.should == [nil, nil] - @site.pages.not_found.first.tap do |page| - page.title.should == 'Page non trouvée' - page.slug.should == '404' + ::Mongoid::Fields::I18n.with_locale('fr') do + site.pages.map(&:fullpath).sort.should == %w{404 index} end end + end - it 'translates the index/404 pages if the default locale changes' do - @site.update_attributes locales: %w(fr en) + context 'the default locale is en' do - @site.errors.should be_empty + let(:locales) { ['en'] } - ::Mongoid::Fields::I18n.with_locale('fr') do - @site.pages.root.first.tap do |page| - page.title.should == "Page d'accueil" - page.slug.should == 'index' + it 'should create the index and 404 pages' do + site.pages.size.should == 2 + site.pages.map(&:fullpath).sort.should == %w{404 index} + end + + it 'translates the index/404 pages if a new locale is added' do + site.update_attributes locales: %w(en fr) + + site.errors.should be_empty + + ::Mongoid::Fields::I18n.with_locale('fr') do + site.pages.root.first.tap do |page| + page.title.should == "Page d'accueil" + page.slug.should == 'index' + end + + site.pages.not_found.first.tap do |page| + page.title.should == 'Page non trouvée' + page.slug.should == '404' + end end + end - @site.pages.not_found.first.tap do |page| - page.title.should == 'Page non trouvée' - page.slug.should == '404' + it 'translates the index/404 pages if the default locale changes' do + site.update_attributes locales: %w(fr en) + + site.errors.should be_empty + + ::Mongoid::Fields::I18n.with_locale('fr') do + site.pages.root.first.tap do |page| + page.title.should == "Page d'accueil" + page.slug.should == 'index' + end + + site.pages.not_found.first.tap do |page| + page.title.should == 'Page non trouvée' + page.slug.should == '404' + end end end - end - it 'does not allow to remove the default locale' do - @site.update_attributes locales: %w(fr) - @site.errors[:locales].should == ['The previous default locale can not be removed right away.'] + it 'does not allow to remove the default locale' do + site.update_attributes locales: %w(fr) + site.errors[:locales].should == ['The previous default locale can not be removed right away.'] + end + end end describe 'deleting in cascade' do