summaryrefslogtreecommitdiff
path: root/vendor/plugins/globalize2/test
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-07-19 19:02:31 +0200
committerhukl <contact@smyck.org>2009-07-19 19:02:31 +0200
commit7c9f0d0823bdce9a011d3bdd2823e15ffb7c1311 (patch)
treeb82854becc5437517180aa6406a0baebdad7e71b /vendor/plugins/globalize2/test
parent0d8879354fbd251e4509a0ab5c6b6e47aa3fa47d (diff)
updated globalize2 plugin
Diffstat (limited to 'vendor/plugins/globalize2/test')
-rw-r--r--vendor/plugins/globalize2/test/backends/chained_test.rb1
-rw-r--r--vendor/plugins/globalize2/test/data/post.rb9
-rw-r--r--vendor/plugins/globalize2/test/model/active_record/translated_test.rb109
3 files changed, 119 insertions, 0 deletions
diff --git a/vendor/plugins/globalize2/test/backends/chained_test.rb b/vendor/plugins/globalize2/test/backends/chained_test.rb
index bc45179..bb0b3e0 100644
--- a/vendor/plugins/globalize2/test/backends/chained_test.rb
+++ b/vendor/plugins/globalize2/test/backends/chained_test.rb
@@ -58,6 +58,7 @@ end
58 58
59class TranslateChainedTest < ActiveSupport::TestCase 59class TranslateChainedTest < ActiveSupport::TestCase
60 def setup 60 def setup
61 I18n.locale = :en
61 I18n.backend = Globalize::Backend::Chain.new 62 I18n.backend = Globalize::Backend::Chain.new
62 @first_backend = I18n::Backend::Simple.new 63 @first_backend = I18n::Backend::Simple.new
63 @last_backend = I18n::Backend::Simple.new 64 @last_backend = I18n::Backend::Simple.new
diff --git a/vendor/plugins/globalize2/test/data/post.rb b/vendor/plugins/globalize2/test/data/post.rb
index fdfb7c0..6673dc4 100644
--- a/vendor/plugins/globalize2/test/data/post.rb
+++ b/vendor/plugins/globalize2/test/data/post.rb
@@ -12,4 +12,13 @@ class Parent < ActiveRecord::Base
12end 12end
13 13
14class Child < Parent 14class Child < Parent
15end
16
17class Comment < ActiveRecord::Base
18 validates_presence_of :content
19 belongs_to :post
20end
21
22class TranslatedComment < Comment
23 translates :content
15end \ No newline at end of file 24end \ 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 6bb7b26..3e9ea00 100644
--- a/vendor/plugins/globalize2/test/model/active_record/translated_test.rb
+++ b/vendor/plugins/globalize2/test/model/active_record/translated_test.rb
@@ -338,6 +338,115 @@ class TranslatedTest < ActiveSupport::TestCase
338 assert_equal [ :de, :es, :fr ], post.translated_locales 338 assert_equal [ :de, :es, :fr ], post.translated_locales
339 assert_equal [ :de, :es, :fr ], Post.first.translated_locales 339 assert_equal [ :de, :es, :fr ], Post.first.translated_locales
340 end 340 end
341
342 test "including globalize_translations" do
343 I18n.locale = :de
344 Post.create :subject => "Foo1", :content => "Bar1"
345 Post.create :subject => "Foo2", :content => "Bar2"
346
347 class << Post
348 def tranlsations_included
349 self.all(:include => :globalize_translations)
350 end
351 end
352
353 default = Post.all.map {|x| [x.subject, x.content]}
354 with_include = Post.tranlsations_included.map {|x| [x.subject, x.content]}
355 assert_equal default, with_include
356 end
357
358 test "setting multiple translations at once with options hash" do
359 Post.locale = :de
360 post = Post.create :subject => "foo1", :content => "foo1"
361 Post.locale = :en
362 post.update_attributes( :subject => "bar1", :content => "bar1" )
363
364 options = { :de => {:subject => "foo2", :content => "foo2"},
365 :en => {:subject => "bar2", :content => "bar2"} }
366 post.set_translations options
367 post.reload
368
369 assert ["bar2", "bar2"], [post.subject, post.content]
370 Post.locale = :de
371 assert ["foo2", "foo2"], [post.subject, post.content]
372 end
373
374 test "setting only one translation with set_translations" do
375 Post.locale = :de
376 post = Post.create :subject => "foo1", :content => "foo1"
377 Post.locale = :en
378 post.update_attributes( :subject => "bar1", :content => "bar1" )
379
380 options = { :en => {:subject => "bar2", :content => "bar2"} }
381 post.set_translations options
382 post.reload
383
384 assert ["bar2", "bar2"], [post.subject, post.content]
385 Post.locale = :de
386 assert ["foo1", "foo1"], [post.subject, post.content]
387 end
388
389 test "setting only selected attributes with set_translations" do
390 Post.locale = :de
391 post = Post.create :subject => "foo1", :content => "foo1"
392 Post.locale = :en
393 post.update_attributes( :subject => "bar1", :content => "bar1" )
394
395 options = { :de => {:content => "foo2"}, :en => {:subject => "bar2"} }
396 post.set_translations options
397 post.reload
398
399 assert ["bar2", "bar1"], [post.subject, post.content]
400 Post.locale = :de
401 assert ["foo1", "foo2"], [post.subject, post.content]
402 end
403
404 test "setting invalid attributes raises ArgumentError" do
405 Post.locale = :de
406 post = Post.create :subject => "foo1", :content => "foo1"
407 Post.locale = :en
408 post.update_attributes( :subject => "bar1", :content => "bar1" )
409
410 options = { :de => {:fake => "foo2"} }
411 exception = assert_raise(ActiveRecord::UnknownAttributeError) do
412 post.set_translations options
413 end
414 assert_equal "unknown attribute: fake", exception.message
415 end
416
417 test "reload accepting find options" do
418 p = Post.create :subject => "Foo", :content => "Bar"
419 assert p.reload(:readonly => true, :lock => true)
420 assert_raise(ArgumentError) { p.reload(:foo => :bar) }
421 end
422
423 test "dependent destroy of translation" do
424 p = Post.create :subject => "Foo", :content => "Bar"
425 assert_equal 1, PostTranslation.count
426 p.destroy
427 assert_equal 0, PostTranslation.count
428 end
429
430 test "translating subclass of untranslated comment model" do
431 translated_comment = TranslatedComment.create(:post => @post)
432 assert_nothing_raised { translated_comment.globalize_translations }
433 end
434
435 test "modifiying translated comments works as expected" do
436 I18n.locale = :en
437 translated_comment = TranslatedComment.create(:post => @post, :content => 'foo')
438 assert_equal 'foo', translated_comment.content
439
440 I18n.locale = :de
441 translated_comment.content = 'bar'
442 assert translated_comment.save
443 assert_equal 'bar', translated_comment.content
444
445 I18n.locale = :en
446 assert_equal 'foo', translated_comment.content
447
448 assert_equal 2, translated_comment.globalize_translations.size
449 end
341end 450end
342 451
343# TODO should validate_presence_of take fallbacks into account? maybe we need 452# TODO should validate_presence_of take fallbacks into account? maybe we need