public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix NamedScope regex so methods containing "an" get delegated to proxy_found. 
[#901 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
DefV (author)
Mon Aug 25 03:37:34 -0700 2008
lifo (committer)
Fri Aug 29 06:06:37 -0700 2008
commit  db116a2ed688d36570f412a42e9fc33dcbca56c7
tree    2f2623fc889af731135efbc06371db59ba9cc27c
parent  6577942b61b98e3bca54c0af3df57f8334b832b9
...
103
104
105
106
 
107
108
109
...
103
104
105
 
106
107
108
109
0
@@ -103,7 +103,7 @@ module ActiveRecord
0
       attr_reader :proxy_scope, :proxy_options
0
 
0
       [].methods.each do |m|
0
-        unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|^find$|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?|respond_to?)/
1
+        unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|^find$|count|sum|average|maximum|minimum|paginate|first|last|empty\?|any\?|respond_to\?)/
0
           delegate m, :to => :proxy_found
0
         end
0
       end
...
249
250
251
 
 
 
 
252
253
254
...
249
250
251
252
253
254
255
256
257
258
0
@@ -249,6 +249,10 @@ class NamedScopeTest < ActiveRecord::TestCase
0
     assert_equal Topic.base.select(&:approved), Topic.base.find_all(&:approved)
0
   end
0
 
0
+  def test_rand_should_select_a_random_object_from_proxy
0
+    assert Topic.approved.rand.is_a? Topic
0
+  end
0
+
0
   def test_should_use_where_in_query_for_named_scope
0
     assert_equal Developer.find_all_by_name('Jamis'), Developer.find_all_by_id(Developer.jamises)
0
   end

Comments

mislav Fri Aug 29 07:26:10 -0700 2008 at activerecord/lib/active_record/named_scope.rb L107

Why aren’t more than half of these regexes anchored to the beginning and end of string, like the ones in the beginning are?

ryanb Fri Aug 29 07:38:43 -0700 2008

That’s what I’m wondering too mislav.

NZKoz Fri Aug 29 12:14:01 -0700 2008