Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[472] Allow arrays to be received for custom ransacker #486

Merged
merged 3 commits into from
Jan 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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