aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew White <pixeltrix@users.noreply.github.com>2017-03-21 10:55:11 +0000
committerGitHub <noreply@github.com>2017-03-21 10:55:11 +0000
commit81b2cd115356d3a5b3bc28454658101efd16bfad (patch)
treec4d2934b1c9bddf88c3c05c9082fcd78e1830f3f
parentcd3c0357d7ca7574f5a15a1229d25417a93a0a06 (diff)
parent19dc69cb07572f8b17ae15c8bc0b5a29bc8a281f (diff)
downloadrails-81b2cd115356d3a5b3bc28454658101efd16bfad.tar.gz
rails-81b2cd115356d3a5b3bc28454658101efd16bfad.tar.bz2
rails-81b2cd115356d3a5b3bc28454658101efd16bfad.zip
Merge pull request #28497 from jhawthorn/unscope_specific_where_value
Fix where_clause#except with specific where value
-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"]