OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/spec/models/project/storage_spec.rb

120 lines
4.3 KiB

#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe Project::Storage, type: :model do
let(:project1) {
FactoryGirl.create(:project)
.reload # Reload required for wiki association to be available
}
let(:project2) { FactoryGirl.create(:project) }
before do
allow(Setting).to receive(:enabled_scm).and_return(['git'])
wp = FactoryGirl.create(:work_package, project: project1)
FactoryGirl.create(:work_package, project: project1)
FactoryGirl.create_list(:attachment, 10, filesize: 250, container: wp)
wikipage = FactoryGirl.create(:wiki_page, wiki: project1.wiki)
FactoryGirl.create(:attachment, filesize: 10000, container: wikipage)
repo = FactoryGirl.create(:repository_git, project: project2)
repo.update_attributes(required_storage_bytes: 1234)
end
describe '#with_required_storage' do
it 'counts projects correctly' do
# TODO Using storage.find(project1.id) here causes work_package_required_space
# to be nil or "2500" (Postgres only) occasionally with no definitive solution found.
# The returned "2500" were pre-Rails4 behavior, thus this might be a Rails bug.
# Please test with 4.1/4.2
storage = Project.with_required_storage
p1 = storage.where(id: project1.id).first
p2 = storage.where(id: project2.id).first
expect(p1.work_package_required_space).to eq(2500)
expect(p1.repositories_required_space).to be_nil
expect(p1.required_disk_space).to eq(12500)
expect(p2.wiki_required_space).to be_nil
expect(p2.work_package_required_space).to be_nil
expect(p2.repositories_required_space).to eq(1234)
expect(p2.required_disk_space).to eq(1234)
end
it 'outputs the correct total amount' do
expect(Project.total_projects_size).to eq(13734)
end
context 'with a project with all modules' do
let(:repository1) { FactoryGirl.create(:repository_git, project: project1) }
before do
repository1.update_attributes(required_storage_bytes: 543211234)
end
it 'counts all projects correctly' do
project = Project.with_required_storage.find(project1.id)
expect(project.wiki_required_space).to eq(10000)
expect(project.work_package_required_space).to eq(2500)
expect(project.repositories_required_space).to eq(543211234)
expect(project.required_disk_space).to eq(543223734)
end
it 'outputs the correct total amount' do
expect(Project.total_projects_size).to eq(543224968)
end
end
end
describe '#count_required_storage' do
it 'provides a hash of the storage information' do
storage = project1.count_required_storage
expect(storage['total']).to eq(12500)
expect(storage['modules'].length).to eq(2)
expect(storage['modules']['project_module_wiki']).to eq(10000)
expect(storage['modules']['label_work_package_plural']).to eq(2500)
end
it 'works with partially available information' do
storage = project2.count_required_storage
expect(storage['total']).to eq(1234)
expect(storage['modules'].length).to eq(1)
expect(storage['modules']['label_repository']).to eq(1234)
end
end
end