Commit 930b098c authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Save repository size limit as Bytes before saving it

parent 3b8daba1
...@@ -2,6 +2,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -2,6 +2,7 @@ class ApplicationSetting < ActiveRecord::Base
include CacheMarkdownField include CacheMarkdownField
include TokenAuthenticatable include TokenAuthenticatable
prepend EE::ApplicationSetting prepend EE::ApplicationSetting
include RepositorySizeLimit
add_authentication_token_field :runners_registration_token add_authentication_token_field :runners_registration_token
add_authentication_token_field :health_check_access_token add_authentication_token_field :health_check_access_token
......
module RepositorySizeLimit
extend ActiveSupport::Concern
included do
before_save :convert_from_megabytes_to_bytes, if: :repository_size_limit_changed?
end
private
def convert_from_megabytes_to_bytes
self.repository_size_limit = (repository_size_limit * 1.megabyte) if repository_size_limit.present?
end
end
...@@ -9,6 +9,7 @@ class Group < Namespace ...@@ -9,6 +9,7 @@ class Group < Namespace
include AccessRequestable include AccessRequestable
include Referable include Referable
include SelectForProjectAuthorization include SelectForProjectAuthorization
include RepositorySizeLimit
prepend EE::GeoAwareAvatar prepend EE::GeoAwareAvatar
has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source has_many :group_members, -> { where(requested_at: nil) }, dependent: :destroy, as: :source
......
...@@ -17,6 +17,7 @@ class Project < ActiveRecord::Base ...@@ -17,6 +17,7 @@ class Project < ActiveRecord::Base
include ProjectFeaturesCompatibility include ProjectFeaturesCompatibility
include SelectForProjectAuthorization include SelectForProjectAuthorization
include Routable include Routable
include RepositorySizeLimit
prepend EE::GeoAwareAvatar prepend EE::GeoAwareAvatar
prepend EE::Project prepend EE::Project
......
require 'spec_helper'
describe RepositorySizeLimit do
context Project do
context 'callback' do
describe '#convert_from_megabyte_to_byte' do
let(:project) { build(:empty_project, repository_size_limit: 10) }
before do
project.update!(repository_size_limit: repository_size_limit)
project.reload
end
context 'when repository_size_limit is present and have changed' do
let(:repository_size_limit) { 20 }
it { expect(project.repository_size_limit).to eql(20 * 1.megabyte) }
end
context 'when repository_size_limit is present but have not changed' do
let(:repository_size_limit) { 10 }
it { expect(project.repository_size_limit).to eql(10 * 1.megabyte) }
end
context 'when repository_size_limit is not present' do
let(:repository_size_limit) { nil }
it { expect(project.repository_size_limit).to be_nil }
end
end
end
end
context Group do
context 'callback' do
describe '#convert_from_megabyte_to_byte' do
let(:group) { build(:group, repository_size_limit: 10) }
before do
group.update!(repository_size_limit: repository_size_limit)
group.reload
end
context 'when repository_size_limit is present and have changed' do
let(:repository_size_limit) { 20 }
it { expect(group.repository_size_limit).to eql(20 * 1.megabyte) }
end
context 'when repository_size_limit is present but have not changed' do
let(:repository_size_limit) { 10 }
it { expect(group.repository_size_limit).to eql(10 * 1.megabyte) }
end
context 'when repository_size_limit is not present' do
let(:repository_size_limit) { nil }
it { expect(group.repository_size_limit).to be_nil }
end
end
end
end
context ApplicationSetting do
context 'callback' do
describe '#convert_from_megabyte_to_byte' do
let(:setting) { ApplicationSetting.create_from_defaults }
before do
setting.update!(repository_size_limit: 10)
setting.update!(repository_size_limit: repository_size_limit)
setting.reload
end
context 'when repository_size_limit is present and have changed' do
let(:repository_size_limit) { 20 }
it { expect(setting.repository_size_limit).to eql(20 * 1.megabyte) }
end
context 'when repository_size_limit is present but have not changed' do
let(:repository_size_limit) { 10 }
it { expect(setting.repository_size_limit).to eql(10 * 1.megabyte) }
end
end
end
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