Skip to content

Commit 3794f2a

Browse files
committed
Ignore case in fuzzy filters for Repos and PRs
1 parent a7d9e4a commit 3794f2a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

lib/commands/user_pulls.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def filter_pulls(query)
2828
query = query.to_s.strip
2929
return user_pulls if query.empty?
3030

31-
filter = Regexp.new(query.split('').join('.*'))
31+
filter = Regexp.new(query.split('').join('.*'), Regexp::IGNORECASE)
3232
user_pulls.select do |pull|
3333
filter =~ pull.title || filter =~ pull.html_url
3434
end

lib/commands/user_repos.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def filter_repos(query)
2525
query = query.to_s.strip
2626
return user_repos if query.empty?
2727

28-
filter = Regexp.new(query.split('').join('.*'))
28+
filter = Regexp.new(query.split('').join('.*'), Regexp::IGNORECASE)
2929
user_repos.select { |repo| filter =~ repo.full_name }
3030
end
3131

test/lib/commands/user_pulls_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def test_fuzzy_filters_pulls_html_url
4949
assert_equal expected, actual
5050
end
5151

52+
def test_fuzzy_filters_ignores_case
53+
pull1 = Entities::PullRequest.new(title: 'Foo bar-baz')
54+
pull2 = Entities::PullRequest.new(title: 'FOO-Bar')
55+
pull3 = Entities::PullRequest.new(title: 'foo-bar')
56+
pull_requests.expects(:user_pulls).returns([pull1, pull2, pull3])
57+
actual = subject.call(%w[fob])
58+
expected = serialize_items([pull1, pull2, pull3])
59+
assert_equal expected, actual
60+
end
61+
5262
def test_inserts_open_pulls_page_when_no_args
5363
pull_requests.expects(:user_pulls).returns([pull_entity])
5464
actual = subject.call([])

test/lib/commands/user_repos_test.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def repository_entity
1818
@repository_entity ||= Entities::Repository.new
1919
end
2020

21+
def serialize_items(items)
22+
JSON.generate(items: items.map(&:as_alfred_item))
23+
end
24+
2125
def test_calls_repositories_data_source
2226
repositories.expects(:user_repos).returns([])
2327
subject.call([])
@@ -28,14 +32,23 @@ def test_fuzzy_filters_repositories
2832
repo2 = Entities::Repository.new(full_name: 'octocat/hello-world')
2933
repositories.expects(:user_repos).returns([repo1, repo2])
3034
actual = subject.call(%w[fobz])
31-
expected = JSON.generate(items: [repo1.as_alfred_item])
35+
expected = serialize_items([repo1])
36+
assert_equal expected, actual
37+
end
38+
39+
def test_fuzzy_filters_ignores_case
40+
repo1 = Entities::Repository.new(full_name: 'Foo/BAR-baz')
41+
repo2 = Entities::Repository.new(full_name: 'octocat/foo-bar')
42+
repositories.expects(:user_repos).returns([repo1, repo2])
43+
actual = subject.call(%w[fob])
44+
expected = serialize_items([repo1, repo2])
3245
assert_equal expected, actual
3346
end
3447

3548
def test_returns_alfred_items_json
3649
repositories.expects(:user_repos).returns([repository_entity])
3750
actual = subject.call([])
38-
expected = JSON.generate(items: [repository_entity.as_alfred_item])
51+
expected = serialize_items([repository_entity])
3952
assert_equal expected, actual
4053
end
4154
end

0 commit comments

Comments
 (0)