Sha256: ff3e610d369a13c3d73fc5391767a5278991b2108eda7c74d063e80d5cad5934

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'spec_helper'

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

  let(:source) { "{{ 'welcome_message' | translate }}" }

  let(:site)        { Locomotive::Steam::Site.new(_id: site_id, locales: %w(en fr nb)) }
  let(:services)    { Locomotive::Steam::Services.build_instance }
  let(:translator)  { services.translator }
  let(:assigns)     { {} }
  let(:context)     { ::Liquid::Context.new(assigns, {}, { services: services }) }

  before { services.locale = :en }

  subject { render_template(source, context) }

  context 'missing translation' do

    before { allow(translator).to receive(:translate).and_return(nil) }

    it { is_expected.to eq 'welcome_message' }

  end

  context 'existing translation' do

    before { allow(translator).to receive(:translate).and_return('Hello world') }

    it { is_expected.to eq 'Hello world' }

  end

  describe 'passing a locale and a scope' do

    before { allow(translator).to receive(:translate).and_return('Bonjour monde') }

    describe 'legacy syntax' do

      let(:source) { "{{ 'welcome_message' | translate: 'fr', 'locomotive.default' }}" }
      it { expect(translator).to receive(:translate).with('welcome_message', 'locale' => 'fr', 'scope' => 'locomotive.default'); subject }

    end

    describe 'new syntax' do

      let(:source) { "{{ 'welcome_message' | translate: locale: 'fr', scope: 'locomotive.default' }}" }
      it { expect(translator).to receive(:translate).with('welcome_message', 'locale' => 'fr', 'scope' => 'locomotive.default'); subject }

    end

  end

  describe 'pluralization' do

    let(:translation) { { 'en' => '{{ name }} has {{ count }} articles' } }
    before { expect(translator.repository).to receive(:group_by_key).and_return({ 'post_count_two' => translation }) }

    let(:source) { "{{ 'post_count' | translate: count: 2, name: 'John' }}" }
    it { expect(subject).to eq('John has 2 articles') }

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
locomotivecms_steam-1.5.0.beta3 spec/integration/liquid/filters/translate_spec.rb