Commit 981b6269 authored by Patricio Cano's avatar Patricio Cano

Added better tests, and corrected documentation.

parent 4ed495fb
...@@ -7,7 +7,7 @@ module LfsHelper ...@@ -7,7 +7,7 @@ module LfsHelper
render( render(
json: { json: {
message: 'Git LFS is not enabled on this GitLab server, contact your admin.', message: 'Git LFS is not enabled on this GitLab server, contact your admin.',
documentation_url: "#{Gitlab.config.gitlab.url}/help", documentation_url: help_url,
}, },
status: 501 status: 501
) )
......
# Repository size restrictions # Repository size restrictions
> **Note:** Introduced with 8.12 EE > Introduced with GitLab Enterprise Edition 8.12
Repositories within your GitLab instance can grow quickly, specially if you are Repositories within your GitLab instance can grow quickly, specially if you are
using LFS. Their size can grow exponentially and eat up your storage device quite using LFS. Their size can grow exponentially and eat up your storage device quite
...@@ -23,7 +23,7 @@ new issues, and clone the project. ...@@ -23,7 +23,7 @@ new issues, and clone the project.
Uploading LFS objects will also be denied. Uploading LFS objects will also be denied.
In order to lift this restrictions, the administrator of the GitLab instance In order to lift these restrictions, the administrator of the GitLab instance
needs to increase the limit on the particular project that exceeded it. needs to increase the limit on the particular project that exceeded it.
......
require 'spec_helper'
describe Gitlab::RepositorySizeError, lib: true do
let(:project) { create(:empty_project, repository_size: 15) }
let(:message) { Gitlab::RepositorySizeError.new(project) }
let(:base_message) { 'because this repository has exceeded its size limit of 10 MB by 5 MB' }
before do
allow(project).to receive(:actual_size_limit).and_return(10)
end
describe 'error messages' do
describe '#to_s' do
it 'returns the correct message' do
expect(message.to_s).to eq('The size of this repository (15 MB) exceeds the limit of 10 MB by 5 MB.')
end
end
describe '#commit_error' do
it 'returns the correct message' do
expect(message.commit_error).to eq("Your changes could not be committed, #{base_message}")
end
end
describe '#merge_error' do
it 'returns the correct message' do
expect(message.merge_error).to eq("This merge request cannot be merged, #{base_message}")
end
end
describe '#push_error' do
it 'returns the correct message' do
expect(message.push_error).to eq("Your push has been rejected, #{base_message}. #{message.more_info_message}")
end
end
describe '#new_changes_error' do
it 'returns the correct message' do
expect(message.new_changes_error).to eq("Your push to this repository would cause it to exceed the size limit of 10 MB so it has been rejected. #{message.more_info_message}")
end
end
end
end
...@@ -87,6 +87,18 @@ describe Namespace, models: true do ...@@ -87,6 +87,18 @@ describe Namespace, models: true do
end end
end end
describe '#actual_size_limit' do
let(:namespace) { build(:namespace) }
before do
allow_any_instance_of(ApplicationSetting).to receive(:repository_size_limit).and_return(50)
end
it 'returns the correct size limit' do
expect(namespace.actual_size_limit).to eq(50)
end
end
describe :rm_dir do describe :rm_dir do
let!(:project) { create(:project, namespace: namespace) } let!(:project) { create(:project, namespace: namespace) }
let!(:path) { File.join(Gitlab.config.repositories.storages.default, namespace.path) } let!(:path) { File.join(Gitlab.config.repositories.storages.default, namespace.path) }
......
...@@ -486,6 +486,15 @@ describe Project, models: true do ...@@ -486,6 +486,15 @@ describe Project, models: true do
allow_any_instance_of(ApplicationSetting).to receive(:repository_size_limit).and_return(50) allow_any_instance_of(ApplicationSetting).to receive(:repository_size_limit).and_return(50)
end end
describe '#changes_will_exceed_size_limit?' do
before do
allow(project).to receive(:repository_and_lfs_size).and_return(49)
end
it 'returns true when changes go over' do
expect(project.changes_will_exceed_size_limit?(5)).to be_truthy
end
end
describe '#actual_size_limit' do describe '#actual_size_limit' do
it 'returns the limit set in the application settings' do it 'returns the limit set in the application settings' do
expect(project.actual_size_limit).to eq(50) expect(project.actual_size_limit).to eq(50)
......
...@@ -38,6 +38,22 @@ describe MergeRequests::MergeService, services: true do ...@@ -38,6 +38,22 @@ describe MergeRequests::MergeService, services: true do
end end
end end
context 'project has exceeded size limit' do
let(:service) { MergeRequests::MergeService.new(project, user, commit_message: 'Awesome message') }
before do
allow(project).to receive(:above_size_limit?).and_return(true)
perform_enqueued_jobs do
service.execute(merge_request)
end
end
it 'returns the correct error message' do
expect(merge_request.merge_error).to include('This merge request cannot be merged')
end
end
context 'remove source branch by author' do context 'remove source branch by author' do
let(:service) do let(:service) do
merge_request.merge_params['force_remove_source_branch'] = '1' merge_request.merge_params['force_remove_source_branch'] = '1'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment