Skip to content
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
2 changes: 1 addition & 1 deletion lib/rails_admin/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def filter_scope(scope, filters, fields = config.list.fields.select(&:filterable
field = fields.detect { |f| f.name.to_s == field_name }
value = parse_field_value(field, filter_dump[:v])

wb.add(field, value, (filter_dump[:o] || 'default'))
wb.add(field, value, (filter_dump[:o] || RailsAdmin::Config.default_search_operator))
# AND current filter statements to other filter statements
scope = wb.build
end
Expand Down
19 changes: 19 additions & 0 deletions spec/rails_admin/adapters/active_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,25 @@ def parse_value(value)
expect(abstract_model.all(filters: {'name' => {'0000' => {o: 'like', v: 'where'}}})).to match_array @teams[2]
end
end

context 'when a default_search_operator is set' do
before do
RailsAdmin.config do |c|
c.default_search_operator = 'starts_with'
end
end

it 'only matches on prefix' do
# Specified operator is honored and matches
expect(abstract_model.all(filters: {'name' => {'0000' => {o: 'like', v: 'where'}}})).to match_array @teams[2..3]

# No operator falls back to the default_search_operator(starts_with) and doesn't match NON-PREFIX
expect(abstract_model.all(filters: {'name' => {'0000' => {v: 'where'}}})).to be_empty

# No operator falls back to the default_search_operator(starts_with) and doesn't match NON-PREFIX
expect(abstract_model.all(filters: {'name' => {'0000' => {v: 'somewhere'}}})).to match_array @teams[2]
end
end
end

describe '#build_statement' do
Expand Down