aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/finder_test.rb9
3 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 107d1cb698..6391dda560 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Allow any Enumerable, not just Array, to work as bind variables #1344 [bitsweat]
+
* Added actual database-changing behavior to collection assigment for has_many and has_and_belongs_to_many #1425 [Sebastian Kanthak].
Example:
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 9782b6cd04..08f749d3c8 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -896,7 +896,7 @@ module ActiveRecord #:nodoc:
def quote_bound_value(value)
case value
- when Array
+ when Enumerable
value.map { |v| connection.quote(v) }.join(',')
else
connection.quote(value)
diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb
index 7a2a0ab0a1..bec7a2dcc0 100644
--- a/activerecord/test/finder_test.rb
+++ b/activerecord/test/finder_test.rb
@@ -156,12 +156,19 @@ class FinderTest < Test::Unit::TestCase
assert_raises(ActiveRecord::PreparedStatementInvalid) { bind ':a :a', :a => 1, :b => 2 } # ' ruby-mode
end
- def test_bind_array
+ def test_bind_enumerable
assert_equal '1,2,3', bind('?', [1, 2, 3])
assert_equal %('a','b','c'), bind('?', %w(a b c))
assert_equal '1,2,3', bind(':a', :a => [1, 2, 3])
assert_equal %('a','b','c'), bind(':a', :a => %w(a b c)) # '
+
+ require 'set'
+ assert_equal '1,2,3', bind('?', Set.new([1, 2, 3]))
+ assert_equal %('a','b','c'), bind('?', Set.new(%w(a b c)))
+
+ assert_equal '1,2,3', bind(':a', :a => Set.new([1, 2, 3]))
+ assert_equal %('a','b','c'), bind(':a', :a => Set.new(%w(a b c))) # '
end
def test_string_sanitation