public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fixed that scopes defined with a string name could not be composed
Tarmo Tänav (author)
Fri Jun 13 13:39:10 -0700 2008
jeremy (committer)
Sun Jun 22 17:26:00 -0700 2008
commit  1afae84ab2656cd58a861ab4a4b1745d80088d0f
tree    29544057e3738abdc680d795aa8fe49ebdf1176b
parent  43cbcb10ae85adc4403e950e69ee14123a20d8ae
...
82
83
84
 
85
86
87
...
82
83
84
85
86
87
88
0
@@ -82,6 +82,7 @@ module ActiveRecord
0
       #   expected_options = { :conditions => { :colored => 'red' } }
0
       #   assert_equal expected_options, Shirt.colored('red').proxy_options
0
       def named_scope(name, options = {}, &block)
0
+        name = name.to_sym
0
         scopes[name] = lambda do |parent_scope, *args|
0
           Scope.new(parent_scope, case options
0
             when Hash
...
59
60
61
 
 
 
 
 
 
62
63
64
...
59
60
61
62
63
64
65
66
67
68
69
70
0
@@ -59,6 +59,12 @@ class NamedScopeTest < ActiveRecord::TestCase
0
     assert_equal Topic.count(:conditions => {:approved => true}), Topic.approved.count
0
   end
0
 
0
+  def test_scopes_with_string_name_can_be_composed
0
+    # NOTE that scopes defined with a string as a name worked on their own
0
+    # but when called on another scope the other scope was completely replaced
0
+    assert_equal Topic.replied.approved, Topic.replied.approved_as_string
0
+  end
0
+
0
   def test_scopes_are_composable
0
     assert_equal (approved = Topic.find(:all, :conditions => {:approved => true})), Topic.approved
0
     assert_equal (replied = Topic.find(:all, :conditions => 'replies_count > 0')), Topic.replied
...
4
5
6
 
7
8
9
...
4
5
6
7
8
9
10
0
@@ -4,6 +4,7 @@ class Topic < ActiveRecord::Base
0
     { :conditions => ['written_on < ?', time] }
0
   }
0
   named_scope :approved, :conditions => {:approved => true}
0
+  named_scope 'approved_as_string', :conditions => {:approved => true}
0
   named_scope :replied, :conditions => ['replies_count > 0']
0
   named_scope :anonymous_extension do
0
     def one

Comments