Sha256: 5ffbd2e3ca0c3b662a143a5bc8259f040a3257f8950744a787dcb974331b687f

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

require 'spec_helper'

describe Locomotive::Extensions::Site::Locales do

  let(:site) { FactoryGirl.build(:site, locales: [:en, :fr]) }

  describe '#localized_page_fullpath' do

    context 'index page' do

      let(:page) { build_page }

      it 'returns an empty string if default locale' do
        site.localized_page_fullpath(page).should == ''
      end

      it 'returns only the locale if another locale ' do
        site.localized_page_fullpath(page, 'fr').should == 'fr'
      end

    end

    context 'another page' do

      let(:page) { build_page('about-us', { fr: 'a-notre-sujet' }) }

      it 'returns only the fullpath if default locale' do
        site.localized_page_fullpath(page).should == 'about-us'
      end

      it 'returns the fullpath if another locale' do
        site.localized_page_fullpath(page, 'fr').should == 'fr/a-notre-sujet'
      end

    end

  end

  def build_page(slug = nil, translations = {})
    FactoryGirl.build(:page).tap do |page|
      page.slug = slug if slug
      page.send(:build_fullpath)
      translations.each do |locale, translation|
        ::Mongoid::Fields::I18n.with_locale(locale) do
          page.slug = translation
          page.send(:build_fullpath)
        end
      end
    end
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.6 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.6.rc2 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.6.rc1 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.5 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.4 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.3 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.2 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.1 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.0 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.0.rc3 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.0.rc2 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.5.0.rc1 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.4.1 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.4.0 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.3.1 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.3.0 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.2.3 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.2.2 spec/models/locomotive/extensions/site/locales_spec.rb
locomotive_cms-2.2.1 spec/models/locomotive/extensions/site/locales_spec.rb