diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 14:28:29 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-30 14:28:29 -0800 |
commit | f64c50a092394917ad9a79abc563aa2bef22ce94 (patch) | |
tree | 864d96082f472e60cbad1afd503fe507cf6dd2e6 /activerecord | |
parent | 27aedeeb0bb9350d653f40d7023dd095be5eb24e (diff) | |
parent | abc19c37aea561e7b087cee9d60c5698483f3136 (diff) | |
download | rails-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.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 10 |
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 } |