Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add test for named_scope#proxy_options. [#97 state:resolved]
  • Loading branch information
duncanbeevers authored and lifo committed May 11, 2008
1 parent 3f0dccb commit 0b8b582
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions activerecord/lib/active_record/named_scope.rb
Expand Up @@ -71,6 +71,18 @@ def scopes
# end
# end
#
#
# For testing complex named scopes, you can examine the scoping options using the
# <tt>proxy_options</tt> method on the proxy itself.
#
# class Shirt < ActiveRecord::Base
# named_scope :colored, lambda { |color|
# { :conditions => { :color => color } }
# }
# end
#
# expected_options = { :conditions => { :colored => 'red' } }
# assert_equal expected_options, Shirt.colored('red').proxy_options
def named_scope(name, options = {}, &block)
scopes[name] = lambda do |parent_scope, *args|
Scope.new(parent_scope, case options
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/named_scope_test.rb
Expand Up @@ -112,4 +112,10 @@ def test_active_records_have_scope_named__scoped__

assert_equal Topic.find(:all, scope), Topic.scoped(scope)
end

def test_proxy_options
expected_proxy_options = { :conditions => { :approved => true } }
assert_equal expected_proxy_options, Topic.approved.proxy_options
end

end

0 comments on commit 0b8b582

Please sign in to comment.