diff options
Diffstat (limited to 'spec/models/user_spec.rb')
-rw-r--r-- | spec/models/user_spec.rb | 211 |
1 files changed, 21 insertions, 190 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index c2535fd3698..e4f25c79e53 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2612,6 +2612,12 @@ RSpec.describe User do it 'returns users with a exact matching name shorter than 3 chars regardless of the casing' do expect(described_class.search(user3.name.upcase)).to eq([user3]) end + + context 'when use_minimum_char_limit is false' do + it 'returns users with a partially matching name' do + expect(described_class.search('u', use_minimum_char_limit: false)).to eq([user3, user, user2]) + end + end end describe 'email matching' do @@ -2671,204 +2677,20 @@ RSpec.describe User do it 'returns users with a exact matching username shorter than 3 chars regardless of the casing' do expect(described_class.search(user3.username.upcase)).to eq([user3]) end - end - - it 'returns no matches for an empty string' do - expect(described_class.search('')).to be_empty - end - - it 'returns no matches for nil' do - expect(described_class.search(nil)).to be_empty - end - end - - describe '.search_without_secondary_emails' do - let_it_be(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'someone.1@example.com' ) } - let_it_be(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'another.2@example.com' ) } - let_it_be(:email) { create(:email, user: another_user, email: 'alias@example.com') } - - it 'returns users with a matching name' do - expect(described_class.search_without_secondary_emails(user.name)).to eq([user]) - end - - it 'returns users with a partially matching name' do - expect(described_class.search_without_secondary_emails(user.name[0..2])).to eq([user]) - end - - it 'returns users with a matching name regardless of the casing' do - expect(described_class.search_without_secondary_emails(user.name.upcase)).to eq([user]) - end - - it 'returns users with a matching email' do - expect(described_class.search_without_secondary_emails(user.email)).to eq([user]) - end - - it 'does not return users with a partially matching email' do - expect(described_class.search_without_secondary_emails(user.email[1...-1])).to be_empty - end - - it 'returns users with a matching email regardless of the casing' do - expect(described_class.search_without_secondary_emails(user.email.upcase)).to eq([user]) - end - - it 'returns users with a matching username' do - expect(described_class.search_without_secondary_emails(user.username)).to eq([user]) - end - - it 'returns users with a partially matching username' do - expect(described_class.search_without_secondary_emails(user.username[0..2])).to eq([user]) - end - - it 'returns users with a matching username regardless of the casing' do - expect(described_class.search_without_secondary_emails(user.username.upcase)).to eq([user]) - end - - it 'does not return users with a matching whole secondary email' do - expect(described_class.search_without_secondary_emails(email.email)).not_to include(email.user) - end - it 'does not return users with a matching part of secondary email' do - expect(described_class.search_without_secondary_emails(email.email[1...-1])).to be_empty - end - - it 'returns no matches for an empty string' do - expect(described_class.search_without_secondary_emails('')).to be_empty - end - - it 'returns no matches for nil' do - expect(described_class.search_without_secondary_emails(nil)).to be_empty - end - end - - describe '.search_with_public_emails' do - let_it_be(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'someone.1@example.com' ) } - let_it_be(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'another.2@example.com' ) } - let_it_be(:public_email) do - create(:email, :confirmed, user: another_user, email: 'alias@example.com').tap do |email| - another_user.update!(public_email: email.email) + context 'when use_minimum_char_limit is false' do + it 'returns users with a partially matching username' do + expect(described_class.search('se', use_minimum_char_limit: false)).to eq([user3, user, user2]) + end end end - let_it_be(:secondary_email) do - create(:email, :confirmed, user: another_user, email: 'secondary@example.com') - end - - it 'returns users with a matching name' do - expect(described_class.search_with_public_emails(user.name)).to match_array([user]) - end - - it 'returns users with a partially matching name' do - expect(described_class.search_with_public_emails(user.name[0..2])).to match_array([user]) - end - - it 'returns users with a matching name regardless of the casing' do - expect(described_class.search_with_public_emails(user.name.upcase)).to match_array([user]) - end - - it 'returns users with a matching public email' do - expect(described_class.search_with_public_emails(another_user.public_email)).to match_array([another_user]) - end - - it 'does not return users with a partially matching email' do - expect(described_class.search_with_public_emails(another_user.public_email[1...-1])).to be_empty - end - - it 'returns users with a matching email regardless of the casing' do - expect(described_class.search_with_public_emails(another_user.public_email.upcase)).to match_array([another_user]) - end - - it 'returns users with a matching username' do - expect(described_class.search_with_public_emails(user.username)).to match_array([user]) - end - - it 'returns users with a partially matching username' do - expect(described_class.search_with_public_emails(user.username[0..2])).to match_array([user]) - end - - it 'returns users with a matching username regardless of the casing' do - expect(described_class.search_with_public_emails(user.username.upcase)).to match_array([user]) - end - - it 'does not return users with a matching whole private email' do - expect(described_class.search_with_public_emails(user.email)).not_to include(user) - end - - it 'does not return users with a matching whole private email' do - expect(described_class.search_with_public_emails(secondary_email.email)).to be_empty - end - - it 'does not return users with a matching part of secondary email' do - expect(described_class.search_with_public_emails(secondary_email.email[1...-1])).to be_empty - end - - it 'does not return users with a matching part of private email' do - expect(described_class.search_with_public_emails(user.email[1...-1])).to be_empty - end - - it 'returns no matches for an empty string' do - expect(described_class.search_with_public_emails('')).to be_empty - end - - it 'returns no matches for nil' do - expect(described_class.search_with_public_emails(nil)).to be_empty - end - end - - describe '.search_with_secondary_emails' do - let_it_be(:user) { create(:user, name: 'John Doe', username: 'john.doe', email: 'someone.1@example.com' ) } - let_it_be(:another_user) { create(:user, name: 'Albert Smith', username: 'albert.smith', email: 'another.2@example.com' ) } - let_it_be(:email) { create(:email, user: another_user, email: 'alias@example.com') } - - it 'returns users with a matching name' do - expect(described_class.search_with_secondary_emails(user.name)).to eq([user]) - end - - it 'returns users with a partially matching name' do - expect(described_class.search_with_secondary_emails(user.name[0..2])).to eq([user]) - end - - it 'returns users with a matching name regardless of the casing' do - expect(described_class.search_with_secondary_emails(user.name.upcase)).to eq([user]) - end - - it 'returns users with a matching email' do - expect(described_class.search_with_secondary_emails(user.email)).to eq([user]) - end - - it 'does not return users with a partially matching email' do - expect(described_class.search_with_secondary_emails(user.email[1...-1])).to be_empty - end - - it 'returns users with a matching email regardless of the casing' do - expect(described_class.search_with_secondary_emails(user.email.upcase)).to eq([user]) - end - - it 'returns users with a matching username' do - expect(described_class.search_with_secondary_emails(user.username)).to eq([user]) - end - - it 'returns users with a partially matching username' do - expect(described_class.search_with_secondary_emails(user.username[0..2])).to eq([user]) - end - - it 'returns users with a matching username regardless of the casing' do - expect(described_class.search_with_secondary_emails(user.username.upcase)).to eq([user]) - end - - it 'returns users with a matching whole secondary email' do - expect(described_class.search_with_secondary_emails(email.email)).to eq([email.user]) - end - - it 'does not return users with a matching part of secondary email' do - expect(described_class.search_with_secondary_emails(email.email[1...-1])).to be_empty - end - it 'returns no matches for an empty string' do - expect(described_class.search_with_secondary_emails('')).to be_empty + expect(described_class.search('')).to be_empty end it 'returns no matches for nil' do - expect(described_class.search_with_secondary_emails(nil)).to be_empty + expect(described_class.search(nil)).to be_empty end end @@ -3683,13 +3505,16 @@ RSpec.describe User do let!(:project1) { create(:project) } let!(:project2) { fork_project(project3) } let!(:project3) { create(:project) } + let!(:project_aimed_for_deletion) { create(:project, marked_for_deletion_at: 2.days.ago, pending_delete: false) } let!(:merge_request) { create(:merge_request, source_project: project2, target_project: project3, author: subject) } let!(:push_event) { create(:push_event, project: project1, author: subject) } let!(:merge_event) { create(:event, :created, project: project3, target: merge_request, author: subject) } + let!(:merge_event_2) { create(:event, :created, project: project_aimed_for_deletion, target: merge_request, author: subject) } before do project1.add_maintainer(subject) project2.add_maintainer(subject) + project_aimed_for_deletion.add_maintainer(subject) end it 'includes IDs for projects the user has pushed to' do @@ -3703,6 +3528,10 @@ RSpec.describe User do it "doesn't include IDs for unrelated projects" do expect(subject.contributed_projects).not_to include(project2) end + + it "doesn't include projects aimed for deletion" do + expect(subject.contributed_projects).not_to include(project_aimed_for_deletion) + end end describe '#fork_of' do @@ -4365,6 +4194,8 @@ RSpec.describe User do context 'when FF ci_owned_runners_cross_joins_fix is disabled' do before do + skip_if_multiple_databases_are_setup + stub_feature_flags(ci_owned_runners_cross_joins_fix: false) end |