Sha256: 3be1ab82e983b80fb61917a85cb1e757427d90191bed607806d1a20da236d8e1

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe ExvoGlobalize do

  I18n.load_path = ['spec/fixtures/locales/en.yml']

  let(:i18n_example) { Factory(:i18n_example) }
  let(:i18n_nested_example) { Factory(:i18n_nested_example) }
  let(:i18n_title) { Factory(:i18n_title) }

  it "respects the default_locale setting" do
    I18n.default_locale.should eq(:en)
  end

  it "provides a valid translation for a given key" do
    i18n_example.value.should eq(I18n.t(:example))
  end

  it "provides a valid translation for a scoped key" do
    i18n_nested_example.value.should eq(I18n.t(:example, :scope => [:nested]))
  end

  context "translation storage" do
    let(:hello_world) { 'Hello world' }
    let(:hello_earth) { 'Hello Earth' }

    it "stores a flatten translations hash" do
      I18n.backend.store_flatten_translations({ :en => { 'hello.world' => hello_world, 'hello.earth' => hello_earth } })
      I18n.translate('hello.world').should eql(hello_world)
      I18n.translate('hello.earth').should eql(hello_earth)
    end

    it "stores a flatten translation" do
      I18n.backend.store_flatten_translation(I18n.locale, 'hello.earth', hello_earth)
      I18n.translate(:earth, :scope => [:hello]).should eql(hello_earth)
    end

    it "stores a nested translation" do
      I18n.backend.store_translations(I18n.locale, { :hello => { :world => hello_world } })
      I18n.translate('hello.world').should eql(hello_world)
    end
  end

  it "falls back to the YAML file if the translation is missing in the GlobalizeStore backend (db)" do
    I18n.translate('yaml.title').should eq('YAML Title')
  end

  it "prioritizes the translations from GlobalizeStore backend (db) over others" do
    i18n_title.value.should eq(I18n.translate(:title))
  end

  it "lists available_translations from the Simple backend (YAML files)" do
    simple_backend = I18n.backend.backends.detect { |backend| backend.is_a?(I18n::Backend::Simple) }
    simple_backend.available_translations[:en][:title].should eq('YAML Title')
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
exvo_globalize-0.1.0 spec/integration/exvo_globalize_spec.rb