Skip to content

Commit

Permalink
Merge pull request #486 from ideanl/master
Browse files Browse the repository at this point in the history
[472] Allow arrays to be received for ransacker with Rails 4.2/Arel 6
  • Loading branch information
jonatack committed Jan 4, 2015
2 parents 059310d + 9631f1d commit b7f1401
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 4 additions & 0 deletions spec/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit b7f1401

Please sign in to comment.