1 require File.join( File.dirname(__FILE__), '..', '..', 'test_helper' )
2 require 'active_record'
3 require 'globalize/model/active_record'
5 # Hook up model translation
6 ActiveRecord::Base.send(:include, Globalize::Model::ActiveRecord::Translated)
9 require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' )
11 class StiTranslatedTest < ActiveSupport::TestCase
13 I18n.locale = :'en-US'
15 reset_db! File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'schema.rb'))
22 test "works with simple dynamic finders" do
23 foo = Child.create :content => 'foo'
24 Child.create :content => 'bar'
25 child = Child.find_by_content('foo')
26 assert_equal foo, child
29 test 'change attribute on globalized model' do
30 child = Child.create :content => 'foo'
31 assert_equal [], child.changed
33 assert_equal [ 'content' ], child.changed
35 assert_member 'content', child.changed
38 test 'change attribute on globalized model after locale switching' do
39 child = Child.create :content => 'foo'
40 assert_equal [], child.changed
43 assert_equal [ 'content' ], child.changed
46 test 'fallbacks with lots of locale switching' do
47 I18n.fallbacks.map :'de-DE' => [ :'en-US' ]
48 child = Child.create :content => 'foo'
50 I18n.locale = :'de-DE'
51 assert_equal 'foo', child.content
53 I18n.locale = :'en-US'
54 child.update_attribute :content, 'bar'
56 I18n.locale = :'de-DE'
57 assert_equal 'bar', child.content
60 test "saves all locales, even after locale switching" do
61 child = Child.new :content => 'foo'
69 assert_equal 'foo', child.content
71 assert_equal 'bar', child.content
73 assert_equal 'baz', child.content