diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 18:09:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-07 18:09:14 +0300 |
commit | 9498dc957345829f29fe0bc4e55c969783b457be (patch) | |
tree | ca19b899f1eee13ad892fe18ece040347c3a1e71 /spec/models | |
parent | ba27dbddc7dbc42f2cc8d84e815a9ea19f87a81d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/merge_request_diff_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/organizations/organization_spec.rb | 31 | ||||
-rw-r--r-- | spec/models/preloaders/merge_request_diff_preloader_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 99 |
4 files changed, 115 insertions, 23 deletions
diff --git a/spec/models/merge_request_diff_spec.rb b/spec/models/merge_request_diff_spec.rb index e2c87b0d85c..57a9963c0f1 100644 --- a/spec/models/merge_request_diff_spec.rb +++ b/spec/models/merge_request_diff_spec.rb @@ -1178,14 +1178,14 @@ RSpec.describe MergeRequestDiff, feature_category: :code_review_workflow do end describe '.latest_diff_for_merge_requests' do - let_it_be(:merge_request_1) { create(:merge_request_without_merge_request_diff) } + let_it_be(:merge_request_1) { create(:merge_request, :skip_diff_creation) } let_it_be(:merge_request_1_diff_1) { create(:merge_request_diff, merge_request: merge_request_1, created_at: 3.days.ago) } let_it_be(:merge_request_1_diff_2) { create(:merge_request_diff, merge_request: merge_request_1, created_at: 1.day.ago) } - let_it_be(:merge_request_2) { create(:merge_request_without_merge_request_diff) } + let_it_be(:merge_request_2) { create(:merge_request, :skip_diff_creation) } let_it_be(:merge_request_2_diff_1) { create(:merge_request_diff, merge_request: merge_request_2, created_at: 3.days.ago) } - let_it_be(:merge_request_3) { create(:merge_request_without_merge_request_diff) } + let_it_be(:merge_request_3) { create(:merge_request, :skip_diff_creation) } subject { described_class.latest_diff_for_merge_requests([merge_request_1, merge_request_2]) } diff --git a/spec/models/organizations/organization_spec.rb b/spec/models/organizations/organization_spec.rb index bb3d0c2307d..3b202b85b48 100644 --- a/spec/models/organizations/organization_spec.rb +++ b/spec/models/organizations/organization_spec.rb @@ -18,6 +18,37 @@ RSpec.describe Organizations::Organization, type: :model, feature_category: :cel it { is_expected.to validate_length_of(:name).is_at_most(255) } it { is_expected.to validate_presence_of(:path) } it { is_expected.to validate_length_of(:path).is_at_least(2).is_at_most(255) } + + describe 'path validator' do + using RSpec::Parameterized::TableSyntax + + let(:default_path_error) do + "can contain only letters, digits, '_', '-' and '.'. Cannot start with '-' or end in '.', '.git' or '.atom'." + end + + let(:reserved_path_error) do + "is a reserved name" + end + + where(:path, :valid, :error_message) do + 'path.' | false | ref(:default_path_error) + 'path.git' | false | ref(:default_path_error) + 'new' | false | ref(:reserved_path_error) + '.path' | true | nil + 'org__path' | true | nil + 'some-name' | true | nil + 'simple' | true | nil + end + + with_them do + it 'validates organization path' do + organization = build(:organization, name: 'Default', path: path) + + expect(organization.valid?).to be(valid) + expect(organization.errors.full_messages.to_sentence).to include(error_message) if error_message.present? + end + end + end end context 'when using scopes' do diff --git a/spec/models/preloaders/merge_request_diff_preloader_spec.rb b/spec/models/preloaders/merge_request_diff_preloader_spec.rb index 9a76d42e73f..9ca5039c4e6 100644 --- a/spec/models/preloaders/merge_request_diff_preloader_spec.rb +++ b/spec/models/preloaders/merge_request_diff_preloader_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Preloaders::MergeRequestDiffPreloader do let_it_be(:merge_request_1) { create(:merge_request) } let_it_be(:merge_request_2) { create(:merge_request) } - let_it_be(:merge_request_3) { create(:merge_request_without_merge_request_diff) } + let_it_be(:merge_request_3) { create(:merge_request, :skip_diff_creation) } let(:merge_requests) { [merge_request_1, merge_request_2, merge_request_3] } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index d10a8afc51e..0e3382b4c6f 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe User, feature_category: :user_profile do + using RSpec::Parameterized::TableSyntax + include ProjectForksHelper include TermsHelper include ExclusiveLeaseHelpers @@ -4168,8 +4170,6 @@ RSpec.describe User, feature_category: :user_profile do end describe '#following_users_allowed?' do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be(:followee) { create(:user) } @@ -6021,27 +6021,42 @@ RSpec.describe User, feature_category: :user_profile do let(:user) { create(:user, note: "existing note") } let(:deleted_by) { create(:user) } - it 'blocks the user then schedules them for deletion if a hard delete is specified' do - expect(DeleteUserWorker).to receive(:perform_async).with(deleted_by.id, user.id, { hard_delete: true }) + shared_examples 'schedules user for deletion without delay' do + it 'schedules user for deletion without delay' do + expect(DeleteUserWorker).to receive(:perform_async).with(deleted_by.id, user.id, {}) + expect(DeleteUserWorker).not_to receive(:perform_in) + + user.delete_async(deleted_by: deleted_by) + end + end + + shared_examples 'it does not block the user' do + it 'does not block the user' do + user.delete_async(deleted_by: deleted_by) + expect(user).not_to be_blocked + end + end + + it 'blocks the user if hard delete is specified' do user.delete_async(deleted_by: deleted_by, params: { hard_delete: true }) expect(user).to be_blocked end - it 'schedules user for deletion without blocking them' do - expect(DeleteUserWorker).to receive(:perform_async).with(deleted_by.id, user.id, {}) - - user.delete_async(deleted_by: deleted_by) + it_behaves_like 'schedules user for deletion without delay' - expect(user).not_to be_blocked - end + it_behaves_like 'it does not block the user' context 'when target user is the same as deleted_by' do let(:deleted_by) { user } subject { user.delete_async(deleted_by: deleted_by) } + before do + allow(user).to receive(:has_possible_spam_contributions?).and_return(true) + end + shared_examples 'schedules the record for deletion with the correct delay' do it 'schedules the record for deletion with the correct delay' do freeze_time do @@ -6061,12 +6076,64 @@ RSpec.describe User, feature_category: :user_profile do expect(user).not_to be_banned end + context 'with possible spam contribution' do + context 'with comments' do + it_behaves_like 'schedules the record for deletion with the correct delay' do + before do + allow(user).to receive(:has_possible_spam_contributions?).and_call_original + + note = create(:note_on_issue, author: user) + create(:event, :commented, target: note, author: user) + end + end + end + + context 'with other types' do + where(:resource, :action, :delayed) do + 'Issue' | :created | true + 'MergeRequest' | :created | true + 'Issue' | :closed | false + 'MergeRequest' | :closed | false + 'WorkItem' | :created | false + end + + with_them do + before do + allow(user).to receive(:has_possible_spam_contributions?).and_call_original + + case resource + when 'Issue' + create(:event, action, :for_issue, author: user) + when 'MergeRequest' + create(:event, action, :for_merge_request, author: user) + when 'WorkItem' + create(:event, action, :for_work_item, author: user) + end + end + + if params[:delayed] + it_behaves_like 'schedules the record for deletion with the correct delay' + else + it_behaves_like 'schedules user for deletion without delay' + end + end + end + end + + context 'when user has no possible spam contributions' do + before do + allow(user).to receive(:has_possible_spam_contributions?).and_return(false) + end + + it_behaves_like 'schedules user for deletion without delay' + end + context 'when the user is a spammer' do before do allow(user).to receive(:spammer?).and_return(true) end - context 'when the user acount is less than 7 days old' do + context 'when the user account is less than 7 days old' do it_behaves_like 'schedules the record for deletion with the correct delay' it 'creates an abuse report with the correct data' do @@ -6140,13 +6207,9 @@ RSpec.describe User, feature_category: :user_profile do stub_feature_flags(delay_delete_own_user: false) end - it 'schedules user for deletion without blocking them' do - expect(DeleteUserWorker).to receive(:perform_async).with(user.id, user.id, {}) - - subject + it_behaves_like 'schedules user for deletion without delay' - expect(user).not_to be_blocked - end + it_behaves_like 'it does not block the user' it 'does not update the note' do expect { user.delete_async(deleted_by: deleted_by) }.not_to change { user.note } @@ -7303,8 +7366,6 @@ RSpec.describe User, feature_category: :user_profile do let(:user_id) { user.id } describe 'update user' do - using RSpec::Parameterized::TableSyntax - where(:attributes) do [ { state: 'blocked' }, |