test/cases/translatable_test.rb in translatable-0.3.0 vs test/cases/translatable_test.rb in translatable-0.3.1
- old
+ new
@@ -3,10 +3,14 @@
require 'support/models/news'
require 'support/models/posts'
require 'support/models/messages'
class TranslatableTest < Test::Unit::TestCase
+ teardown do
+ ::I18n.locale = ::I18n.default_locale
+ end
+
context "Translatable hash" do
should "Define default" do
th = News.instance_variable_get :@translatable
assert_kind_of Hash, th
@@ -52,13 +56,14 @@
assert news.persisted?
t_news = TranslatableNews.last
assert_equal [t_news], news.other_translations
- ::I18n.locale = :ru
+
+ news.set_current_translation :ru
+
assert_equal [], news.other_translations
- ::I18n.locale = ::I18n.default_locale
end
should "Provide errors on creation" do
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
{:title => "Resent News", :content => "That is where the text goes", :locale => ""}]
@@ -152,27 +157,27 @@
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
assert news.persisted?
::I18n.locale = :ru
+
assert_equal "Заголовок", news.title
assert_equal "Содержание", news.content
- ::I18n.locale = ::I18n.default_locale
end
should "Not been set if unavailable" do
news = News.create :translations_attributes => [{:title => "Заголовок", :content => "Содержание", :locale => "ru"},
{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
assert news.persisted?
+ news.set_current_translation :de
- ::I18n.locale = :de
assert_nil news.title
assert_nil news.content
end
- should "Be be switched on locale switching" do
+ should "Be switched on locale switching" do
news = News.create :translations_attributes => [{:title => "Resent News", :content => "That is where the text goes", :locale => "en"}]
assert news.persisted?
t_news = news.translations.create :title => "Заголовок", :content => "Содержание",:locale => "ru"
@@ -181,11 +186,11 @@
::I18n.locale = ::I18n.default_locale
assert_equal "Resent News", news.title
assert_equal "That is where the text goes", news.content
- ::I18n.locale = :ru
+ news.set_current_translation :ru
assert_equal "Заголовок", news.title
assert_equal "Содержание", news.content
end
end
@@ -238,12 +243,12 @@
{:title => "Resent Post", :content => "That is where the text goes", :locale => "en"}]
assert post.persisted?, "Message had errors: #{post.errors.inspect}"
assert_equal "Resent Post", post.translated_title
- ::I18n.locale = :ru
+ post.set_current_translation :ru
+
assert_equal "Заголовок", post.translated_title
- ::I18n.locale = ::I18n.default_locale
end
context "Mass assigment" do
should "Be available to mass assigment by default" do
tp = TranslatableNews.new( :title => "Resent News", :content => "That is where the text goes", :locale => "en", :origin_id => 1)