Allow any Enumerable, not just Array, to work as bind variables #1344 [bitsweat]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1442 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
a895be0259
commit
253a2bbefb
@ -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:
|
||||
|
||||
|
@ -896,7 +896,7 @@ def replace_named_bind_variables(statement, bind_vars)
|
||||
|
||||
def quote_bound_value(value)
|
||||
case value
|
||||
when Array
|
||||
when Enumerable
|
||||
value.map { |v| connection.quote(v) }.join(',')
|
||||
else
|
||||
connection.quote(value)
|
||||
|
@ -156,12 +156,19 @@ def test_named_bind_arity
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user