diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-21 06:15:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-21 06:15:00 +0300 |
commit | e3ecb7dc093db47b9491e20d9f20de02b4ac2b6d (patch) | |
tree | e87e5dd85e9c33644b3eddcd47a6214e5537d2c9 /spec/models | |
parent | 4aa6fba6d825b88d23ff37668e78c851bec102b0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/namespace_spec.rb | 22 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 21 |
2 files changed, 43 insertions, 0 deletions
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index 0e6513764f5..45ebde13a00 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -1130,6 +1130,28 @@ RSpec.describe Namespace, feature_category: :groups_and_projects do end end + describe '.gfm_autocomplete_search' do + let_it_be(:parent_group) { create(:group, path: 'parent', name: 'Parent') } + let_it_be(:group_1) { create(:group, parent: parent_group, path: 'somepath', name: 'Your Group') } + let_it_be(:group_2) { create(:group, path: 'noparent', name: 'My Group') } + + it 'returns partial matches on full path' do + expect(described_class.gfm_autocomplete_search('parent/som')).to eq([group_1]) + end + + it 'returns matches on full name across multiple words' do + expect(described_class.gfm_autocomplete_search('yourgr')).to eq([group_1]) + end + + it 'prioritizes sorting of matches that start with the query' do + expect(described_class.gfm_autocomplete_search('pare')).to eq([parent_group, group_1, group_2]) + end + + it 'falls back to sorting by full path' do + expect(described_class.gfm_autocomplete_search('group')).to eq([group_2, group_1]) + end + end + describe '.with_statistics' do let_it_be(:namespace) { create(:namespace) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ddf5a9a7221..69fdec0fc10 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3381,6 +3381,27 @@ RSpec.describe User, feature_category: :user_profile do end end + describe '.gfm_autocomplete_search' do + let_it_be(:user_1) { create(:user, username: 'someuser', name: 'John Doe') } + let_it_be(:user_2) { create(:user, username: 'userthomas', name: 'Thomas Person') } + + it 'returns partial matches on username' do + expect(described_class.gfm_autocomplete_search('some')).to eq([user_1]) + end + + it 'returns matches on name across multiple words' do + expect(described_class.gfm_autocomplete_search('johnd')).to eq([user_1]) + end + + it 'prioritizes sorting of matches that start with the query' do + expect(described_class.gfm_autocomplete_search('user')).to eq([user_2, user_1]) + end + + it 'falls back to sorting by username' do + expect(described_class.gfm_autocomplete_search('ser')).to eq([user_1, user_2]) + end + end + describe '.user_search_minimum_char_limit' do it 'returns true' do expect(described_class.user_search_minimum_char_limit).to be(true) |