Fix investments search with numbers in their title
This commit is contained in:
@@ -201,10 +201,10 @@ class Budget
|
||||
end
|
||||
|
||||
def self.search_by_title_or_id(title_or_id)
|
||||
return where(id: title_or_id) if title_or_id =~ /^[0-9]+$/
|
||||
with_joins = with_translations(Globalize.fallbacks(I18n.locale))
|
||||
|
||||
with_translations(Globalize.fallbacks(I18n.locale)).
|
||||
where("budget_investment_translations.title ILIKE ?", "%#{title_or_id}%")
|
||||
with_joins.where(id: title_or_id).
|
||||
or(with_joins.where("budget_investment_translations.title ILIKE ?", "%#{title_or_id}%"))
|
||||
end
|
||||
|
||||
def searchable_values
|
||||
|
||||
@@ -665,6 +665,12 @@ describe Budget::Investment do
|
||||
|
||||
expect(Budget::Investment.search_by_title_or_id("Investment title")).to eq([investment])
|
||||
end
|
||||
|
||||
it "finds investments with numbers in their title" do
|
||||
investment = create(:budget_investment, title: "99 red balloons")
|
||||
|
||||
expect(Budget::Investment.search_by_title_or_id("99")).to eq([investment])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user