aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-06-01 01:43:20 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-06-01 01:43:20 +0000
commitb09d02c9e8523857aa290d0824e1c22a714604ac (patch)
tree326f2841bfcced993561d2b9b0e692f929bea142 /activerecord/test
parent9fcc0654c37772a3d6884c5d6f7099a39fe88f73 (diff)
downloadrails-b09d02c9e8523857aa290d0824e1c22a714604ac.tar.gz
rails-b09d02c9e8523857aa290d0824e1c22a714604ac.tar.bz2
rails-b09d02c9e8523857aa290d0824e1c22a714604ac.zip
Records and arrays of records are bound as quoted ids.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4391 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/finder_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index f23e383115..e04d02d9cb 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -186,10 +186,25 @@ class FinderTest < Test::Unit::TestCase
assert_equal %('a','b','c'), bind(':a', :a => Set.new(%w(a b c))) # '
end
+ def test_bind_empty_enumerable
+ quoted_nil = ActiveRecord::Base.connection.quote(nil)
+ assert_equal quoted_nil, bind('?', [])
+ assert_equal " in (#{quoted_nil})", bind(' in (?)', [])
+ assert_equal "foo in (#{quoted_nil})", bind('foo in (?)', [])
+ end
+
def test_bind_string
assert_equal "''", bind('?', '')
end
+ def test_bind_record
+ o = Struct.new(:quoted_id).new(1)
+ assert_equal '1', bind('?', o)
+
+ os = [o] * 3
+ assert_equal '1,1,1', bind('?', os)
+ end
+
def test_string_sanitation
assert_not_equal "'something ' 1=1'", ActiveRecord::Base.sanitize("something ' 1=1")
assert_equal "'something; select table'", ActiveRecord::Base.sanitize("something; select table")
@@ -363,6 +378,24 @@ class FinderTest < Test::Unit::TestCase
end
end
+ def test_find_by_empty_ids
+ assert_equal [], Post.find([])
+ end
+
+ def test_find_by_empty_in_condition
+ assert_equal [], Post.find(:all, :conditions => ['id in (?)', []])
+ end
+
+ def test_find_by_records
+ p1, p2 = Post.find(1, 2)
+ assert_equal [p1, p2], Post.find(:all, :conditions => ['id in (?)', [p1, p2]]).sort_by { |p| p.id }
+ end
+
+ def test_find_by_records_and_ids
+ p1, p2 = Post.find(1, 2)
+ assert_equal [p1, p2], Post.find(:all, :conditions => ['id in (?)', [p1, p2.id]]).sort_by { |p| p.id }
+ end
+
def test_select_value
assert_equal "37signals", Company.connection.select_value("SELECT name FROM companies WHERE id = 1")
assert_nil Company.connection.select_value("SELECT name FROM companies WHERE id = -1")