Fix #4893: Add a FIELD_present parameter variation for text fields.
Usage: * https://danbooru.donmai.us/wiki_pages.json?search[body_present]=true * https://danbooru.donmai.us/wiki_pages.json?search[body_present]=false
This commit is contained in:
@@ -307,6 +307,14 @@ module Searchable
|
||||
relation = relation.where(attr => params[attr])
|
||||
end
|
||||
|
||||
if params[:"#{attr}_present"].present? && params[:"#{attr}_present"].truthy?
|
||||
relation = relation.where.not(attr => "")
|
||||
end
|
||||
|
||||
if params[:"#{attr}_present"].present? && params[:"#{attr}_present"].falsy?
|
||||
relation = relation.where(attr => "")
|
||||
end
|
||||
|
||||
if params[:"#{attr}_eq"].present?
|
||||
relation = relation.where(attr => params[:"#{attr}_eq"])
|
||||
end
|
||||
|
||||
@@ -82,6 +82,9 @@ class SearchableTest < ActiveSupport::TestCase
|
||||
assert_search_equals([@p3, @p2], source_not_like: "a*")
|
||||
assert_search_equals([@p3, @p2], source_not_ilike: "A*")
|
||||
assert_search_equals([@p3, @p2], source_not_regex: "^a.*")
|
||||
|
||||
assert_search_equals([], source_present: "false")
|
||||
assert_search_equals([@p3, @p2, @p1], source_present: "true")
|
||||
end
|
||||
|
||||
should "support multiple operators on the same attribute" do
|
||||
|
||||
Reference in New Issue
Block a user