diff options
| author | hukl <contact@smyck.org> | 2009-02-25 22:37:22 +0100 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-02-25 22:37:22 +0100 |
| commit | f4c73763e5b3d65f3377fb1238a94122a1c272a4 (patch) | |
| tree | 8f6b276f9432e31ae0fe7bffe010e680081a1e0a /vendor/plugins/globalize2/test/model | |
| parent | 19b07ff63c626f76ad512b95ddbf16cddd2bf855 (diff) | |
updated globalize2
Diffstat (limited to 'vendor/plugins/globalize2/test/model')
3 files changed, 160 insertions, 2 deletions
diff --git a/vendor/plugins/globalize2/test/model/active_record/migration_test.rb b/vendor/plugins/globalize2/test/model/active_record/migration_test.rb index 09804c7d..c539fb6e 100644 --- a/vendor/plugins/globalize2/test/model/active_record/migration_test.rb +++ b/vendor/plugins/globalize2/test/model/active_record/migration_test.rb | |||
| @@ -10,7 +10,7 @@ require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' ) | |||
| 10 | 10 | ||
| 11 | class MigrationTest < ActiveSupport::TestCase | 11 | class MigrationTest < ActiveSupport::TestCase |
| 12 | def setup | 12 | def setup |
| 13 | reset_db! 'no_globalize_schema' | 13 | reset_db! File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'no_globalize_schema.rb')) |
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | test 'globalize table added' do | 16 | test 'globalize table added' do |
diff --git a/vendor/plugins/globalize2/test/model/active_record/sti_translated_test.rb b/vendor/plugins/globalize2/test/model/active_record/sti_translated_test.rb new file mode 100644 index 00000000..14d7d0f9 --- /dev/null +++ b/vendor/plugins/globalize2/test/model/active_record/sti_translated_test.rb | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | require File.join( File.dirname(__FILE__), '..', '..', 'test_helper' ) | ||
| 2 | require 'active_record' | ||
| 3 | require 'globalize/model/active_record' | ||
| 4 | |||
| 5 | # Hook up model translation | ||
| 6 | ActiveRecord::Base.send(:include, Globalize::Model::ActiveRecord::Translated) | ||
| 7 | |||
| 8 | # Load Post model | ||
| 9 | require File.join( File.dirname(__FILE__), '..', '..', 'data', 'post' ) | ||
| 10 | |||
| 11 | class StiTranslatedTest < ActiveSupport::TestCase | ||
| 12 | def setup | ||
| 13 | I18n.locale = :'en-US' | ||
| 14 | I18n.fallbacks.clear | ||
| 15 | reset_db! File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'schema.rb')) | ||
| 16 | end | ||
| 17 | |||
| 18 | def teardown | ||
| 19 | I18n.fallbacks.clear | ||
| 20 | end | ||
| 21 | |||
| 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 | ||
| 27 | end | ||
| 28 | |||
| 29 | test 'change attribute on globalized model' do | ||
| 30 | child = Child.create :content => 'foo' | ||
| 31 | assert_equal [], child.changed | ||
| 32 | child.content = 'bar' | ||
| 33 | assert_equal [ 'content' ], child.changed | ||
| 34 | child.content = 'baz' | ||
| 35 | assert_member 'content', child.changed | ||
| 36 | end | ||
| 37 | |||
| 38 | test 'change attribute on globalized model after locale switching' do | ||
| 39 | child = Child.create :content => 'foo' | ||
| 40 | assert_equal [], child.changed | ||
| 41 | child.content = 'bar' | ||
| 42 | I18n.locale = :de | ||
| 43 | assert_equal [ 'content' ], child.changed | ||
| 44 | end | ||
| 45 | |||
| 46 | test 'fallbacks with lots of locale switching' do | ||
| 47 | I18n.fallbacks.map :'de-DE' => [ :'en-US' ] | ||
| 48 | child = Child.create :content => 'foo' | ||
| 49 | |||
| 50 | I18n.locale = :'de-DE' | ||
| 51 | assert_equal 'foo', child.content | ||
| 52 | |||
| 53 | I18n.locale = :'en-US' | ||
| 54 | child.update_attribute :content, 'bar' | ||
| 55 | |||
| 56 | I18n.locale = :'de-DE' | ||
| 57 | assert_equal 'bar', child.content | ||
| 58 | end | ||
| 59 | |||
| 60 | test "saves all locales, even after locale switching" do | ||
| 61 | child = Child.new :content => 'foo' | ||
| 62 | I18n.locale = 'de-DE' | ||
| 63 | child.content = 'bar' | ||
| 64 | I18n.locale = 'he-IL' | ||
| 65 | child.content = 'baz' | ||
| 66 | child.save | ||
| 67 | I18n.locale = 'en-US' | ||
| 68 | child = Child.first | ||
| 69 | assert_equal 'foo', child.content | ||
| 70 | I18n.locale = 'de-DE' | ||
| 71 | assert_equal 'bar', child.content | ||
| 72 | I18n.locale = 'he-IL' | ||
| 73 | assert_equal 'baz', child.content | ||
| 74 | end | ||
| 75 | end \ No newline at end of file | ||
diff --git a/vendor/plugins/globalize2/test/model/active_record/translated_test.rb b/vendor/plugins/globalize2/test/model/active_record/translated_test.rb index ec507e03..6bb7b26a 100644 --- a/vendor/plugins/globalize2/test/model/active_record/translated_test.rb +++ b/vendor/plugins/globalize2/test/model/active_record/translated_test.rb | |||
| @@ -12,7 +12,8 @@ class TranslatedTest < ActiveSupport::TestCase | |||
| 12 | def setup | 12 | def setup |
| 13 | I18n.locale = :'en-US' | 13 | I18n.locale = :'en-US' |
| 14 | I18n.fallbacks.clear | 14 | I18n.fallbacks.clear |
| 15 | reset_db! | 15 | reset_db! File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'data', 'schema.rb')) |
| 16 | ActiveRecord::Base.locale = nil | ||
| 16 | end | 17 | end |
| 17 | 18 | ||
| 18 | def teardown | 19 | def teardown |
| @@ -92,6 +93,13 @@ class TranslatedTest < ActiveSupport::TestCase | |||
| 92 | assert_equal 'baz', Post.first.subject | 93 | assert_equal 'baz', Post.first.subject |
| 93 | end | 94 | end |
| 94 | 95 | ||
| 96 | test "update_attributes failure" do | ||
| 97 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 98 | assert !post.update_attributes( { :subject => '' } ) | ||
| 99 | assert_nil post.reload.attributes['subject'] | ||
| 100 | assert_equal 'foo', post.subject | ||
| 101 | end | ||
| 102 | |||
| 95 | test "validates presence of :subject" do | 103 | test "validates presence of :subject" do |
| 96 | post = Post.new | 104 | post = Post.new |
| 97 | assert !post.save | 105 | assert !post.save |
| @@ -255,6 +263,81 @@ class TranslatedTest < ActiveSupport::TestCase | |||
| 255 | I18n.locale = :'de-DE' | 263 | I18n.locale = :'de-DE' |
| 256 | assert_equal 'bar', post.subject | 264 | assert_equal 'bar', post.subject |
| 257 | end | 265 | end |
| 266 | |||
| 267 | test 'reload' do | ||
| 268 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 269 | post.subject = 'baz' | ||
| 270 | assert_equal 'foo', post.reload.subject | ||
| 271 | end | ||
| 272 | |||
| 273 | test 'complex writing and stashing' do | ||
| 274 | post = Post.create :subject => 'foo', :content => 'bar' | ||
| 275 | post.subject = nil | ||
| 276 | assert_nil post.subject | ||
| 277 | assert !post.valid? | ||
| 278 | end | ||
| 279 | |||
| 280 | test 'translated class locale setting' do | ||
| 281 | assert ActiveRecord::Base.respond_to?(:locale) | ||
| 282 | assert_equal :'en-US', I18n.locale | ||
| 283 | assert_equal :'en-US', ActiveRecord::Base.locale | ||
| 284 | I18n.locale = :de | ||
| 285 | assert_equal :de, I18n.locale | ||
| 286 | assert_equal :de, ActiveRecord::Base.locale | ||
| 287 | ActiveRecord::Base.locale = :es | ||
| 288 | assert_equal :de, I18n.locale | ||
| 289 | assert_equal :es, ActiveRecord::Base.locale | ||
| 290 | I18n.locale = :fr | ||
| 291 | assert_equal :fr, I18n.locale | ||
| 292 | assert_equal :es, ActiveRecord::Base.locale | ||
| 293 | end | ||
| 294 | |||
| 295 | test "untranslated class responds to locale" do | ||
| 296 | assert Blog.respond_to?(:locale) | ||
| 297 | end | ||
| 298 | |||
| 299 | test "to ensure locales in different classes are the same" do | ||
| 300 | ActiveRecord::Base.locale = :de | ||
| 301 | assert_equal :de, ActiveRecord::Base.locale | ||
| 302 | assert_equal :de, Parent.locale | ||
| 303 | Parent.locale = :es | ||
| 304 | assert_equal :es, ActiveRecord::Base.locale | ||
| 305 | assert_equal :es, Parent.locale | ||
| 306 | end | ||
| 307 | |||
| 308 | test "attribute saving goes by content locale and not global locale" do | ||
| 309 | ActiveRecord::Base.locale = :de | ||
| 310 | assert_equal :'en-US', I18n.locale | ||
| 311 | Post.create :subject => 'foo' | ||
| 312 | assert_equal :de, Post.first.globalize_translations.first.locale | ||
| 313 | end | ||
| 314 | |||
| 315 | test "attribute loading goes by content locale and not global locale" do | ||
| 316 | post = Post.create :subject => 'foo' | ||
| 317 | assert_equal :'en-US', ActiveRecord::Base.locale | ||
| 318 | ActiveRecord::Base.locale = :de | ||
| 319 | assert_equal :'en-US', I18n.locale | ||
| 320 | post.update_attribute :subject, 'foo [de]' | ||
| 321 | assert_equal 'foo [de]', Post.first.subject | ||
| 322 | ActiveRecord::Base.locale = :'en-US' | ||
| 323 | assert_equal 'foo', Post.first.subject | ||
| 324 | end | ||
| 325 | |||
| 326 | test "access content locale before setting" do | ||
| 327 | Globalize::Model::ActiveRecord::Translated::ActMethods.class_eval "remove_class_variable(:@@locale)" | ||
| 328 | assert_nothing_raised { ActiveRecord::Base.locale } | ||
| 329 | end | ||
| 330 | |||
| 331 | test "translated_locales" do | ||
| 332 | Post.locale = :de | ||
| 333 | post = Post.create :subject => 'foo' | ||
| 334 | Post.locale = :es | ||
| 335 | post.update_attribute :subject, 'bar' | ||
| 336 | Post.locale = :fr | ||
| 337 | post.update_attribute :subject, 'baz' | ||
| 338 | assert_equal [ :de, :es, :fr ], post.translated_locales | ||
| 339 | assert_equal [ :de, :es, :fr ], Post.first.translated_locales | ||
| 340 | end | ||
| 258 | end | 341 | end |
| 259 | 342 | ||
| 260 | # TODO should validate_presence_of take fallbacks into account? maybe we need | 343 | # TODO should validate_presence_of take fallbacks into account? maybe we need |
