diff options
author | Washington Luiz <huoxito@gmail.com> | 2014-01-28 00:59:11 -0300 |
---|---|---|
committer | Washington Luiz <huoxito@gmail.com> | 2014-01-30 18:35:27 -0300 |
commit | abc19c37aea561e7b087cee9d60c5698483f3136 (patch) | |
tree | b0c1ac1dd708a88eb264ed1398ff7e6826d32aa4 /activerecord | |
parent | d4d041c1fe55c10a786a4a1a7ff0c34867944b2f (diff) | |
download | rails-abc19c37aea561e7b087cee9d60c5698483f3136.tar.gz rails-abc19c37aea561e7b087cee9d60c5698483f3136.tar.bz2 rails-abc19c37aea561e7b087cee9d60c5698483f3136.zip |
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 } |