diff options
author | Duncan Beevers <duncanbeevers@gmail.com> | 2008-05-11 20:33:25 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-05-11 20:33:25 +0100 |
commit | 0b8b582e0668416c6e6760e97a64b9fa3507782c (patch) | |
tree | 9d6f5250628a777db52141dd95bd68e7e7799245 /activerecord | |
parent | 3f0dccbbc7c98938349650033ff9a41a814d300d (diff) | |
download | rails-0b8b582e0668416c6e6760e97a64b9fa3507782c.tar.gz rails-0b8b582e0668416c6e6760e97a64b9fa3507782c.tar.bz2 rails-0b8b582e0668416c6e6760e97a64b9fa3507782c.zip |
Add test for named_scope#proxy_options. [#97 state:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/named_scope.rb | 12 | ||||
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 6 |
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/named_scope.rb b/activerecord/lib/active_record/named_scope.rb index 81b99f8e96..d43ebefc3b 100644 --- a/activerecord/lib/active_record/named_scope.rb +++ b/activerecord/lib/active_record/named_scope.rb @@ -71,6 +71,18 @@ module ActiveRecord # 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 diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index e99448c23e..30c074c9d8 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -112,4 +112,10 @@ class NamedScopeTest < ActiveRecord::TestCase 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 |