aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnie Miller <ernie@metautonomo.us>2011-02-07 21:39:19 -0500
committerErnie Miller <ernie@metautonomo.us>2011-02-08 06:33:38 -0500
commit3d21dabaa6c214ab2f2941c063bd7de04fd95202 (patch)
tree1f79851b857033c8e1edb80974826b1b171fda45
parent3cd905ee7b6ec8765cf9690b88ada5ae27fc3fd0 (diff)
downloadrails-3d21dabaa6c214ab2f2941c063bd7de04fd95202.tar.gz
rails-3d21dabaa6c214ab2f2941c063bd7de04fd95202.tar.bz2
rails-3d21dabaa6c214ab2f2941c063bd7de04fd95202.zip
Fix modification of input on *_any/*_all predications
-rw-r--r--lib/arel/predications.rb2
-rw-r--r--test/attributes/test_attribute.rb16
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/arel/predications.rb b/lib/arel/predications.rb
index 58f02a2b53..920a9ee374 100644
--- a/lib/arel/predications.rb
+++ b/lib/arel/predications.rb
@@ -163,6 +163,7 @@ module Arel
private
def grouping_any method_id, others
+ others = others.dup
first = send method_id, others.shift
Nodes::Grouping.new others.inject(first) { |memo,expr|
@@ -171,6 +172,7 @@ module Arel
end
def grouping_all method_id, others
+ others = others.dup
first = send method_id, others.shift
Nodes::Grouping.new others.inject(first) { |memo,expr|
diff --git a/test/attributes/test_attribute.rb b/test/attributes/test_attribute.rb
index df7dc69621..352774071a 100644
--- a/test/attributes/test_attribute.rb
+++ b/test/attributes/test_attribute.rb
@@ -366,6 +366,14 @@ module Arel
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 OR "users"."id" = 2)
}
end
+
+ it 'should not eat input' do
+ relation = Table.new(:users)
+ mgr = relation.project relation[:id]
+ values = [1,2]
+ mgr.where relation[:id].eq_any(values)
+ values.must_equal [1,2]
+ end
end
describe '#eq_all' do
@@ -382,6 +390,14 @@ module Arel
SELECT "users"."id" FROM "users" WHERE ("users"."id" = 1 AND "users"."id" = 2)
}
end
+
+ it 'should not eat input' do
+ relation = Table.new(:users)
+ mgr = relation.project relation[:id]
+ values = [1,2]
+ mgr.where relation[:id].eq_all(values)
+ values.must_equal [1,2]
+ end
end
describe '#matches' do