Skip to content

Commit fbceb1c

Browse files
committed
Enhance fund search to include description and add corresponding tests
1 parent 84697c1 commit fbceb1c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/models/fund.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Fund < ApplicationRecord
1414
scope :short_names, -> { where("LENGTH(name) < ?", 20) }
1515

1616
def self.search(query)
17-
where("name ILIKE ?", "%#{query}%")
17+
where("name ILIKE :query OR description ILIKE :query", query: "%#{query}%")
1818
end
1919

2020
def self.sync_least_recently_synced

test/controllers/funds_controller_test.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ class FundsControllerTest < ActionDispatch::IntegrationTest
1818
get fund_url(fund)
1919
assert_response :success
2020
end
21+
22+
test "should get search results" do
23+
fund1 = Fund.create!(name: 'Test Fund 1', slug: 'test1', registry_name: 'npm')
24+
fund2 = Fund.create!(name: 'Another Fund', slug: 'test2', registry_name: 'rubygems')
25+
26+
get search_funds_url, params: { query: 'Test' }
27+
assert_response :success
28+
29+
assert_not_nil assigns(:funds), "@funds should be set"
30+
assert_includes assigns(:funds), fund1, "Expected fund1 to be in @funds"
31+
assert_not_includes assigns(:funds), fund2, "Expected fund2 to NOT be in @funds"
32+
end
2133
end

0 commit comments

Comments
 (0)