diff --git a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb index fb0210dbf..df5c2ac3e 100644 --- a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +++ b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb @@ -18,6 +18,7 @@ def arel_predicate predicates.inject(&:or) end else + predicates.first.right[0] = predicates.first.right[0].val if defined?(Arel::Nodes::Casted) && predicates.first.class == Arel::Nodes::In && predicates.first.right.is_a?(Array) && predicates.first.right[0].class == Arel::Nodes::Casted predicates.first end end diff --git a/spec/ransack/adapters/active_record/base_spec.rb b/spec/ransack/adapters/active_record/base_spec.rb index dd3c3aad3..20d01943a 100644 --- a/spec/ransack/adapters/active_record/base_spec.rb +++ b/spec/ransack/adapters/active_record/base_spec.rb @@ -161,6 +161,11 @@ def self.sane_adapter? expect(s.result.to_a).to eq [p] end + it "should function correctly when an array is passed into custom ransacker with _in" do + s = Person.search(array_users_in: true) + expect(s.result.length).to be > 0 + end + it "should function correctly when an attribute name ends with '_start'" do p = Person.create!(:new_start => 'Bar and foo', :name => 'Xiang') diff --git a/spec/support/schema.rb b/spec/support/schema.rb index 52073ed84..33f312677 100644 --- a/spec/support/schema.rb +++ b/spec/support/schema.rb @@ -45,6 +45,10 @@ class Person < ActiveRecord::Base parent.table[:name] end + ransacker :array_users, formatter: proc { |v| Person.first(2).map(&:id) } do |parent| + parent.table[:id] + end + ransacker :doubled_name do |parent| Arel::Nodes::InfixOperation.new( '||', parent.table[:name], parent.table[:name]