Skip to content

Commit 0b8b582

Browse files
duncanbeeverslifo
authored andcommitted
Add test for named_scope#proxy_options. [#97 state:resolved]
1 parent 3f0dccb commit 0b8b582

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

activerecord/lib/active_record/named_scope.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ def scopes
7171
# end
7272
# end
7373
#
74+
#
75+
# For testing complex named scopes, you can examine the scoping options using the
76+
# <tt>proxy_options</tt> method on the proxy itself.
77+
#
78+
# class Shirt < ActiveRecord::Base
79+
# named_scope :colored, lambda { |color|
80+
# { :conditions => { :color => color } }
81+
# }
82+
# end
83+
#
84+
# expected_options = { :conditions => { :colored => 'red' } }
85+
# assert_equal expected_options, Shirt.colored('red').proxy_options
7486
def named_scope(name, options = {}, &block)
7587
scopes[name] = lambda do |parent_scope, *args|
7688
Scope.new(parent_scope, case options

activerecord/test/cases/named_scope_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,10 @@ def test_active_records_have_scope_named__scoped__
112112

113113
assert_equal Topic.find(:all, scope), Topic.scoped(scope)
114114
end
115+
116+
def test_proxy_options
117+
expected_proxy_options = { :conditions => { :approved => true } }
118+
assert_equal expected_proxy_options, Topic.approved.proxy_options
119+
end
120+
115121
end

0 commit comments

Comments
 (0)