Sha256: db577af2af09d509327cff6f2e5c9a841239b407ad1fbe0c2f0911d6282ecf06

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 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' }
    let(:globalize_store_backend) { I18n.backend.backends.detect { |backend| backend.is_a?(I18n::Backend::GlobalizeStore) } }

    it "stores nested translations in the GlobalizeStore backend" do
      globalize_store_backend.store_translations(I18n.locale, { :hello => { :world => hello_world} })
      I18n.translate('hello.world').should eql(hello_world)
    end

    it "stores flatten translation in the GlobalizeStore backend" do
      globalize_store_backend.store_flatten_translation(I18n.locale, 'hello.earth', hello_earth)
      I18n.translate(:earth, :scope => [:hello]).should eql(hello_earth)
    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.0.2 spec/integration/exvo_globalize_spec.rb