test/armot_test.rb in armot-0.2.0 vs test/armot_test.rb in armot-0.2.1

- old
+ new

@@ -98,10 +98,20 @@ 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" @@ -129,10 +139,31 @@ foo = Post.find_by_title "Catalan title" assert_equal nil, foo end + test "should return nil when finding for an existant value but incompatible with the current scope" do + post = Post.first + I18n.locale = :ca + post.title = "Catalan title" + post.save! + + foo = Post.where("title != 'Catalan title'").find_by_title "Catalan title" + assert_equal nil, foo + end + + test "should raise a RecordNotFound error when finding for an existant value but incompatible with the current scope with bang!" do + post = Post.first + I18n.locale = :ca + post.title = "Catalan title" + post.save! + + assert_raise(ActiveRecord::RecordNotFound) do + Post.where("title != 'Catalan title'").find_by_title! "Catalan title" + end + end + test "should raise exception with bang version" do assert_raise(ActiveRecord::RecordNotFound) do Post.find_by_title! "Non existant" end end @@ -170,7 +201,20 @@ I18n::Backend::ActiveRecord::Translation.delete_all assert_raise(ActiveRecord::RecordNotFound) do Post.find_by_title! "Non existant" end + end + + test "_changed? method should work as expected" do + post = Post.first + post.title = "Other title" + + assert_equal true, post.title_changed? + + post.save! + assert_equal false, post.title_changed? + + post.title = "Another change" + assert_equal true, post.title_changed? end end