test/armot_test.rb in armot-0.3.0 vs test/armot_test.rb in armot-0.3.1
- old
+ new
@@ -11,10 +11,11 @@
class ArmotTest < ActiveSupport::TestCase
def setup
setup_db
I18n.locale = I18n.default_locale = :en
+ I18n.fallbacks.clear
Post.create(:title => 'English title')
end
def teardown
teardown_db
@@ -107,20 +108,10 @@
I18n::Backend::ActiveRecord::Translation.delete_all
assert_equal "original title", Post.first.title
end
- test "should look for translations in other languages before fail" do
- post = Post.first
- I18n::Backend::ActiveRecord::Translation.delete_all
- I18n.locale = :ca
- post.title = "Catalan title"
- post.save!
- I18n.locale = :it
- assert_equal "Catalan title", post.title
- end
-
test "should find by translated title in database as a translation" do
post = Post.first
I18n.locale = :ca
post.title = "Catalan title"
@@ -303,7 +294,36 @@
a.reload
I18n.locale = :ca
res = Product.find_by_name("Catalan foo customized")
assert_equal "Catalan foo customized_override", res
+ end
+
+ test "should respect I18n standard fallback system" do
+ I18n.fallbacks.map :es => :ca
+ post = Post.first
+ I18n.locale = :ca
+ post.title = "Bola de drac"
+ I18n.locale = :en
+ post.title = "Dragon ball"
+ I18n.locale = :es
+ post.save!
+ assert_equal "Bola de drac", post.title
+ end
+
+ test "should return the fallback even if not saved" do
+ I18n.fallbacks.map :es => :ca
+ post = Post.first
+ I18n.locale = :ca
+ post.title = "Bola de drac"
+ I18n.locale = :en
+ post.title = "Dragon ball"
+ I18n.locale = :es
+ assert_equal "Bola de drac", post.title
+ end
+
+ test "should return db-column values even if not persisted" do
+ post = Post.new
+ post[:title] = "Hello world"
+ assert_equal "Hello world", post.title
end
end