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

FilterService: when integer passed for global search, search only in model id #1152

Merged
merged 1 commit into from
Aug 24, 2023
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
5 changes: 4 additions & 1 deletion backend/app/services/filter_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def global_search_query(value)

def call
global_search = @filters.find { |filter_item| filter_item["key"] == "global_search" }
if global_search

if global_search && global_search["value"].to_i.to_s == global_search["value"]
return @items.where(id: global_search["value"])
elsif global_search
@items = @items.where(global_search_query(global_search["value"]))
@filters.reject! { |filter_item| filter_item["key"] == "global_search" }
end
Expand Down
8 changes: 8 additions & 0 deletions backend/spec/services/filter_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
it "returns items matching the global search" do
expect(subject.map(&:id)).to match_array([@enrollment_franceconnect["id"], @enrollment_franceconnect2["id"]])
end

context "when value is an exact enrollment id" do
let(:filters) { [{"key" => "global_search", "value" => @enrollment_franceconnect.id.to_s}].to_json }

it "returns only this item" do
expect(subject.map(&:id)).to eq([@enrollment_franceconnect["id"]])
end
end
end

context "when global_search is used with fuzzy matching" do
Expand Down