Sha256: 8ba22e6bccacbbe9e09867855d5bdb756e2ced9e6364cdb3b1f31e5c6168d4e0

Contents?: true

Size: 1.73 KB

Versions: 12

Compression:

Stored size: 1.73 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
require File.expand_path(File.dirname(__FILE__) + '/../data/models')

class StiTranslatedTest < ActiveSupport::TestCase
  def setup
    I18n.locale = :'en-US'
    reset_db!
  end

  test "works with simple dynamic finders" do
    foo = Child.create :content => 'foo'
    Child.create :content => 'bar'
    child = Child.find_by_content('foo')
    assert_equal foo, child
  end

  test 'change attribute on globalized model' do
    child = Child.create :content => 'foo'
    assert_equal [], child.changed
    child.content = 'bar'
    assert_equal [ 'content' ], child.changed
    child.content = 'baz'
    assert_member 'content', child.changed
  end

  test 'change attribute on globalized model after locale switching' do
    child = Child.create :content => 'foo'
    assert_equal [], child.changed
    child.content = 'bar'
    I18n.locale = :de
    assert_equal [ 'content' ], child.changed
  end

  test "saves all locales, even after locale switching" do
    child = Child.new :content => 'foo'
    I18n.locale = 'de-DE'
    child.content = 'bar'
    I18n.locale = 'he-IL'
    child.content = 'baz'
    child.save
    I18n.locale = 'en-US'
    child = Child.first
    assert_equal 'foo', child.content
    I18n.locale = 'de-DE'
    assert_equal 'bar', child.content
    I18n.locale = 'he-IL'
    assert_equal 'baz', child.content
  end
  
  test "works when STI class is defined before globalize is applied" do
    child = EarlyChild.create :content => 'foo'
    I18n.locale = 'de-DE'
    child.content = 'bar'
    child.save
    I18n.locale = 'en-US'
    child = EarlyChild.first
    assert_equal 'foo', child.content
    I18n.locale = 'de-DE'
    assert_equal 'bar', child.content
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
radiant-globalize2-extension-0.3.2 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.3.1 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.3.0 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.8 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.7 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.6 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.5 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.4 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.3 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.2 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.1 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
radiant-globalize2-extension-0.2.0 vendor/plugins/globalize2/test/active_record/sti_translated_test.rb