Bug in proxy_respond_to?

Commit http://github.com/rails/rails/commit/517bc500ed95a84fd2aadff34fdc14cb7965bc6b introduced the new method proxy_respond_to?, but it has a bug.

Suppose the following case (it’s using will_paginate plugin)

class User < ActiveRecord::Base has_many :articles end

Then you call:

u = User.first u.articles # => [some articles…] u.articles # => ArgumentError: wrong number of arguments (2 for 1) from …/activerecord/lib/active_record/associations/association_proxy.rb:78:in proxy_respond_to?' from .../activerecord/lib/active_record/associations/association_proxy.rb:78:in respond_to?’ from …/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:155:in respond_to?' from .../activerecord/lib/active_record/associations.rb:1287:in articles’ from (irb):3

As you can see, the bug is caused in the will_paginate plugin because it pass two params to the super respond_to?

def respond_to?(method, include_priv = false) #:nodoc: case method.to_sym when :paginate, :paginate_by_sql true else super(method.to_s.sub(/^paginate/, ‘find’), include_priv) end end

So the fix should be adding an extra param to proxy_respond_to?

def proxy_respond_to?(method, include_priv = false) super || @reflection.klass.respond_to?(method, include_priv) end

How could I test this to submit a patch?

PS: Even this is kinda curious because it throws the Exception after the second time it’s called, not the first one. Haven’t gone that deep yet.

Regards.

Edgar J. Suarez

У Чцв, 16/10/2008 у 15:57 -0500, Edgar J. Suárez піша:

Commit Allow class methods to be sent (via #send) to association proxy (fix … · rails/rails@517bc50 · GitHub introduced the new method proxy_respond_to?, but it has a bug.

...

How could I test this to submit a patch?

Just check that association proxy understands #respond_to? with two arguments. This test will and the fix is trivial.

BTW. I may be wrong, but it seems that people who contribute & accept patches somehow started to think less about trivial corner cases like this one. Is it false sence of safety caused by wider introduction of unit testing ?

BTW. I may be wrong, but it seems that people who contribute & accept patches somehow started to think less about trivial corner cases like this one. Is it false sence of safety caused by wider introduction of unit testing ?

Sorry I don't follow you ?

У Пят, 17/10/2008 у 08:20 +0200, Pratik піша: