diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 22:15:06 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 22:15:06 +0000 |
commit | c5ec16e5833a4284a5ef07c7b09306df01e964f2 (patch) | |
tree | a66fbdb06fa06171d43c537f4494660816ad4fac /activerecord/test | |
parent | cb62f06dcf11f440d917cd4862c0786a213a5252 (diff) | |
download | rails-c5ec16e5833a4284a5ef07c7b09306df01e964f2.tar.gz rails-c5ec16e5833a4284a5ef07c7b09306df01e964f2.tar.bz2 rails-c5ec16e5833a4284a5ef07c7b09306df01e964f2.zip |
Added simple hash conditions to find that'll just convert hash to an AND-based condition string (closes #5143) [hcatlin@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4425 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/finder_test.rb | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 1cd16c7cd8..20898237d1 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -117,17 +117,46 @@ class FinderTest < Test::Unit::TestCase assert topic.respond_to?("author_name") end - def test_find_on_conditions + def test_find_on_array_conditions assert Topic.find(1, :conditions => ["approved = ?", false]) assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => ["approved = ?", true]) } end - def test_condition_interpolation + def test_find_on_hash_conditions + assert Topic.find(1, :conditions => { :approved => false }) + assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :approved => true }) } + end + + def test_find_on_multiple_hash_conditions + assert Topic.find(1, :conditions => { :author_name => "David", :title => "The First Topic", :replies_count => 1, :approved => false }) + assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :author_name => "David", :title => "The First Topic", :replies_count => 1, :approved => true }) } + assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :author_name => "David", :title => "HHC", :replies_count => 1, :approved => false }) } + assert_raises(ActiveRecord::RecordNotFound) { Topic.find(1, :conditions => { :author_name => "David", :title => "The First Topic", :replies_count => 1, :approved => true }) } + end + + def test_condition_array_interpolation assert_kind_of Firm, Company.find(:first, :conditions => ["name = '%s'", "37signals"]) assert_nil Company.find(:first, :conditions => ["name = '%s'", "37signals!"]) assert_nil Company.find(:first, :conditions => ["name = '%s'", "37signals!' OR 1=1"]) assert_kind_of Time, Topic.find(:first, :conditions => ["id = %d", 1]).written_on end + + def test_condition_hash_interpolation + assert_kind_of Firm, Company.find(:first, :conditions => { :name => "37signals"}) + assert_nil Company.find(:first, :conditions => { :name => "37signals!"}) + assert_kind_of Time, Topic.find(:first, :conditions => {:id => 1}).written_on + end + + def test_hash_condition_find_malformed + assert_raises(ActiveRecord::StatementInvalid) { + Company.find(:first, :conditions => { :id => 2, :dhh => true }) + } + end + + def test_hash_condition_find_with_escaped_characters + Company.create("name" => "Ain't noth'n like' \#stuff") + assert Company.find(:first, :conditions => { :name => "Ain't noth'n like' \#stuff"}) + end def test_bind_variables assert_kind_of Firm, Company.find(:first, :conditions => ["name = ?", "37signals"]) |