aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/finder_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-24 19:50:57 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-24 19:50:57 +0000
commitcaaf40d5358ae8a2b31949c2af2d94be1be73976 (patch)
tree4a7d7cb629b8e730e0f2981fea60458eedcf9992 /activerecord/test/finder_test.rb
parent66820a4aa70889a02f48eb860727daa31639aab3 (diff)
downloadrails-caaf40d5358ae8a2b31949c2af2d94be1be73976.tar.gz
rails-caaf40d5358ae8a2b31949c2af2d94be1be73976.tar.bz2
rails-caaf40d5358ae8a2b31949c2af2d94be1be73976.zip
Added AbstractAdapter#select_value and AbstractAdapter#select_values as convenience methods for selecting single values, instead of hashes, of the first column in a SELECT #2283
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2323 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/finder_test.rb')
-rw-r--r--activerecord/test/finder_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index 2f23503ce1..8fc89f3808 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -311,6 +311,19 @@ class FinderTest < Test::Unit::TestCase
assert developer_names.include?('Jamis')
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")
+ # make sure we didn't break count...
+ assert_equal 0, Company.count_by_sql("SELECT COUNT(*) FROM companies WHERE name = 'Halliburton'")
+ assert_equal 1, Company.count_by_sql("SELECT COUNT(*) FROM companies WHERE name = '37signals'")
+ end
+
+ def test_select_values
+ assert_equal ["1","2","3"], Company.connection.select_values("SELECT id FROM companies ORDER BY id LIMIT 3")
+ assert_equal ["37signals","Summit","Microsoft"], Company.connection.select_values("SELECT name FROM companies ORDER BY id LIMIT 3")
+ end
+
protected
def bind(statement, *vars)
if vars.first.is_a?(Hash)