mrkamel/search_cop

Rails 4.2, arel 6: wrong number of arguments for #accept

Closed this issue · 6 comments

Thanks for search_cop! I was using attr_searchable before, and I've been upgrading my app. I just started a new Rails 4.2 project and did the most basic search_cop installation.

class Bug < ActiveRecord::Base
  include SearchCop
  search_scope :search do
    attributes :title
  end
end

When I try a search, I get the following error:

Bug.search("cimon")
ArgumentError: wrong number of arguments (1 for 2)
    from /Users/adam/.rvm/gems/ruby-2.1.2/gems/arel-6.0.0.beta2/lib/arel/visitors/reduce.rb:6:in `accept'

I don't know this area very well, but it looks like arel 6 added a second argument to the #accept method:
rails/arel@a6a7c75
which search_cop uses in query_builder:
https://github.com/mrkamel/search_cop/blob/master/lib/search_cop/query_builder.rb#L12

I tried downgrading arel to lower version, but it said arel 6 is required for rails 4.2.

Hi, thx for the report. I'll dig into this.

I forgot to mention – I included fairly few details in my report because it seemed easily reproducible. If you don't find it so, I'm happy to provide more.

Sure, no problem. It's indeed rather obvious, but not as simple as adding the missing param. Arel now seems to favor #compile over #accept. That alone would not be an issue, but Arel 6 seems to include many API specific changes, especially this commit in Arel, which IMO focuses on performance tweaks, breaks a lot in SearchCop: rails/arel@93d7213 which will force us to now wrap every String with Arel::Nodes.build_quoted before handing it out to Arel. Otherwise we'll get exceptions telling us that plain strings are unsupported. Thus, i'm thinking about dropping Arel. SearchCop already has a lot of code to handle specific Arel versions, just take a look into https://github.com/mrkamel/search_cop/blob/master/lib/search_cop/arel/visitors.rb - and generating the SQL by ourselves would not be that hard.

Hi, as you probably noticed, i created a branch 'drop_arel' which replaces Arel with a custom visitors. I'll merge it into master, probably today or tomorrow and bump a new gem version. In the meantime, you're very welcome to try it out:

gem 'search_cop', :git => 'https://github.com/mrkamel/search_cop.git', :branch => 'drop_arel'

Looks good. I'm not going to get to it for the next couple of days, but I'll definitely try things this week. Thanks for the quick fix.

In the meantime, this has been merged into master.