Delegate #unscope query method

This commit is contained in:
Carlos Antonio da Silva 2013-04-28 22:59:18 -03:00
parent 226de24fa2
commit 85a56ff01d
2 changed files with 11 additions and 1 deletions

@ -8,7 +8,7 @@ module Querying
delegate :find_each, :find_in_batches, :to => :all
delegate :select, :group, :order, :except, :reorder, :limit, :offset, :joins,
:where, :preload, :eager_load, :includes, :from, :lock, :readonly,
:having, :create_with, :uniq, :distinct, :references, :none, :to => :all
:having, :create_with, :uniq, :distinct, :references, :none, :unscope, :to => :all
delegate :count, :average, :minimum, :maximum, :sum, :calculate, :pluck, :ids, :to => :all
# Executes a custom SQL query against your database and returns all the results. The results will

@ -198,6 +198,16 @@ def test_unscope_having
assert_equal expected, received
end
def test_unscope_and_scope
developer_klass = Class.new(Developer) do
scope :by_name, -> name { unscope(where: :name).where(name: name) }
end
expected = developer_klass.where(name: 'Jamis').collect { |dev| [dev.name, dev.id] }
received = developer_klass.where(name: 'David').by_name('Jamis').collect { |dev| [dev.name, dev.id] }
assert_equal expected, received
end
def test_unscope_errors_with_invalid_value
assert_raises(ArgumentError) do
Developer.includes(:projects).where(name: "Jamis").unscope(:stupidly_incorrect_value)