Commit 3b8daba1 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Properly convert values to deal with Bytes

parent aedac4e8
......@@ -136,7 +136,7 @@ module LfsRequest
size_of_objects = objects.sum { |o| o[:size] }
@limit_exceeded = (project.repository_and_lfs_size + size_of_objects.to_mb) > project.actual_size_limit
@limit_exceeded = (project.repository_and_lfs_size + size_of_objects) > project.actual_size_limit
end
end
......
......@@ -1541,8 +1541,10 @@ class Project < ActiveRecord::Base
actual_size_limit != 0
end
def changes_will_exceed_size_limit?(size_mb)
size_limit_enabled? && (size_mb > actual_size_limit || size_mb + repository_and_lfs_size > actual_size_limit)
def changes_will_exceed_size_limit?(size_in_bytes)
size_limit_enabled? &&
(size_in_bytes > actual_size_limit ||
size_in_bytes + repository_and_lfs_size > actual_size_limit)
end
def environments_for(ref, commit: nil, with_tags: false)
......
......@@ -185,7 +185,7 @@ module Gitlab
end
end
if project.changes_will_exceed_size_limit?(push_size_in_bytes.to_mb)
if project.changes_will_exceed_size_limit?(push_size_in_bytes)
raise UnauthorizedError, Gitlab::RepositorySizeError.new(project).new_changes_error
end
end
......
......@@ -55,7 +55,7 @@ module Gitlab
end
def format_number(number)
number_to_human_size(number * 1.megabyte, delimiter: ',', precision: 2)
number_to_human_size(number, delimiter: ',', precision: 2)
end
end
end
......@@ -2,14 +2,14 @@ require 'spec_helper'
describe Gitlab::RepositorySizeError, lib: true do
let(:project) do
create(:empty_project, statistics: build(:project_statistics, repository_size: 15))
create(:empty_project, statistics: build(:project_statistics, repository_size: 15.megabytes))
end
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)
allow(project).to receive(:actual_size_limit).and_return(10.megabytes)
end
describe 'error messages' do
......
......@@ -573,13 +573,13 @@ describe Project, models: true do
group = create(:group, repository_size_limit: 100)
project.update_attribute(:namespace_id, group.id)
expect(project.actual_size_limit).to eq(100)
expect(project.actual_size_limit).to eq(100.megabytes)
end
it 'returns the value set locally' do
project.update_attribute(:repository_size_limit, 75)
expect(project.actual_size_limit).to eq(75)
expect(project.actual_size_limit).to eq(75.megabytes)
end
end
......
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