Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-15 09:10:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-15 09:10:17 +0300
commitd35de87f96f580fede92e6b43352fbff8316e2c3 (patch)
tree9b0ebb12a3ce148f35f1e05a3dba2675adc97f99 /spec
parent03c5d7f2c175acedafcb1b233ec1e40e9fcc8d1b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/groups_controller_spec.rb19
-rw-r--r--spec/controllers/projects_controller_spec.rb15
-rw-r--r--spec/factories/groups.rb7
-rw-r--r--spec/frontend/diffs/components/diff_stats_spec.js29
-rw-r--r--spec/frontend/diffs/mock_data/diff_file.js2
-rw-r--r--spec/frontend/diffs/utils/diff_file_spec.js78
-rw-r--r--spec/models/application_setting_spec.rb28
-rw-r--r--spec/models/commit_spec.rb86
-rw-r--r--spec/models/group_spec.rb12
-rw-r--r--spec/models/import_export_upload_spec.rb80
-rw-r--r--spec/models/project_spec.rb16
-rw-r--r--spec/requests/api/group_export_spec.rb17
-rw-r--r--spec/requests/api/merge_requests_spec.rb2
-rw-r--r--spec/requests/api/project_export_spec.rb13
-rw-r--r--spec/requests/api/settings_spec.rb4
15 files changed, 399 insertions, 9 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb
index 07d8332bfd0..91b11cd46c5 100644
--- a/spec/controllers/groups_controller_spec.rb
+++ b/spec/controllers/groups_controller_spec.rb
@@ -1065,14 +1065,13 @@ RSpec.describe GroupsController, factory_default: :keep do
describe 'GET #download_export' do
let(:admin) { create(:admin) }
+ let(:export_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
before do
enable_admin_mode!(admin)
end
context 'when there is a file available to download' do
- let(:export_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
-
before do
sign_in(admin)
create(:import_export_upload, group: group, export_file: export_file)
@@ -1085,6 +1084,22 @@ RSpec.describe GroupsController, factory_default: :keep do
end
end
+ context 'when the file is no longer present on disk' do
+ before do
+ sign_in(admin)
+
+ create(:import_export_upload, group: group, export_file: export_file)
+ group.export_file.file.delete
+ end
+
+ it 'returns not found' do
+ get :download_export, params: { id: group.to_param }
+
+ expect(flash[:alert]).to include('file containing the export is not available yet')
+ expect(response).to redirect_to(edit_group_path(group))
+ end
+ end
+
context 'when there is no file available to download' do
before do
sign_in(admin)
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 398aedfd8e2..ce229fb861a 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe ProjectsController do
include ProjectForksHelper
using RSpec::Parameterized::TableSyntax
- let_it_be(:project, reload: true) { create(:project, service_desk_enabled: false) }
+ let_it_be(:project, reload: true) { create(:project, :with_export, service_desk_enabled: false) }
let_it_be(:public_project) { create(:project, :public) }
let_it_be(:user) { create(:user) }
@@ -1349,7 +1349,7 @@ RSpec.describe ProjectsController do
end
end
- describe '#download_export' do
+ describe '#download_export', :clean_gitlab_redis_cache do
let(:action) { :download_export }
context 'object storage enabled' do
@@ -1361,6 +1361,17 @@ RSpec.describe ProjectsController do
end
end
+ context 'when project export file is absent' do
+ it 'alerts the user and returns 302' do
+ project.export_file.file.delete
+
+ get action, params: { namespace_id: project.namespace, id: project }
+
+ expect(flash[:alert]).to include('file containing the export is not available yet')
+ expect(response).to have_gitlab_http_status(:found)
+ end
+ end
+
context 'when project export is disabled' do
before do
stub_application_setting(project_export_enabled?: false)
diff --git a/spec/factories/groups.rb b/spec/factories/groups.rb
index 5d232a9d09a..bd6e37c1cef 100644
--- a/spec/factories/groups.rb
+++ b/spec/factories/groups.rb
@@ -58,6 +58,13 @@ FactoryBot.define do
shared_runners_enabled { false }
end
+ trait :with_export do
+ after(:create) do |group, _evaluator|
+ export_file = fixture_file_upload('spec/fixtures/group_export.tar.gz')
+ create(:import_export_upload, group: group, export_file: export_file)
+ end
+ end
+
trait :allow_descendants_override_disabled_shared_runners do
allow_descendants_override_disabled_shared_runners { true }
end
diff --git a/spec/frontend/diffs/components/diff_stats_spec.js b/spec/frontend/diffs/components/diff_stats_spec.js
index 504158fb7fc..52e68b35889 100644
--- a/spec/frontend/diffs/components/diff_stats_spec.js
+++ b/spec/frontend/diffs/components/diff_stats_spec.js
@@ -1,6 +1,7 @@
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import DiffStats from '~/diffs/components/diff_stats.vue';
+import mockDiffFile from '../mock_data/diff_file';
const TEST_ADDED_LINES = 100;
const TEST_REMOVED_LINES = 200;
@@ -38,9 +39,37 @@ describe('diff_stats', () => {
});
});
+ describe('bytes changes', () => {
+ let file;
+ const getBytesContainer = () => wrapper.find('.diff-stats > div:first-child');
+
+ beforeEach(() => {
+ file = {
+ ...mockDiffFile,
+ viewer: {
+ ...mockDiffFile.viewer,
+ name: 'not_diffable',
+ },
+ };
+
+ createComponent({ diffFile: file });
+ });
+
+ it("renders the bytes changes instead of line changes when the file isn't diffable", () => {
+ const content = getBytesContainer();
+
+ expect(content.classes('cgreen')).toBe(true);
+ expect(content.text()).toBe('+1.00 KiB (+100%)');
+ });
+ });
+
describe('line changes', () => {
const findFileLine = (name) => wrapper.find(name);
+ beforeEach(() => {
+ createComponent();
+ });
+
it('shows the amount of lines added', () => {
expect(findFileLine('.js-file-addition-line').text()).toBe(TEST_ADDED_LINES.toString());
});
diff --git a/spec/frontend/diffs/mock_data/diff_file.js b/spec/frontend/diffs/mock_data/diff_file.js
index cef776c885a..9ebcd5ef26b 100644
--- a/spec/frontend/diffs/mock_data/diff_file.js
+++ b/spec/frontend/diffs/mock_data/diff_file.js
@@ -19,6 +19,8 @@ export default {
renamed_file: false,
old_path: 'CHANGELOG',
new_path: 'CHANGELOG',
+ old_size: 1024,
+ new_size: 2048,
mode_changed: false,
a_mode: '100644',
b_mode: '100644',
diff --git a/spec/frontend/diffs/utils/diff_file_spec.js b/spec/frontend/diffs/utils/diff_file_spec.js
index c6cfdfced65..ba9130966b9 100644
--- a/spec/frontend/diffs/utils/diff_file_spec.js
+++ b/spec/frontend/diffs/utils/diff_file_spec.js
@@ -1,4 +1,11 @@
-import { prepareRawDiffFile, getShortShaFromFile } from '~/diffs/utils/diff_file';
+import {
+ prepareRawDiffFile,
+ getShortShaFromFile,
+ stats,
+ isNotDiffable,
+} from '~/diffs/utils/diff_file';
+import { diffViewerModes } from '~/ide/constants';
+import mockDiffFile from '../mock_data/diff_file';
function getDiffFiles() {
const loadFull = 'namespace/project/-/merge_requests/12345/diff_for_path?file_identifier=abc';
@@ -154,4 +161,73 @@ describe('diff_file utilities', () => {
expect(getShortShaFromFile({ content_sha: cs })).toBe(response);
});
});
+
+ describe('stats', () => {
+ const noFile = [
+ "returns empty stats when the file isn't provided",
+ undefined,
+ {
+ text: '',
+ percent: 0,
+ changed: 0,
+ classes: '',
+ sign: '',
+ valid: false,
+ },
+ ];
+ const validFile = [
+ 'computes the correct stats from a file',
+ mockDiffFile,
+ {
+ changed: 1024,
+ percent: 100,
+ classes: 'cgreen',
+ sign: '+',
+ text: '+1.00 KiB (+100%)',
+ valid: true,
+ },
+ ];
+ const negativeChange = [
+ 'computed the correct states from a file with a negative size change',
+ {
+ ...mockDiffFile,
+ new_size: 0,
+ old_size: 1024,
+ },
+ {
+ changed: -1024,
+ percent: -100,
+ classes: 'cred',
+ sign: '',
+ text: '-1.00 KiB (-100%)',
+ valid: true,
+ },
+ ];
+
+ it.each([noFile, validFile, negativeChange])('%s', (_, file, output) => {
+ expect(stats(file)).toEqual(output);
+ });
+ });
+
+ describe('isNotDiffable', () => {
+ it.each`
+ bool | vw
+ ${true} | ${diffViewerModes.not_diffable}
+ ${false} | ${diffViewerModes.text}
+ ${false} | ${diffViewerModes.image}
+ `('returns $bool when the viewer is $vw', ({ bool, vw }) => {
+ expect(isNotDiffable({ viewer: { name: vw } })).toBe(bool);
+ });
+
+ it.each`
+ file
+ ${undefined}
+ ${null}
+ ${{}}
+ ${{ viewer: undefined }}
+ ${{ viewer: null }}
+ `('reports `false` when the file is `$file`', ({ file }) => {
+ expect(isNotDiffable(file)).toBe(false);
+ });
+ });
});
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index c13d83d1685..4e72d558b52 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -990,6 +990,34 @@ RSpec.describe ApplicationSetting do
end
end
end
+
+ describe '#diff_max_files' do
+ context 'validations' do
+ it { is_expected.to validate_presence_of(:diff_max_files) }
+
+ specify do
+ is_expected
+ .to validate_numericality_of(:diff_max_files)
+ .only_integer
+ .is_greater_than_or_equal_to(Commit::DEFAULT_MAX_DIFF_FILES_SETTING)
+ .is_less_than_or_equal_to(Commit::MAX_DIFF_FILES_SETTING_UPPER_BOUND)
+ end
+ end
+ end
+
+ describe '#diff_max_lines' do
+ context 'validations' do
+ it { is_expected.to validate_presence_of(:diff_max_lines) }
+
+ specify do
+ is_expected
+ .to validate_numericality_of(:diff_max_lines)
+ .only_integer
+ .is_greater_than_or_equal_to(Commit::DEFAULT_MAX_DIFF_LINES_SETTING)
+ .is_less_than_or_equal_to(Commit::MAX_DIFF_LINES_SETTING_UPPER_BOUND)
+ end
+ end
+ end
end
describe '#sourcegraph_url_is_com?' do
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 693e754c53d..8ffc198fc4d 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -672,6 +672,92 @@ eos
it_behaves_like '#uri_type'
end
+ describe '.diff_max_files' do
+ subject(:diff_max_files) { described_class.diff_max_files }
+
+ let(:increased_diff_limits) { false }
+ let(:configurable_diff_limits) { false }
+
+ before do
+ stub_feature_flags(increased_diff_limits: increased_diff_limits, configurable_diff_limits: configurable_diff_limits)
+ end
+
+ context 'when increased_diff_limits is enabled' do
+ let(:increased_diff_limits) { true }
+
+ it 'returns 3000' do
+ expect(diff_max_files).to eq(3000)
+ end
+ end
+
+ context 'when configurable_diff_limits is enabled' do
+ let(:configurable_diff_limits) { true }
+
+ it 'returns the current settings' do
+ Gitlab::CurrentSettings.update!(diff_max_files: 1234)
+ expect(diff_max_files).to eq(1234)
+ end
+ end
+
+ context 'when neither feature flag is enabled' do
+ it 'returns 1000' do
+ expect(diff_max_files).to eq(1000)
+ end
+ end
+ end
+
+ describe '.diff_max_lines' do
+ subject(:diff_max_lines) { described_class.diff_max_lines }
+
+ let(:increased_diff_limits) { false }
+ let(:configurable_diff_limits) { false }
+
+ before do
+ stub_feature_flags(increased_diff_limits: increased_diff_limits, configurable_diff_limits: configurable_diff_limits)
+ end
+
+ context 'when increased_diff_limits is enabled' do
+ let(:increased_diff_limits) { true }
+
+ it 'returns 100000' do
+ expect(diff_max_lines).to eq(100000)
+ end
+ end
+
+ context 'when configurable_diff_limits is enabled' do
+ let(:configurable_diff_limits) { true }
+
+ it 'returns the current settings' do
+ Gitlab::CurrentSettings.update!(diff_max_lines: 65321)
+ expect(diff_max_lines).to eq(65321)
+ end
+ end
+
+ context 'when neither feature flag is enabled' do
+ it 'returns 50000' do
+ expect(diff_max_lines).to eq(50000)
+ end
+ end
+ end
+
+ describe '.diff_safe_max_files' do
+ subject(:diff_safe_max_files) { described_class.diff_safe_max_files }
+
+ it 'returns the commit diff max divided by the limit factor of 10' do
+ expect(::Commit).to receive(:diff_max_files).and_return(10)
+ expect(diff_safe_max_files).to eq(1)
+ end
+ end
+
+ describe '.diff_safe_max_lines' do
+ subject(:diff_safe_max_lines) { described_class.diff_safe_max_lines }
+
+ it 'returns the commit diff max divided by the limit factor of 10' do
+ expect(::Commit).to receive(:diff_max_lines).and_return(100)
+ expect(diff_safe_max_lines).to eq(10)
+ end
+ end
+
describe '.from_hash' do
subject { described_class.from_hash(commit.to_hash, container) }
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index c8acc85cfd9..c2bc581d519 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -2613,4 +2613,16 @@ RSpec.describe Group do
expect(group.activity_path).to eq(expected_path)
end
end
+
+ context 'with export' do
+ let(:group) { create(:group, :with_export) }
+
+ it '#export_file_exists returns true' do
+ expect(group.export_file_exists?).to be true
+ end
+
+ it '#export_archive_exists? returns true' do
+ expect(group.export_archive_exists?).to be true
+ end
+ end
end
diff --git a/spec/models/import_export_upload_spec.rb b/spec/models/import_export_upload_spec.rb
index f82c8da379f..e13f504b82a 100644
--- a/spec/models/import_export_upload_spec.rb
+++ b/spec/models/import_export_upload_spec.rb
@@ -3,7 +3,9 @@
require 'spec_helper'
RSpec.describe ImportExportUpload do
- subject { described_class.new(project: create(:project)) }
+ let(:project) { create(:project) }
+
+ subject { described_class.new(project: project) }
shared_examples 'stores the Import/Export file' do |method|
it 'stores the import file' do
@@ -43,4 +45,80 @@ RSpec.describe ImportExportUpload do
end
end
end
+
+ context 'ActiveRecord callbacks' do
+ let(:after_save_callbacks) { described_class._save_callbacks.select { |cb| cb.kind == :after } }
+ let(:after_commit_callbacks) { described_class._commit_callbacks.select { |cb| cb.kind == :after } }
+
+ def find_callback(callbacks, key)
+ callbacks.find { |cb| cb.instance_variable_get(:@key) == key }
+ end
+
+ it 'export file is stored in after_commit callback' do
+ expect(find_callback(after_commit_callbacks, :store_export_file!)).to be_present
+ expect(find_callback(after_save_callbacks, :store_export_file!)).to be_nil
+ end
+
+ it 'import file is stored in after_save callback' do
+ expect(find_callback(after_save_callbacks, :store_import_file!)).to be_present
+ expect(find_callback(after_commit_callbacks, :store_import_file!)).to be_nil
+ end
+ end
+
+ describe 'export file' do
+ it '#export_file_exists? returns false' do
+ expect(subject.export_file_exists?).to be false
+ end
+
+ it '#export_archive_exists? returns false' do
+ expect(subject.export_archive_exists?).to be false
+ end
+
+ context 'with export' do
+ let(:project_with_export) { create(:project, :with_export) }
+
+ subject { described_class.with_export_file.find_by(project: project_with_export) }
+
+ it '#export_file_exists? returns true' do
+ expect(subject.export_file_exists?).to be true
+ end
+
+ it '#export_archive_exists? returns false' do
+ expect(subject.export_archive_exists?).to be true
+ end
+
+ context 'when object file does not exist' do
+ before do
+ subject.export_file.file.delete
+ end
+
+ it '#export_file_exists? returns true' do
+ expect(subject.export_file_exists?).to be true
+ end
+
+ it '#export_archive_exists? returns false' do
+ expect(subject.export_archive_exists?).to be false
+ end
+ end
+
+ context 'when checking object existence raises a error' do
+ let(:exception) { Excon::Error::Forbidden.new('not allowed') }
+
+ before do
+ file = double
+ allow(file).to receive(:exists?).and_raise(exception)
+ allow(subject).to receive(:carrierwave_export_file).and_return(file)
+ end
+
+ it '#export_file_exists? returns true' do
+ expect(subject.export_file_exists?).to be true
+ end
+
+ it '#export_archive_exists? returns false' do
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(exception)
+ expect(subject.export_archive_exists?).to be false
+ end
+ end
+ end
+ end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 242d5947d26..e012fcac810 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -4376,6 +4376,18 @@ RSpec.describe Project, factory_default: :keep do
end
end
+ context 'with export' do
+ let(:project) { create(:project, :with_export) }
+
+ it '#export_file_exists? returns true' do
+ expect(project.export_file_exists?).to be true
+ end
+
+ it '#export_archive_exists? returns false' do
+ expect(project.export_archive_exists?).to be true
+ end
+ end
+
describe '#forks_count' do
it 'returns the number of forks' do
project = build(:project)
@@ -6638,7 +6650,7 @@ RSpec.describe Project, factory_default: :keep do
context 'when project export is completed' do
before do
finish_job(project_export_job)
- allow(project).to receive(:export_file).and_return(double(ImportExportUploader, file: 'exists.zip'))
+ allow(project).to receive(:export_file_exists?).and_return(true)
end
it { expect(project.export_status).to eq :finished }
@@ -6649,7 +6661,7 @@ RSpec.describe Project, factory_default: :keep do
before do
finish_job(project_export_job)
- allow(project).to receive(:export_file).and_return(double(ImportExportUploader, file: 'exists.zip'))
+ allow(project).to receive(:export_file_exists?).and_return(true)
end
it { expect(project.export_status).to eq :regeneration_in_progress }
diff --git a/spec/requests/api/group_export_spec.rb b/spec/requests/api/group_export_spec.rb
index ee88d1eb1e9..31eef21654a 100644
--- a/spec/requests/api/group_export_spec.rb
+++ b/spec/requests/api/group_export_spec.rb
@@ -64,6 +64,23 @@ RSpec.describe API::GroupExport do
expect(response).to have_gitlab_http_status(:not_found)
end
end
+
+ context 'when object is not present' do
+ let(:other_group) { create(:group, :with_export) }
+ let(:other_download_path) { "/groups/#{other_group.id}/export/download" }
+
+ before do
+ other_group.add_owner(user)
+ other_group.export_file.file.delete
+ end
+
+ it 'returns 404' do
+ get api(other_download_path, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('The group export file is not available yet')
+ end
+ end
end
context 'when export file does not exist' do
diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb
index eb6e78aeda2..038c3bc552a 100644
--- a/spec/requests/api/merge_requests_spec.rb
+++ b/spec/requests/api/merge_requests_spec.rb
@@ -1353,7 +1353,7 @@ RSpec.describe API::MergeRequests do
context 'when a merge request has more than the changes limit' do
it "returns a string indicating that more changes were made" do
- allow(Commit).to receive(:diff_hard_limit_files).and_return(5)
+ allow(Commit).to receive(:diff_max_files).and_return(5)
merge_request_overflow = create(:merge_request, :simple,
author: user,
diff --git a/spec/requests/api/project_export_spec.rb b/spec/requests/api/project_export_spec.rb
index ac24aeee52c..06f4475ef79 100644
--- a/spec/requests/api/project_export_spec.rb
+++ b/spec/requests/api/project_export_spec.rb
@@ -196,6 +196,19 @@ RSpec.describe API::ProjectExport, :clean_gitlab_redis_cache do
end
end
+ context 'when export object is not present' do
+ before do
+ project_after_export.export_file.file.delete
+ end
+
+ it 'returns 404' do
+ get api(download_path_export_action, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ expect(json_response['message']).to eq('The project export file is not available yet')
+ end
+ end
+
context 'when upload complete' do
before do
project_after_export.remove_exports
diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb
index 66c0dcaa36c..4a4aeaea714 100644
--- a/spec/requests/api/settings_spec.rb
+++ b/spec/requests/api/settings_spec.rb
@@ -113,6 +113,8 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do
terms: 'Hello world!',
performance_bar_allowed_group_path: group.full_path,
diff_max_patch_bytes: 300_000,
+ diff_max_files: 2000,
+ diff_max_lines: 50000,
default_branch_protection: ::Gitlab::Access::PROTECTION_DEV_CAN_MERGE,
local_markdown_version: 3,
allow_local_requests_from_web_hooks_and_services: true,
@@ -159,6 +161,8 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do
expect(json_response['terms']).to eq('Hello world!')
expect(json_response['performance_bar_allowed_group_id']).to eq(group.id)
expect(json_response['diff_max_patch_bytes']).to eq(300_000)
+ expect(json_response['diff_max_files']).to eq(2000)
+ expect(json_response['diff_max_lines']).to eq(50000)
expect(json_response['default_branch_protection']).to eq(Gitlab::Access::PROTECTION_DEV_CAN_MERGE)
expect(json_response['local_markdown_version']).to eq(3)
expect(json_response['allow_local_requests_from_web_hooks_and_services']).to eq(true)