From b04cf70f6edbaf9d7ac943c2fe84615ca82b0120 Mon Sep 17 00:00:00 2001 From: Tys von Gaza Date: Thu, 26 Feb 2009 14:05:28 -0700 Subject: [PATCH] added tests to catch nested conditions bug --- activerecord/test/cases/finder_test.rb | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb index ee8f490..c58a855 100644 --- a/activerecord/test/cases/finder_test.rb +++ b/activerecord/test/cases/finder_test.rb @@ -283,6 +283,19 @@ class FinderTest < ActiveRecord::TestCase assert_equal 1, firms.size assert_equal companies(:first_firm), firms.first end + + def test_find_with_hash_conditions_with_nesting_and_no_joined_table + # should throw an exception as we have no column named "posts_authors".title in our query + assert_raises(ActiveRecord::StatementInvalid) { + posts = Post.all(:conditions => { :author => { :posts => { :title => "Welcome to the weblog" } } }) + } + end + + def test_find_with_hash_conditions_with_nesting_and_joined_table + # all our records should not be the same, conditions should filter on "posts_authors".title not "posts".title + posts = Post.all(:joins => { :author => :posts }, :conditions => { :author => { :posts => { :title => "Welcome to the weblog" } } }) + assert_not_equal 1, posts.uniq.size + end def test_find_with_hash_conditions_on_joined_table_and_with_range firms = DependentFirm.all :joins => :account, :conditions => {:name => 'RailsCore', :accounts => { :credit_limit => 55..60 }} -- 1.6.1