Sha256: 7c210ecdd52163482997a20b8fc4a24a8c6d6b4a43abfb5b762724ebb5ac2aca

Contents?: true

Size: 1.9 KB

Versions: 4

Compression:

Stored size: 1.9 KB

Contents

# encoding: utf-8
$:.unshift(File.expand_path(File.dirname(__FILE__) + '/../../')); $:.uniq!
require 'test_helper'

require_active_record!

class I18nActiveRecordMissingTest < Test::Unit::TestCase
  def setup
    store_translations(:en, :i18n => { :plural => { :keys => [:zero, :one, :other] } })
    
    I18n.backend = I18n::Backend::Chain.new(I18n.backend)
    I18n.backend.meta_class.send(:include, I18n::Backend::ActiveRecord::Missing)
    
    I18n::Backend::ActiveRecord::Translation.delete_all
  end
  
  test "can persist interpolations" do
    translation = I18n::Backend::ActiveRecord::Translation.new(:key => 'foo', :value => 'bar', :locale => :en)
    translation.interpolations = %w(count name)
    translation.save
    assert translation.valid?
  end

  test "lookup persists the key" do
    I18n.t('foo.bar.baz')
    assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
  end

  test "lookup does not persist the key twice" do
    2.times { I18n.t('foo.bar.baz') }
    assert_equal 1, I18n::Backend::ActiveRecord::Translation.count
  end
  
  test "lookup persists interpolation keys when looked up directly" do
    I18n.t('foo.bar.baz', :cow => "lucy" )  # creates stub translation.
    translation_stub = I18n::Backend::ActiveRecord::Translation.locale(:en).lookup('foo.bar.baz').first
    assert translation_stub.interpolates?(:cow)
  end

  test "creates one stub per pluralization" do
    I18n.t('foo', :count => 999)
    translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_all_by_key %w{ foo.zero foo.one foo.other }
    assert_equal 3, translations.length
  end

  test "creates no stub for base key in pluralization" do
    I18n.t('foo', :count => 999)
    translations = I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key %w{ foo.zero foo.one foo.other }
    assert !I18n::Backend::ActiveRecord::Translation.locale(:en).find_by_key("foo")
  end
end if defined?(ActiveRecord)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
i18n-0.3.6 test/backend/active_record/missing_test.rb
i18n-0.3.6.pre test/backend/active_record/missing_test.rb
i18n-0.3.5 test/backend/active_record/missing_test.rb
i18n-0.3.4 test/backend/active_record/missing_test.rb