Skip to content

Commit

Permalink
Ignore case in fuzzy filters for Repos and PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarjs committed Feb 14, 2021
1 parent a7d9e4a commit 3794f2a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/commands/user_pulls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def filter_pulls(query)
query = query.to_s.strip
return user_pulls if query.empty?

filter = Regexp.new(query.split('').join('.*'))
filter = Regexp.new(query.split('').join('.*'), Regexp::IGNORECASE)
user_pulls.select do |pull|
filter =~ pull.title || filter =~ pull.html_url
end
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/user_repos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def filter_repos(query)
query = query.to_s.strip
return user_repos if query.empty?

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

Expand Down
10 changes: 10 additions & 0 deletions test/lib/commands/user_pulls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def test_fuzzy_filters_pulls_html_url
assert_equal expected, actual
end

def test_fuzzy_filters_ignores_case
pull1 = Entities::PullRequest.new(title: 'Foo bar-baz')
pull2 = Entities::PullRequest.new(title: 'FOO-Bar')
pull3 = Entities::PullRequest.new(title: 'foo-bar')
pull_requests.expects(:user_pulls).returns([pull1, pull2, pull3])
actual = subject.call(%w[fob])
expected = serialize_items([pull1, pull2, pull3])
assert_equal expected, actual
end

def test_inserts_open_pulls_page_when_no_args
pull_requests.expects(:user_pulls).returns([pull_entity])
actual = subject.call([])
Expand Down
17 changes: 15 additions & 2 deletions test/lib/commands/user_repos_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def repository_entity
@repository_entity ||= Entities::Repository.new
end

def serialize_items(items)
JSON.generate(items: items.map(&:as_alfred_item))
end

def test_calls_repositories_data_source
repositories.expects(:user_repos).returns([])
subject.call([])
Expand All @@ -28,14 +32,23 @@ def test_fuzzy_filters_repositories
repo2 = Entities::Repository.new(full_name: 'octocat/hello-world')
repositories.expects(:user_repos).returns([repo1, repo2])
actual = subject.call(%w[fobz])
expected = JSON.generate(items: [repo1.as_alfred_item])
expected = serialize_items([repo1])
assert_equal expected, actual
end

def test_fuzzy_filters_ignores_case
repo1 = Entities::Repository.new(full_name: 'Foo/BAR-baz')
repo2 = Entities::Repository.new(full_name: 'octocat/foo-bar')
repositories.expects(:user_repos).returns([repo1, repo2])
actual = subject.call(%w[fob])
expected = serialize_items([repo1, repo2])
assert_equal expected, actual
end

def test_returns_alfred_items_json
repositories.expects(:user_repos).returns([repository_entity])
actual = subject.call([])
expected = JSON.generate(items: [repository_entity.as_alfred_item])
expected = serialize_items([repository_entity])
assert_equal expected, actual
end
end
Expand Down

0 comments on commit 3794f2a

Please sign in to comment.