Permalink
Browse files

Failing test for ticket #33 - mixing translated and untranslated attr…

…ibutes
  • Loading branch information...
1 parent 92217da commit 22c2d748331f2f0b79cc9d979991452059c20380 Robert Pankowecki (Gavdi) committed Mar 4, 2011
Showing with 39 additions and 3 deletions.
  1. +39 −3 test/globalize3/dynamic_finders_test.rb
View
42 test/globalize3/dynamic_finders_test.rb
@@ -4,10 +4,8 @@
class DynamicFindersTest < Test::Unit::TestCase
- Rpa = "rpa@gavdi.com"
-
test "Does not break normal finders" do
- user = User.create!(:name => "name", :email => Rpa)
+ user = User.create!(:name => "name", :email => "email@example.org")
assert_equal user, User.find_by_email(user.email)
assert_equal [user], User.find_all_by_email([user.email])
@@ -120,4 +118,42 @@ def setup
assert_equal [], Post.find_all_by_content_and_title(@content, ["not existing"])
end
+end
+
+class TranslatedAndNormalAttributeDynamicFindersTest < Test::Unit::TestCase
+
+ def setup
+ @name1, @name2, @email = "n1", "n2", "email@example.org"
+ @p1 = User.create!(:name => @name1, :email => @email)
+ @p2 = User.create!(:name => @name2, :email => @email)
+ end
+
+ test "find one element by two translation columns" do
+ assert_equal @p1, User.find_by_name_and_email(@name1, @email)
+ assert_equal @p2, User.find_by_email_and_name(@email, @name2)
+ end
+
+ test "return nil for none existing values" do
+ assert_nil User.find_by_email_and_name(@email, "not exisiting")
+ assert_nil User.find_by_email_and_name("not existing", @name2)
+
+ assert_nil User.find_by_name_and_email("not exisiting", @email)
+ assert_nil User.find_by_name_and_email(@name2, "not existing")
+ end
+
+ test "find elements by two translation columns" do
+ two_results = User.find_all_by_name_and_email([@name1, @name2], @email)
+ assert two_results.include?(@p1)
+ assert two_results.include?(@p2)
+ assert_equal @p2, User.find_all_by_email_and_name(@email, @name2)
+ end
+
+ test "returns empty result set for none existing values" do
+ assert_equal [], User.find_all_by_name_and_email([@name1, @name2], "not existing")
+ assert_equal [], User.find_all_by_name_and_email("not existing", @email)
+
+ assert_equal [], User.find_all_by_email_and_name(["not existing"], @name1)
+ assert_equal [], User.find_all_by_email_and_name(@email, ["not existing"])
+ end
+
end

0 comments on commit 22c2d74

Please sign in to comment.