aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-30 14:28:29 -0800
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-01-30 14:28:29 -0800
commitf64c50a092394917ad9a79abc563aa2bef22ce94 (patch)
tree864d96082f472e60cbad1afd503fe507cf6dd2e6 /activerecord
parent27aedeeb0bb9350d653f40d7023dd095be5eb24e (diff)
parentabc19c37aea561e7b087cee9d60c5698483f3136 (diff)
downloadrails-f64c50a092394917ad9a79abc563aa2bef22ce94.tar.gz
rails-f64c50a092394917ad9a79abc563aa2bef22ce94.tar.bz2
rails-f64c50a092394917ad9a79abc563aa2bef22ce94.zip
Merge pull request #13859 from huoxito/let-it-go
Let `unscope` ignore non Arel scope.where_values
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb2
-rw-r--r--activerecord/test/cases/scoping/default_scoping_test.rb10
2 files changed, 10 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 14470f22aa..860063426a 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -883,8 +883,6 @@ module ActiveRecord
when Arel::Nodes::In, Arel::Nodes::NotIn, Arel::Nodes::Equality, Arel::Nodes::NotEqual
subrelation = (rel.left.kind_of?(Arel::Attributes::Attribute) ? rel.left : rel.right)
subrelation.name == target_value
- else
- raise "unscope(where: #{target_value.inspect}) failed: unscoping #{rel.class} \"#{rel}\" is unimplemented."
end
end
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb
index 71754cf0a2..170e9a49eb 100644
--- a/activerecord/test/cases/scoping/default_scoping_test.rb
+++ b/activerecord/test/cases/scoping/default_scoping_test.rb
@@ -149,6 +149,16 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected, received
end
+ def test_unscope_string_where_clauses_involved
+ dev_relation = Developer.order('salary DESC').where("created_at > ?", 1.year.ago)
+ expected = dev_relation.collect { |dev| dev.name }
+
+ dev_ordered_relation = DeveloperOrderedBySalary.where(name: 'Jamis').where("created_at > ?", 1.year.ago)
+ received = dev_ordered_relation.unscope(where: [:name]).collect { |dev| dev.name }
+
+ assert_equal expected, received
+ end
+
def test_unscope_with_grouping_attributes
expected = Developer.order('salary DESC').collect { |dev| dev.name }
received = DeveloperOrderedBySalary.group(:name).unscope(:group).collect { |dev| dev.name }