[rspec-users] named_scope doesn't check for critical method names.

Rick DeNatale rick.denatale at gmail.com
Thu Jun 12 16:44:15 EDT 2008

I just entered this ticket.


It turns out that in an ActiveRecord model like this

Model << ActiveRecord::Base

   named_scope :public

   def private_method

   def public_method

The method public_method will be private because named scope overrides
Ruby's public method!  Also this can cause additionally hard to debug
failures in metaprogramming, I discovered this when the RSpec stub! method
blew up when it used class_eval to generate a stub method which apparently
caused public to be called internally by Ruby, at which time the named_scope
generated method failed.

See the ticket for details.

I'm not sure what the fix should be, but I think that named_scope should not
cause public/private, and the like to be clobbered.

Rick DeNatale

My blog on Ruby
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080612/acb93570/attachment.html>

More information about the rspec-users mailing list