aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJohn Hawthorn <john@stembolt.com>2017-03-20 14:55:53 -0700
committerJohn Hawthorn <john@stembolt.com>2017-03-20 15:52:35 -0700
commit19dc69cb07572f8b17ae15c8bc0b5a29bc8a281f (patch)
tree16ba6bc1a19644ff748512bcf079a9c8834e7743 /activerecord
parent5c0d00072d1309dbc77bb5d97e42956bac3e8684 (diff)
downloadrails-19dc69cb07572f8b17ae15c8bc0b5a29bc8a281f.tar.gz
rails-19dc69cb07572f8b17ae15c8bc0b5a29bc8a281f.tar.bz2
rails-19dc69cb07572f8b17ae15c8bc0b5a29bc8a281f.zip
Fix where_clause#except with specific where value
Fixes a regression introduced in 22ca710f20c3c656811df006cbf1f4dbc359f7a6 where Relation#unscope with a specific where value (vs unscoping the entire where clause) could result in the wrong binds being left on the query. This was caused by an index variable not being incremented properly.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/where_clause.rb4
-rw-r--r--activerecord/test/cases/relations_test.rb8
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb
index 417b24c7bb..119910ee79 100644
--- a/activerecord/lib/active_record/relation/where_clause.rb
+++ b/activerecord/lib/active_record/relation/where_clause.rb
@@ -148,10 +148,10 @@ module ActiveRecord
(binds_index...(binds_index + binds_contains)).each do |i|
except_binds[i] = true
end
-
- binds_index += binds_contains
end
+ binds_index += binds_contains if binds_contains
+
except
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 73986d2d16..e17cb1795e 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -1970,6 +1970,14 @@ class RelationTest < ActiveRecord::TestCase
assert_equal p2.first.comments, comments
end
+ def test_unscope_specific_where_value
+ posts = Post.where(title: "Welcome to the weblog", body: "Such a lovely day")
+
+ assert_equal 1, posts.count
+ assert_equal 1, posts.unscope(where: :title).count
+ assert_equal 1, posts.unscope(where: :body).count
+ end
+
def test_unscope_removes_binds
left = Post.where(id: Arel::Nodes::BindParam.new)
column = Post.columns_hash["id"]