Sha256: 5d974e0e9501c2734b9151183177640a2c99d68954b10f1ebb074e7a67c98d3a

Contents?: true

Size: 1.48 KB

Versions: 26

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe Locomotive::Liquid::Filters::Translate do

  let(:site)      { FactoryGirl.create(:site) }
  let(:context)   { Liquid::Context.new({}, {}, {site: site}) }
  let(:template)  { Liquid::Template.parse("{{ 'example_text' | translate }}") }
  subject         { template.render(context) }

  describe '#translate' do
    before do
      values = {
        en: 'Example text', es: 'Texto de ejemplo'
      }
      FactoryGirl.create(:translation, site: site, key: 'example_text', values: values)
    end

    it "uses default locale " do
      should == "Example text"
    end

    context "specifying a locale" do
      let(:template) { Liquid::Template.parse("{{ 'example_text' | translate:'es' }}") }

      it "translates" do
        should == "Texto de ejemplo"
      end
    end

    context "specifying a locale that doesn't exist" do
      let(:template) { Liquid::Template.parse("{{ 'example_text' | translate [locale: nl] }}") }

      it "reverts to default locale" do
        should == "Example text"
      end
    end

    context "with a different global locale" do
      before do
        I18n.locale = :es
      end

      after do
        I18n.locale = :en
      end

      it "translates" do
        should == "Texto de ejemplo"
      end
    end

    context "specifying a scope" do

      let(:template) { Liquid::Template.parse("{{ 'fr' | translate: 'en', 'locomotive.locales' }}") }

      it "translates" do
        should == "French"
      end

    end

  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
locomotive_cms-2.5.7 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.6 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.6.rc2 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.6.rc1 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.5 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.4 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.3 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.2 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.1 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.0 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.0.rc3 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.0.rc2 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.5.0.rc1 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.4.1 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.4.0 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.3.1 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.3.0 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.2.3 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.2.2 spec/lib/locomotive/liquid/filters/translate_spec.rb
locomotive_cms-2.2.1 spec/lib/locomotive/liquid/filters/translate_spec.rb