Overzealous match with finder.rb#method_missing_with_paginate? #35

Open
xunker opened this Issue Mar 29, 2010 · 4 comments

2 participants

@xunker

I am seeing an issue with 2.3.11 under rspec with rails 2.3.5. Given I have an activerecord class with a method containing the word 'paginate':

class Foo << ActiveRecord::Base; def self.paginated_search; end; end

..when attempting to call that method in specs I will be told:

"undefined method ‘findd_search’ for #Class:0x60f2c"

I have traced this down to Finder module in #method_missing_with_paginate where it appears to be patching ActiveRecord's base with a method missing that is calling .sub on the method name that replaces 'paginate' with 'find' and is changing my method call to 'findd_search' (which doesn't exist, of couse)

I have been able to fix problems in my local install by either changing the method name to be something that doesn't contain the word 'paginate' or by patching the method_missing.

For the next version of will_paginate, might it be a good change to switch:

finder.rb:175:
finder = method.to_s.sub('paginate', 'find')

to something like:
finder = method.to_s.sub(/^paginate_/, 'find_')

..so that it will only match methods named "paginate_*" and not methods named "is_paginated_*".

@mislav
Owner

If your method exists, how come method_missing is being called? It only gets triggered for calls to non-existing methods.

@xunker

That's one of the things I've been trying to figure out. It's as if the the method_missing it being invoked at a lower level than the model.

It wouldn't surprise me if it was an interaction of will_paginate with some of the magic rspec uses underneath when running specs.

@mislav
Owner

I should be obvious just by looking at the stack trace. Pls paste it in a gist or somewhere

@xunker

private message send with gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment