summaryrefslogtreecommitdiff
path: root/vendor/plugins/globalize2/test
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-06-24 04:13:16 +0200
committererdgeist <erdgeist@erdgeist.org>2026-06-24 04:13:16 +0200
commite0a7e0fec760ba12c8067a37e10c96f1f05876e2 (patch)
treed0cf745592a46aee4d4913911fd34c7c24515220 /vendor/plugins/globalize2/test
parent6424e10be5a89f175a74c71c55660412a169b8b8 (diff)
Stage 1 complete: Rails 2.3.5 to Rails 3.2.22.5 upgrade
- Converted plugins to gems (Gemfile) - Updated config structure (application.rb, boot.rb, environment.rb) - Converted routes to Rails 3 DSL - Converted named_scope to scope throughout models - Converted find(:all, :conditions) to where() chains - Fixed has_many :order to use ordering scope - Updated session store and secret token configuration - Fixed exception_notification middleware configuration - Patched Ruby 2.4 / Rails 3.2 incompatibilities: - Integer/Float duration arithmetic (ActiveSupport) - Arel visit_Integer for PostgreSQL adapter - create_database String/Integer coercion - ActionController consider_all_requests_local - Migrated taggings schema for acts-as-taggable-on - Replaced dynamic_form gem with custom form_error_messages helper - Fixed Rails 3 block helper syntax (form_for, form_tag, fields_for) - Fixed admin layout yield - Updated test suite for Rails 3 APIs
Diffstat (limited to 'vendor/plugins/globalize2/test')
-rw-r--r--vendor/plugins/globalize2/test/active_record/fallbacks_test.rb102
-rw-r--r--vendor/plugins/globalize2/test/active_record/migration_test.rb118
-rw-r--r--vendor/plugins/globalize2/test/active_record/sti_translated_test.rb49
-rw-r--r--vendor/plugins/globalize2/test/active_record/translates_test.rb87
-rw-r--r--vendor/plugins/globalize2/test/active_record/translation_class_test.rb30
-rw-r--r--vendor/plugins/globalize2/test/active_record/validation_tests.rb75
-rw-r--r--vendor/plugins/globalize2/test/active_record_test.rb442
-rw-r--r--vendor/plugins/globalize2/test/all.rb2
-rw-r--r--vendor/plugins/globalize2/test/data/models.rb51
-rw-r--r--vendor/plugins/globalize2/test/data/no_globalize_schema.rb11
-rw-r--r--vendor/plugins/globalize2/test/i18n/missing_translations_test.rb36
-rw-r--r--vendor/plugins/globalize2/test/test_helper.rb76
12 files changed, 0 insertions, 1079 deletions
diff --git a/vendor/plugins/globalize2/test/active_record/fallbacks_test.rb b/vendor/plugins/globalize2/test/active_record/fallbacks_test.rb
deleted file mode 100644
index 449ec8b..0000000
--- a/vendor/plugins/globalize2/test/active_record/fallbacks_test.rb
+++ /dev/null
@@ -1,102 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4if I18n.respond_to?(:fallbacks)
5 class TranslatedTest < ActiveSupport::TestCase
6 def setup
7 I18n.locale = :'en-US'
8 I18n.fallbacks.clear
9 reset_db!
10 ActiveRecord::Base.locale = nil
11 end
12
13 def teardown
14 I18n.fallbacks.clear
15 end
16
17 test "keeping one field in new locale when other field is changed" do
18 I18n.fallbacks.map 'de-DE' => [ 'en-US' ]
19 post = Post.create :subject => 'foo'
20 I18n.locale = 'de-DE'
21 post.content = 'bar'
22 assert_equal 'foo', post.subject
23 end
24
25 test "modifying non-required field in a new locale" do
26 I18n.fallbacks.map 'de-DE' => [ 'en-US' ]
27 post = Post.create :subject => 'foo'
28 I18n.locale = 'de-DE'
29 post.content = 'bar'
30 assert post.save
31 end
32
33 test "resolves a simple fallback" do
34 I18n.locale = 'de-DE'
35 post = Post.create :subject => 'foo'
36 I18n.locale = 'de'
37 post.subject = 'baz'
38 post.content = 'bar'
39 post.save
40 I18n.locale = 'de-DE'
41 assert_equal 'foo', post.subject
42 assert_equal 'bar', post.content
43 end
44
45 test "resolves a simple fallback without reloading" do
46 I18n.locale = 'de-DE'
47 post = Post.new :subject => 'foo'
48 I18n.locale = 'de'
49 post.subject = 'baz'
50 post.content = 'bar'
51 I18n.locale = 'de-DE'
52 assert_equal 'foo', post.subject
53 assert_equal 'bar', post.content
54 end
55
56 test "resolves a complex fallback without reloading" do
57 I18n.fallbacks.map 'de' => %w(en he)
58 I18n.locale = 'de'
59 post = Post.new
60 I18n.locale = 'en'
61 post.subject = 'foo'
62 I18n.locale = 'he'
63 post.subject = 'baz'
64 post.content = 'bar'
65 I18n.locale = 'de'
66 assert_equal 'foo', post.subject
67 assert_equal 'bar', post.content
68 end
69
70 test 'fallbacks with lots of locale switching' do
71 I18n.fallbacks.map :'de-DE' => [ :'en-US' ]
72 post = Post.create :subject => 'foo'
73
74 I18n.locale = :'de-DE'
75 assert_equal 'foo', post.subject
76
77 I18n.locale = :'en-US'
78 post.update_attribute :subject, 'bar'
79
80 I18n.locale = :'de-DE'
81 assert_equal 'bar', post.subject
82 end
83
84 test 'fallbacks with lots of locale switching' do
85 I18n.fallbacks.map :'de-DE' => [ :'en-US' ]
86 child = Child.create :content => 'foo'
87
88 I18n.locale = :'de-DE'
89 assert_equal 'foo', child.content
90
91 I18n.locale = :'en-US'
92 child.update_attribute :content, 'bar'
93
94 I18n.locale = :'de-DE'
95 assert_equal 'bar', child.content
96 end
97 end
98end
99
100# TODO should validate_presence_of take fallbacks into account? maybe we need
101# an extra validation call, or more options for validate_presence_of.
102
diff --git a/vendor/plugins/globalize2/test/active_record/migration_test.rb b/vendor/plugins/globalize2/test/active_record/migration_test.rb
deleted file mode 100644
index 359d811..0000000
--- a/vendor/plugins/globalize2/test/active_record/migration_test.rb
+++ /dev/null
@@ -1,118 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4class MigrationTest < ActiveSupport::TestCase
5 def setup
6 reset_db!
7 Post.drop_translation_table!
8 end
9
10 test 'globalize table added' do
11 assert !Post.connection.table_exists?(:post_translations)
12 assert !Post.connection.index_exists?(:post_translations, :post_id)
13
14 Post.create_translation_table!(:subject => :string, :content => :text)
15 assert Post.connection.table_exists?(:post_translations)
16 assert Post.connection.index_exists?(:post_translations, :post_id)
17
18 columns = Post.connection.columns(:post_translations)
19 assert locale = columns.detect { |c| c.name == 'locale' }
20 assert_equal :string, locale.type
21 assert subject = columns.detect { |c| c.name == 'subject' }
22 assert_equal :string, subject.type
23 assert content = columns.detect { |c| c.name == 'content' }
24 assert_equal :text, content.type
25 assert post_id = columns.detect { |c| c.name == 'post_id' }
26 assert_equal :integer, post_id.type
27 assert created_at = columns.detect { |c| c.name == 'created_at' }
28 assert_equal :datetime, created_at.type
29 assert updated_at = columns.detect { |c| c.name == 'updated_at' }
30 assert_equal :datetime, updated_at.type
31 end
32
33 test 'globalize table dropped' do
34 assert !Post.connection.table_exists?( :post_translations )
35 assert !Post.connection.index_exists?( :post_translations, :post_id )
36 Post.create_translation_table! :subject => :string, :content => :text
37 assert Post.connection.table_exists?( :post_translations )
38 assert Post.connection.index_exists?( :post_translations, :post_id )
39 Post.drop_translation_table!
40 assert !Post.connection.table_exists?( :post_translations )
41 assert !Post.connection.index_exists?( :post_translations, :post_id )
42 end
43
44 test 'exception on missing field inputs' do
45 assert_raise Globalize::MigrationMissingTranslatedField do
46 Post.create_translation_table! :content => :text
47 end
48 end
49
50 test 'exception on bad input type' do
51 assert_raise Globalize::BadMigrationFieldType do
52 Post.create_translation_table! :subject => :string, :content => :integer
53 end
54 end
55
56 test "exception on bad input type isn't raised for untranslated fields" do
57 assert_nothing_raised do
58 Post.create_translation_table! :subject => :string, :content => :string, :views_count => :integer
59 end
60 end
61
62 test 'create_translation_table! should not be called on non-translated models' do
63 assert_raise NoMethodError do
64 Blog.create_translation_table! :name => :string
65 end
66 end
67
68 test 'drop_translation_table! should not be called on non-translated models' do
69 assert_raise NoMethodError do
70 Blog.drop_translation_table!
71 end
72 end
73
74 test "translation_index_name returns a readable index name when it's not longer than 50 characters" do
75 assert_equal 'index_post_translations_on_post_id', Post.send(:translation_index_name)
76 end
77
78 test "translation_index_name returns a hashed index name when it's longer than 50 characters" do
79 class UltraLongModelNameWithoutProper < ActiveRecord::Base
80 translates :foo
81 end
82 name = UltraLongModelNameWithoutProper.send(:translation_index_name)
83 assert_match /^index_[a-z0-9]{40}$/, name
84 end
85
86 test 'globalize table added when table has long name' do
87 UltraLongModelNameWithoutProper.create_translation_table!(
88 :subject => :string, :content => :text
89 )
90
91 assert UltraLongModelNameWithoutProper.connection.table_exists?(
92 :ultra_long_model_name_without_proper_translations
93 )
94 assert UltraLongModelNameWithoutProper.connection.index_exists?(
95 :ultra_long_model_name_without_proper_translations,
96 :name => UltraLongModelNameWithoutProper.send(
97 :translation_index_name
98 )
99 )
100 end
101
102 test 'globalize table dropped when table has long name' do
103 UltraLongModelNameWithoutProper.drop_translation_table!
104 UltraLongModelNameWithoutProper.create_translation_table!(
105 :subject => :string, :content => :text
106 )
107 UltraLongModelNameWithoutProper.drop_translation_table!
108
109 assert !UltraLongModelNameWithoutProper.connection.table_exists?(
110 :ultra_long_model_name_without_proper_translations
111 )
112 assert !UltraLongModelNameWithoutProper.connection.index_exists?(
113 :ultra_long_model_name_without_proper_translations,
114 :ultra_long_model_name_without_proper_id
115 )
116 end
117
118end
diff --git a/vendor/plugins/globalize2/test/active_record/sti_translated_test.rb b/vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
deleted file mode 100644
index f529b8d..0000000
--- a/vendor/plugins/globalize2/test/active_record/sti_translated_test.rb
+++ /dev/null
@@ -1,49 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4class StiTranslatedTest < ActiveSupport::TestCase
5 def setup
6 I18n.locale = :'en-US'
7 reset_db!
8 end
9
10 test "works with simple dynamic finders" do
11 foo = Child.create :content => 'foo'
12 Child.create :content => 'bar'
13 child = Child.find_by_content('foo')
14 assert_equal foo, child
15 end
16
17 test 'change attribute on globalized model' do
18 child = Child.create :content => 'foo'
19 assert_equal [], child.changed
20 child.content = 'bar'
21 assert_equal [ 'content' ], child.changed
22 child.content = 'baz'
23 assert_member 'content', child.changed
24 end
25
26 test 'change attribute on globalized model after locale switching' do
27 child = Child.create :content => 'foo'
28 assert_equal [], child.changed
29 child.content = 'bar'
30 I18n.locale = :de
31 assert_equal [ 'content' ], child.changed
32 end
33
34 test "saves all locales, even after locale switching" do
35 child = Child.new :content => 'foo'
36 I18n.locale = 'de-DE'
37 child.content = 'bar'
38 I18n.locale = 'he-IL'
39 child.content = 'baz'
40 child.save
41 I18n.locale = 'en-US'
42 child = Child.first
43 assert_equal 'foo', child.content
44 I18n.locale = 'de-DE'
45 assert_equal 'bar', child.content
46 I18n.locale = 'he-IL'
47 assert_equal 'baz', child.content
48 end
49end
diff --git a/vendor/plugins/globalize2/test/active_record/translates_test.rb b/vendor/plugins/globalize2/test/active_record/translates_test.rb
deleted file mode 100644
index 4207bc4..0000000
--- a/vendor/plugins/globalize2/test/active_record/translates_test.rb
+++ /dev/null
@@ -1,87 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4class TranslatesTest < ActiveSupport::TestCase
5 def setup
6 I18n.locale = nil
7 ActiveRecord::Base.locale = nil
8 reset_db!
9 end
10
11 test 'defines a :locale accessors on ActiveRecord::Base' do
12 ActiveRecord::Base.locale = :de
13 assert_equal :de, ActiveRecord::Base.locale
14 end
15
16 test 'the :locale reader on ActiveRecord::Base does not default to I18n.locale (anymore)' do
17 I18n.locale = :en
18 assert_nil ActiveRecord::Base.locale
19 end
20
21 test 'ActiveRecord::Base.with_locale temporarily sets the given locale and yields the block' do
22 I18n.locale = :en
23 post = Post.with_locale(:de) do
24 Post.create!(:subject => 'Titel', :content => 'Inhalt')
25 end
26 assert_nil Post.locale
27 assert_equal :en, I18n.locale
28
29 I18n.locale = :de
30 assert_equal 'Titel', post.subject
31 end
32
33 test 'translation_class returns the Translation class' do
34 assert_equal Post::Translation, Post.translation_class
35 end
36
37 test 'defines a has_many association on the model class' do
38 assert_has_many Post, :translations
39 end
40
41 test 'defines a scope for retrieving locales that have complete translations' do
42 post = Post.create!(:subject => 'subject', :content => 'content')
43 assert_equal [:en], post.translated_locales
44 end
45
46 test 'sets the given attributes to translated_attribute_names' do
47 assert_equal [:subject, :content], Post.translated_attribute_names
48 end
49
50 test 'defines accessors for the translated attributes' do
51 post = Post.new
52 assert post.respond_to?(:subject)
53 assert post.respond_to?(:subject=)
54 end
55
56 test 'attribute reader without arguments will use the current locale on ActiveRecord::Base or I18n' do
57 post = Post.with_locale(:de) do
58 Post.create!(:subject => 'Titel', :content => 'Inhalt')
59 end
60 I18n.locale = :de
61 assert_equal 'Titel', post.subject
62
63 I18n.locale = :en
64 ActiveRecord::Base.locale = :de
65 assert_equal 'Titel', post.subject
66 end
67
68 test 'attribute reader when passed a locale will use the given locale' do
69 post = Post.with_locale(:de) do
70 Post.create!(:subject => 'Titel', :content => 'Inhalt')
71 end
72 assert_equal 'Titel', post.subject(:de)
73 end
74
75 test 'attribute reader will use the current locale on ActiveRecord::Base or I18n' do
76 post = Post.with_locale(:en) do
77 Post.create!(:subject => 'title', :content => 'content')
78 end
79 I18n.locale = :de
80 post.subject = 'Titel'
81 assert_equal 'Titel', post.subject
82
83 ActiveRecord::Base.locale = :en
84 post.subject = 'title'
85 assert_equal 'title', post.subject
86 end
87end
diff --git a/vendor/plugins/globalize2/test/active_record/translation_class_test.rb b/vendor/plugins/globalize2/test/active_record/translation_class_test.rb
deleted file mode 100644
index 1628416..0000000
--- a/vendor/plugins/globalize2/test/active_record/translation_class_test.rb
+++ /dev/null
@@ -1,30 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4class TranlationClassTest < ActiveSupport::TestCase
5 def setup
6 reset_db!
7 end
8
9 test 'defines a Translation class nested in the model class' do
10 assert Post.const_defined?(:Translation)
11 end
12
13 test 'defines a belongs_to association' do
14 assert_belongs_to Post::Translation, :post
15 end
16
17 test 'defines a reader for :locale that always returns a symbol' do
18 post = Post::Translation.new
19 post.write_attribute('locale', 'de')
20 assert_equal :de, post.locale
21 end
22
23 test 'defines a write for :locale that always writes a string' do
24 post = Post::Translation.new
25 post.locale = :de
26 assert_equal 'de', post.read_attribute('locale')
27 end
28end
29
30
diff --git a/vendor/plugins/globalize2/test/active_record/validation_tests.rb b/vendor/plugins/globalize2/test/active_record/validation_tests.rb
deleted file mode 100644
index 0148fa3..0000000
--- a/vendor/plugins/globalize2/test/active_record/validation_tests.rb
+++ /dev/null
@@ -1,75 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/../data/models')
3
4class ValidationTest < ActiveSupport::TestCase
5 def setup
6 reset_db!
7 end
8
9 def teardown
10 Validatee.instance_variable_set(:@validate_callbacks, CallbackChain.new)
11 end
12
13 test "validates_presence_of" do
14 Validatee.class_eval { validates_presence_of :string }
15 assert !Validatee.new.valid?
16 assert Validatee.new(:string => 'foo').valid?
17 end
18
19 test "validates_confirmation_of" do
20 Validatee.class_eval { validates_confirmation_of :string }
21 assert !Validatee.new(:string => 'foo', :string_confirmation => 'bar').valid?
22 assert Validatee.new(:string => 'foo', :string_confirmation => 'foo').valid?
23 end
24
25 test "validates_acceptance_of" do
26 Validatee.class_eval { validates_acceptance_of :string, :accept => '1' }
27 assert !Validatee.new(:string => '0').valid?
28 assert Validatee.new(:string => '1').valid?
29 end
30
31 test "validates_length_of (:is)" do
32 Validatee.class_eval { validates_length_of :string, :is => 1 }
33 assert !Validatee.new(:string => 'aa').valid?
34 assert Validatee.new(:string => 'a').valid?
35 end
36
37 test "validates_format_of" do
38 Validatee.class_eval { validates_format_of :string, :with => /^\d+$/ }
39 assert !Validatee.new(:string => 'a').valid?
40 assert Validatee.new(:string => '1').valid?
41 end
42
43 test "validates_inclusion_of" do
44 Validatee.class_eval { validates_inclusion_of :string, :in => %(a) }
45 assert !Validatee.new(:string => 'b').valid?
46 assert Validatee.new(:string => 'a').valid?
47 end
48
49 test "validates_exclusion_of" do
50 Validatee.class_eval { validates_exclusion_of :string, :in => %(b) }
51 assert !Validatee.new(:string => 'b').valid?
52 assert Validatee.new(:string => 'a').valid?
53 end
54
55 test "validates_numericality_of" do
56 Validatee.class_eval { validates_numericality_of :string }
57 assert !Validatee.new(:string => 'a').valid?
58 assert Validatee.new(:string => '1').valid?
59 end
60
61 # This doesn't pass and Rails' validates_uniqueness_of implementation doesn't
62 # seem to be extensible easily. One can work around that by either defining
63 # a custom validation on the Validatee model itself, or by using validates_uniqueness_of
64 # on Validatee::Translation.
65 #
66 # test "validates_uniqueness_of" do
67 # Validatee.class_eval { validates_uniqueness_of :string }
68 # Validatee.create!(:string => 'a')
69 # assert !Validatee.new(:string => 'a').valid?
70 # assert Validatee.new(:string => 'b').valid?
71 # end
72
73 # test "validates_associated" do
74 # end
75end \ No newline at end of file
diff --git a/vendor/plugins/globalize2/test/active_record_test.rb b/vendor/plugins/globalize2/test/active_record_test.rb
deleted file mode 100644
index e6b54f0..0000000
--- a/vendor/plugins/globalize2/test/active_record_test.rb
+++ /dev/null
@@ -1,442 +0,0 @@
1require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2require File.expand_path(File.dirname(__FILE__) + '/data/models')
3
4# Higher level tests.
5
6class ActiveRecordTest < ActiveSupport::TestCase
7 def setup
8 I18n.locale = :en
9 reset_db!
10 ActiveRecord::Base.locale = nil
11 end
12
13 def assert_translated(locale, record, names, expected)
14 I18n.locale = locale
15 assert_equal Array(expected), Array(names).map { |name| record.send(name) }
16 end
17
18 test "a translated record has translations" do
19 assert_equal [], Post.new.translations
20 end
21
22 test "saves a translated version of the record for each locale" do
23 post = Post.create(:subject => 'title')
24 I18n.locale = :de
25 post.update_attributes(:subject => 'Titel')
26
27 assert_equal 2, post.translations.size
28 assert_equal %w(de en), post.translations.map(&:locale).map(&:to_s).sort
29 assert_equal %w(Titel title), post.translations.map(&:subject).sort
30 end
31
32 test "a translated record has German translations" do
33 I18n.locale = :de
34 post = Post.create(:subject => 'foo')
35 assert_equal 1, post.translations.size
36 assert_equal [:de], post.translations.map { |t| t.locale }
37 end
38
39 test "modifiying translated fields while switching locales" do
40 post = Post.create(:subject => 'title', :content => 'content')
41 assert_equal %w(title content), [post.subject, post.content]
42
43 I18n.locale = :de
44 post.subject, post.content = 'Titel', 'Inhalt'
45
46 assert_translated(:de, post, [:subject, :content], %w(Titel Inhalt))
47 assert_translated(:en, post, [:subject, :content], %w(title content))
48 assert_translated(:de, post, [:subject, :content], %w(Titel Inhalt))
49
50 post.save
51 post.reload
52
53 assert_translated(:en, post, [:subject, :content], %w(title content))
54 assert_translated(:de, post, [:subject, :content], %w(Titel Inhalt))
55 end
56
57 test "attribute writers do return their argument" do
58 value = Post.new.subject = 'foo'
59 assert_equal 'foo', value
60 end
61
62 test "update_attribute succeeds with valid values" do
63 post = Post.create(:subject => 'foo', :content => 'bar')
64 post.update_attribute(:subject, 'baz')
65 assert_equal 'baz', Post.first.subject
66 end
67
68 test "update_attributes fails with invalid values" do
69 post = Post.create(:subject => 'foo', :content => 'bar')
70 assert !post.update_attributes(:subject => '')
71 assert_nil post.reload.attributes['subject']
72 assert_equal 'foo', post.subject
73 end
74
75 test "passing the locale to create uses the given locale" do
76 post = Post.create(:subject => 'Titel', :content => 'Inhalt', :locale => :de)
77 assert_equal :en, I18n.locale
78 assert_nil ActiveRecord::Base.locale
79
80 I18n.locale = :de
81 assert_equal 'Titel', post.subject
82 end
83
84 test "passing the locale to attributes= uses the given locale" do
85 post = Post.create(:subject => 'title', :content => 'content')
86 post.update_attributes(:subject => 'Titel', :content => 'Inhalt', :locale => :de)
87 post.reload
88
89 assert_equal :en, I18n.locale
90 assert_nil ActiveRecord::Base.locale
91
92 assert_equal 'title', post.subject
93 I18n.locale = :de
94 assert_equal 'Titel', post.subject
95 end
96
97 test 'reload works' do
98 post = Post.create(:subject => 'foo', :content => 'bar')
99 post.subject = 'baz'
100 post.reload
101 assert_equal 'foo', post.subject
102 end
103
104 test "returns nil if no translations are found (unsaved record)" do
105 post = Post.new(:subject => 'foo')
106 assert_equal 'foo', post.subject
107 assert_nil post.content
108 end
109
110 test "returns nil if no translations are found (saved record)" do
111 post = Post.create(:subject => 'foo')
112 post.reload
113 assert_equal 'foo', post.subject
114 assert_nil post.content
115 end
116
117 test "finds a German post" do
118 post = Post.create(:subject => 'foo (en)', :content => 'bar')
119 I18n.locale = :de
120 post = Post.first
121 post.subject = 'baz (de)'
122 post.save
123 assert_equal 'baz (de)', Post.first.subject
124 I18n.locale = :en
125 assert_equal 'foo (en)', Post.first.subject
126 end
127
128 test "saves an English post and loads correctly" do
129 post = Post.create(:subject => 'foo', :content => 'bar')
130 assert post.save
131 post = Post.first
132 assert_equal 'foo', post.subject
133 assert_equal 'bar', post.content
134 end
135
136 test "returns the value for the correct locale, after locale switching" do
137 post = Post.create(:subject => 'foo')
138 I18n.locale = :de
139 post.subject = 'bar'
140 post.save
141 I18n.locale = :en
142 post = Post.first
143 assert_equal 'foo', post.subject
144 I18n.locale = :de
145 assert_equal 'bar', post.subject
146 end
147
148 test "returns the value for the correct locale, after locale switching, without saving" do
149 post = Post.create :subject => 'foo'
150 I18n.locale = :de
151 post.subject = 'bar'
152 I18n.locale = :en
153 assert_equal 'foo', post.subject
154 I18n.locale = :de
155 assert_equal 'bar', post.subject
156 end
157
158 test "saves all locales, even after locale switching" do
159 post = Post.new :subject => 'foo'
160 I18n.locale = :de
161 post.subject = 'bar'
162 I18n.locale = :he
163 post.subject = 'baz'
164 post.save
165 I18n.locale = :en
166 post = Post.first
167 assert_equal 'foo', post.subject
168 I18n.locale = :de
169 assert_equal 'bar', post.subject
170 I18n.locale = :he
171 assert_equal 'baz', post.subject
172 end
173
174 test "works with associations" do
175 blog = Blog.create
176 post1 = blog.posts.create(:subject => 'foo')
177
178 I18n.locale = :de
179 post2 = blog.posts.create(:subject => 'bar')
180 assert_equal 2, blog.posts.size
181
182 I18n.locale = :en
183 assert_equal 'foo', blog.posts.first.subject
184 assert_nil blog.posts.last.subject
185
186 I18n.locale = :de
187 assert_equal 'bar', blog.posts.last.subject
188 end
189
190 test "works with simple dynamic finders" do
191 foo = Post.create(:subject => 'foo')
192 Post.create(:subject => 'bar')
193 post = Post.find_by_subject('foo')
194 assert_equal foo, post
195 end
196
197 test 'change attribute on globalized model' do
198 post = Post.create(:subject => 'foo', :content => 'bar')
199 assert_equal [], post.changed
200 post.subject = 'baz'
201 assert_equal ['subject'], post.changed
202 post.content = 'quux'
203 assert_member 'subject', post.changed
204 assert_member 'content', post.changed
205 end
206
207 test 'change attribute on globalized model after locale switching' do
208 post = Post.create(:subject => 'foo', :content => 'bar')
209 assert_equal [], post.changed
210 post.subject = 'baz'
211 I18n.locale = :de
212 assert_equal ['subject'], post.changed
213 end
214
215 test 'complex writing and stashing' do
216 post = Post.create(:subject => 'foo', :content => 'bar')
217 post.subject = nil
218 assert_nil post.subject
219 assert !post.valid?
220 post.subject = 'stashed_foo'
221 assert_equal 'stashed_foo', post.subject
222 end
223
224 test 'translated class locale setting' do
225 assert ActiveRecord::Base.respond_to?(:locale)
226 assert_equal :en, I18n.locale
227 assert_nil ActiveRecord::Base.locale
228
229 I18n.locale = :de
230 assert_equal :de, I18n.locale
231 assert_nil ActiveRecord::Base.locale
232
233 ActiveRecord::Base.locale = :es
234 assert_equal :de, I18n.locale
235 assert_equal :es, ActiveRecord::Base.locale
236
237 I18n.locale = :fr
238 assert_equal :fr, I18n.locale
239 assert_equal :es, ActiveRecord::Base.locale
240 end
241
242 test "untranslated class responds to locale" do
243 assert Blog.respond_to?(:locale)
244 end
245
246 test "to ensure locales in different classes are the same" do
247 ActiveRecord::Base.locale = :de
248 assert_equal :de, ActiveRecord::Base.locale
249 assert_equal :de, Parent.locale
250
251 Parent.locale = :es
252 assert_equal :es, ActiveRecord::Base.locale
253 assert_equal :es, Parent.locale
254 end
255
256 test "attribute saving goes by content locale and not global locale" do
257 ActiveRecord::Base.locale = :de
258 assert_equal :en, I18n.locale
259 Post.create :subject => 'foo'
260 assert_equal :de, Post.first.translations.first.locale
261 end
262
263 test "attribute loading goes by content locale and not global locale" do
264 post = Post.create(:subject => 'foo')
265 assert_nil ActiveRecord::Base.locale
266
267 ActiveRecord::Base.locale = :de
268 assert_equal :en, I18n.locale
269 post.update_attribute(:subject, 'foo [de]')
270 assert_equal 'foo [de]', Post.first.subject
271
272 ActiveRecord::Base.locale = :en
273 assert_equal 'foo', Post.first.subject
274 end
275
276 test "access content locale before setting" do
277 Globalize::ActiveRecord::ActMacro.class_eval "remove_class_variable(:@@locale)"
278 assert_nothing_raised { ActiveRecord::Base.locale }
279 end
280
281 test "available_locales" do
282 Post.locale = :de
283 post = Post.create(:subject => 'foo')
284 Post.locale = :es
285 post.update_attribute(:subject, 'bar')
286 Post.locale = :fr
287 post.update_attribute(:subject, 'baz')
288 assert_equal [:de, :es, :fr], post.available_locales
289 assert_equal [:de, :es, :fr], Post.first.available_locales
290 end
291
292 test "saving record correctly after post-save reload" do
293 reloader = Reloader.create(:content => 'foo')
294 assert_equal 'foo', reloader.content
295 end
296
297 test "including translations" do
298 I18n.locale = :de
299 Post.create(:subject => "Foo1", :content => "Bar1")
300 Post.create(:subject => "Foo2", :content => "Bar2")
301
302 class << Post
303 def translations_included
304 self.all(:include => :translations)
305 end
306 end
307
308 default = Post.all.map { |x| [x.subject, x.content] }
309 with_include = Post.translations_included.map { |x| [x.subject, x.content] }
310 assert_equal default, with_include
311 end
312
313 test "setting multiple translations at once with options hash" do
314 Post.locale = :de
315 post = Post.create(:subject => "foo1", :content => "foo1")
316 Post.locale = :en
317 post.update_attributes(:subject => "bar1", :content => "bar1")
318
319 options = { :de => {:subject => "foo2", :content => "foo2"},
320 :en => {:subject => "bar2", :content => "bar2"} }
321 post.set_translations options
322 post.reload
323
324 assert ["bar2", "bar2"], [post.subject, post.content]
325 Post.locale = :de
326 assert ["foo2", "foo2"], [post.subject, post.content]
327 end
328
329 test "setting only one translation with set_translations" do
330 Post.locale = :de
331 post = Post.create(:subject => "foo1", :content => "foo1")
332 Post.locale = :en
333 post.update_attributes(:subject => "bar1", :content => "bar1")
334
335 options = { :en => { :subject => "bar2", :content => "bar2" } }
336 post.set_translations options
337 post.reload
338
339 assert ["bar2", "bar2"], [post.subject, post.content]
340 Post.locale = :de
341 assert ["foo1", "foo1"], [post.subject, post.content]
342 end
343
344 test "setting only selected attributes with set_translations" do
345 Post.locale = :de
346 post = Post.create(:subject => "foo1", :content => "foo1")
347 Post.locale = :en
348 post.update_attributes(:subject => "bar1", :content => "bar1")
349
350 options = { :de => { :content => "foo2" }, :en => { :subject => "bar2" } }
351 post.set_translations options
352 post.reload
353
354 assert ["bar2", "bar1"], [post.subject, post.content]
355 Post.locale = :de
356 assert ["foo1", "foo2"], [post.subject, post.content]
357 end
358
359 test "setting invalid attributes raises ArgumentError" do
360 Post.locale = :de
361 post = Post.create(:subject => "foo1", :content => "foo1")
362 Post.locale = :en
363 post.update_attributes(:subject => "bar1", :content => "bar1")
364
365 options = { :de => {:fake => "foo2"} }
366 exception = assert_raise(ActiveRecord::UnknownAttributeError) do
367 post.set_translations options
368 end
369 assert_equal "unknown attribute: fake", exception.message
370 end
371
372 test "reload accepting find options" do
373 p = Post.create(:subject => "Foo", :content => "Bar")
374 assert p.reload(:readonly => true, :lock => true)
375 assert_raise(ArgumentError) { p.reload(:foo => :bar) }
376 end
377
378 test "dependent destroy of translation" do
379 p = Post.create(:subject => "Foo", :content => "Bar")
380 assert_equal 1, PostTranslation.count
381 p.destroy
382 assert_equal 0, PostTranslation.count
383 end
384
385 test "translating subclass of untranslated comment model" do
386 translated_comment = TranslatedComment.create(:post => @post)
387 assert_nothing_raised { translated_comment.translations }
388 end
389
390 test "modifiying translated comments works as expected" do
391 I18n.locale = :en
392 translated_comment = TranslatedComment.create(:post => @post, :content => 'foo')
393 assert_equal 'foo', translated_comment.content
394
395 I18n.locale = :de
396 translated_comment.content = 'bar'
397 assert translated_comment.save
398 assert_equal 'bar', translated_comment.content
399
400 I18n.locale = :en
401 assert_equal 'foo', translated_comment.content
402
403 assert_equal 2, translated_comment.translations.size
404 end
405
406 test "can create a proxy class for a namespaced model" do
407 assert_nothing_raised do
408 module Foo
409 module Bar
410 class Baz < ActiveRecord::Base
411 translates :bumm
412 end
413 end
414 end
415 end
416 end
417
418 test "attribute translated before type cast" do
419 Post.locale = :en
420 post = Post.create(:subject => 'foo', :content => 'bar')
421 Post.locale = :de
422 post.update_attribute(:subject, "German foo")
423 assert_equal 'German foo', post.subject_before_type_cast
424 Post.locale = :en
425 assert_equal 'foo', post.subject_before_type_cast
426 end
427
428 test "don't override existing translation class" do
429 assert PostTranslation.new.respond_to?(:existing_method)
430 end
431
432 test "has_many and named scopes work with globalize" do
433 blog = Blog.create
434 assert_nothing_raised { blog.posts.foobar }
435 end
436end
437
438# TODO error checking for fields that exist in main table, don't exist in
439# proxy table, aren't strings or text
440#
441# TODO allow finding by translated attributes in conditions?
442# TODO generate advanced dynamic finders?
diff --git a/vendor/plugins/globalize2/test/all.rb b/vendor/plugins/globalize2/test/all.rb
deleted file mode 100644
index ff467a1..0000000
--- a/vendor/plugins/globalize2/test/all.rb
+++ /dev/null
@@ -1,2 +0,0 @@
1files = Dir[File.dirname(__FILE__) + '/**/*_test.rb']
2files.each { |file| require file } \ No newline at end of file
diff --git a/vendor/plugins/globalize2/test/data/models.rb b/vendor/plugins/globalize2/test/data/models.rb
deleted file mode 100644
index 553fca3..0000000
--- a/vendor/plugins/globalize2/test/data/models.rb
+++ /dev/null
@@ -1,51 +0,0 @@
1#require 'ruby2ruby'
2#require 'parse_tree'
3#require 'parse_tree_extensions'
4#require 'pp'
5
6class PostTranslation < ActiveRecord::Base
7 def existing_method ; end
8end
9
10class Post < ActiveRecord::Base
11 translates :subject, :content
12 validates_presence_of :subject
13 named_scope :foobar, :conditions => { :title => "foobar" }
14end
15
16class Blog < ActiveRecord::Base
17 has_many :posts, :order => 'id ASC'
18end
19
20class Parent < ActiveRecord::Base
21 translates :content
22end
23
24class Child < Parent
25end
26
27class Comment < ActiveRecord::Base
28 validates_presence_of :content
29 belongs_to :post
30end
31
32class TranslatedComment < Comment
33 translates :content
34end
35
36class UltraLongModelNameWithoutProper < ActiveRecord::Base
37 translates :subject, :content
38 validates_presence_of :subject
39end
40
41class Reloader < Parent
42 after_create :do_reload
43
44 def do_reload
45 reload
46 end
47end
48
49class Validatee < ActiveRecord::Base
50 translates :string
51end
diff --git a/vendor/plugins/globalize2/test/data/no_globalize_schema.rb b/vendor/plugins/globalize2/test/data/no_globalize_schema.rb
deleted file mode 100644
index 379455d..0000000
--- a/vendor/plugins/globalize2/test/data/no_globalize_schema.rb
+++ /dev/null
@@ -1,11 +0,0 @@
1# This schema creates tables without columns for the translated fields
2ActiveRecord::Schema.define do
3 create_table :blogs, :force => true do |t|
4 t.string :name
5 end
6
7 create_table :posts, :force => true do |t|
8 t.references :blog
9 end
10end
11
diff --git a/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb b/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb
deleted file mode 100644
index 5d0ecd6..0000000
--- a/vendor/plugins/globalize2/test/i18n/missing_translations_test.rb
+++ /dev/null
@@ -1,36 +0,0 @@
1require File.dirname(__FILE__) + '/../test_helper'
2require 'i18n/missing_translations_log_handler'
3
4class MissingTranslationsTest < ActiveSupport::TestCase
5 test "defines I18n.missing_translations_logger accessor" do
6 assert I18n.respond_to?(:missing_translations_logger)
7 end
8
9 test "defines I18n.missing_translations_logger= writer" do
10 assert I18n.respond_to?(:missing_translations_logger=)
11 end
12end
13
14class TestLogger < String
15 def warn(msg) self.concat msg; end
16end
17
18class LogMissingTranslationsTest < ActiveSupport::TestCase
19 def setup
20 @locale, @key, @options = :en, :foo, {}
21 @exception = I18n::MissingTranslationData.new(@locale, @key, @options)
22
23 @logger = TestLogger.new
24 I18n.missing_translations_logger = @logger
25 end
26
27 test "still returns the exception message for MissingTranslationData exceptions" do
28 result = I18n.send(:missing_translations_log_handler, @exception, @locale, @key, @options)
29 assert_equal 'translation missing: en, foo', result
30 end
31
32 test "logs the missing translation to I18n.missing_translations_logger" do
33 I18n.send(:missing_translations_log_handler, @exception, @locale, @key, @options)
34 assert_equal 'translation missing: en, foo', @logger
35 end
36end
diff --git a/vendor/plugins/globalize2/test/test_helper.rb b/vendor/plugins/globalize2/test/test_helper.rb
deleted file mode 100644
index 195907d..0000000
--- a/vendor/plugins/globalize2/test/test_helper.rb
+++ /dev/null
@@ -1,76 +0,0 @@
1$LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
2
3require 'rubygems'
4require 'test/unit'
5require 'active_record'
6require 'active_support'
7require 'active_support/test_case'
8require 'mocha'
9require 'globalize'
10require 'validation_reflection'
11
12config = { :adapter => 'sqlite3', :database => ':memory:' }
13ActiveRecord::Base.establish_connection(config)
14
15class ActiveSupport::TestCase
16 def reset_db!(schema_path = nil)
17 schema_path ||= File.expand_path(File.dirname(__FILE__) + '/data/schema.rb')
18 ActiveRecord::Migration.verbose = false
19 ActiveRecord::Base.silence { load(schema_path) }
20 end
21
22 def assert_member(item, array)
23 assert_block "Item #{item} is not in array #{array}" do
24 array.member?(item)
25 end
26 end
27
28 def assert_belongs_to(model, associated)
29 assert model.reflect_on_all_associations(:belongs_to).detect { |association|
30 association.name.to_s == associated.to_s
31 }
32 end
33
34 def assert_has_many(model, associated)
35 assert model.reflect_on_all_associations(:has_many).detect { |association|
36 association.name.to_s == associated.to_s
37 }
38 end
39end
40
41module ActiveRecord
42 module ConnectionAdapters
43 class AbstractAdapter
44 def index_exists?(table_name, column_name)
45 indexes(table_name).any? { |index| index.name == index_name(table_name, column_name) }
46 end
47 end
48 end
49end
50
51# module ActiveRecord
52# class BaseWithoutTable < Base
53# self.abstract_class = true
54#
55# def create_or_update
56# errors.empty?
57# end
58#
59# class << self
60# def columns()
61# @columns ||= []
62# end
63#
64# def column(name, sql_type = nil, default = nil, null = true)
65# columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
66# reset_column_information
67# end
68#
69# # Do not reset @columns
70# def reset_column_information
71# read_methods.each { |name| undef_method(name) }
72# @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @read_methods = nil
73# end
74# end
75# end
76# end \ No newline at end of file