OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
replace legacy spec
ulfertsef872fc8a20a
diff --git a/spec/controllers/roles_controller_spec.rb b/spec/controllers/roles_controller_spec.rbindex 86723158a9a..88c784fb139 100644--- a/spec/controllers/roles_controller_spec.rb+++ b/spec/controllers/roles_controller_spec.rb@@ -43,9 +43,7 @@ describe RolesController, type: :controller do}end- before do- login_as(user)- end+ current_user { user }describe '#create' dolet(:new_role) { double('role double') }@@ -126,8 +124,8 @@ describe RolesController, type: :controller dolet(:service_call) { ServiceResult.failure(result: new_role) }it 'returns a 200 OK' do- expect(response.status)- .to be(200)+ expect(response)+ .to have_http_status(:ok)endit 'renders the new template' do@@ -209,8 +207,8 @@ describe RolesController, type: :controller dolet(:service_call) { ServiceResult.failure(result: role) }it 'returns a 200 OK' do- expect(response.status)- .to be(200)+ expect(response)+ .to have_http_status(:ok)endit 'renders the edit template' do@@ -352,8 +350,8 @@ describe RolesController, type: :controller dolet(:service_call2) { ServiceResult.failure(result: role2) }it 'returns a 200 OK' do- expect(response.status)- .to be(200)+ expect(response)+ .to have_http_status(:ok)endit 'renders the report template' do@@ -372,4 +370,91 @@ describe RolesController, type: :controller doendendend++ describe '#destroys' do+ let(:role) do+ build_stubbed(:role).tap do |d|+ allow(Role)+ .to receive(:find)+ .with(d.id.to_s)+ .and_return(d)++ allow(d)+ .to receive(:destroy)+ end+ end+ let(:params) { { id: role.id } }++ subject do+ delete :destroy, params:+ end++ context 'with the role not in use' do+ before { subject }++ it 'redirects' do+ expect(response)+ .to redirect_to roles_path+ end++ it 'destroys the role' do+ expect(role)+ .to have_received(:destroy)+ end+ end++ context 'with the role in use' do+ before do+ allow(role)+ .to receive(:destroy)+ .and_throw(:an_error)++ subject+ end++ it 'redirects' do+ expect(response)+ .to redirect_to roles_path+ end++ it 'sets a flash error' do+ expect(flash[:error])+ .to eq I18n.t(:error_can_not_remove_role)+ end+ end+ end++ describe '#report' do+ let!(:roles) do+ [build_stubbed(:role)].tap do |roles|+ allow(Role)+ .to receive(:order)+ .and_return(roles)+ end+ end++ before do+ delete :report+ end++ it 'is successful' do+ expect(response)+ .to have_http_status :ok+ end++ it 'renders the template' do+ expect(response)+ .to render_template :report+ end++ it 'assigns permissions' do+ expect(assigns(:permissions))+ .to match OpenProject::AccessControl.permissions.reject(&:public?)+ end++ it 'assigns roles' do+ expect(assigns(:roles))+ .to match roles+ end+ endenddiff --git a/spec/models/version_spec.rb b/spec/models/version_spec.rbindex b853c36185e..da9b3f6aae4 100644--- a/spec/models/version_spec.rb+++ b/spec/models/version_spec.rb@@ -33,12 +33,41 @@ describe Version, type: :model doit { is_expected.to be_valid }- it 'rejects a finish date that is smaller than the start date' do- version.start_date = '2013-05-01'- version.effective_date = '2012-01-01'+ describe 'default values' do+ let(:version) { described_class.new }- expect(version).not_to be_valid- expect(version.errors[:effective_date].size).to eq(1)+ it 'sets the status to be open' do+ expect(version.status)+ .to eq 'open'+ end+ end++ describe 'validations' do+ context 'with finish date that is smaller than the start date' do+ before do+ version.start_date = '2013-05-01'+ version.effective_date = '2012-01-01'+ end++ it 'is invalid' do+ expect(version).not_to be_valid+ expect(version.errors[:effective_date])+ .to eq [I18n.t('activerecord.errors.messages.greater_than_start_date')]+ end+ end++ context 'with an invalid date' do+ before do+ version.start_date = '2013-05-01'+ version.effective_date = '99999-01-01'+ end++ it 'is invalid' do+ expect(version).not_to be_valid+ expect(version.errors[:effective_date])+ .to eq [I18n.t('activerecord.errors.messages.not_a_date')]+ end+ endenddescribe '#to_s_for_project' do@@ -277,4 +306,69 @@ describe Version, type: :model doexpect(unshared_version.projects).to match_array([parent_project])endend++ describe '#estimated_hours' do+ before do+ version.save+ end++ context 'without assigned work packages' do+ it 'returns 0.0' do+ expect(version.estimated_hours)+ .to eq 0.0+ end+ end++ context 'with assigned work packages without estimated hours' do+ let!(:work_package) { create(:work_package, version:) }++ it 'returns 0.0' do+ expect(version.estimated_hours)+ .to eq 0.0+ end+ end++ context 'with two assigned work packages with estimated hours' do+ let!(:work_package1) { create(:work_package, version:, estimated_hours: 2.5) }+ let!(:work_package2) { create(:work_package, version:, estimated_hours: 5) }++ it 'returns the sum of estimated hours' do+ expect(version.estimated_hours)+ .to eq 7.5+ end+ end++ context 'with assigned work packages with estimated hours in the leaves' do+ let!(:parent) { create(:work_package, version:) }+ let!(:work_package1) { create(:work_package, parent:, version:, estimated_hours: 2.5) }+ let!(:work_package2) { create(:work_package, parent:, version:, estimated_hours: 5) }++ it 'returns the sum of estimated hours' do+ expect(version.estimated_hours)+ .to eq 7.5+ end+ end+ end++ describe '#start_date' do+ context 'with a value saved and a work package with its own start_date' do+ let(:version) { create(:version, start_date: '2010-01-05') }+ let!(:work_package) { create(:work_package, version:, start_date: '2010-03-01') }++ it 'is the value' do+ expect(version.start_date)+ .to eq Date.parse('2010-01-05')+ end+ end++ context 'without a value saved and a work package with its own start_date' do+ let(:version) { create(:version) }+ let!(:work_package) { create(:work_package, version:, start_date: '2010-03-01') }++ it 'is nil' do+ expect(version.start_date)+ .to be_nil+ end+ end+ endenddiff --git a/spec_legacy/functional/roles_controller_spec.rb b/spec_legacy/functional/roles_controller_spec.rbdeleted file mode 100644index 6b954262da9..00000000000--- a/spec_legacy/functional/roles_controller_spec.rb+++ /dev/null@@ -1,75 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2022 the OpenProject GmbH-#-# 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 COPYRIGHT and LICENSE files for more details.-#++-require_relative '../legacy_spec_helper'-require 'roles_controller'--describe RolesController, type: :controller do- render_views-- fixtures :all-- before do- User.current = nil- session[:user_id] = 1 # admin- end-- it 'destroys' do- r = Role.new(name: 'ToBeDestroyed', permissions: [:view_wiki_pages])- assert r.save-- delete :destroy, params: { id: r }- assert_redirected_to roles_path- assert_nil Role.find_by(id: r.id)- end-- it 'destroys role in use' do- delete :destroy, params: { id: 1 }- assert_redirected_to roles_path- assert flash[:error] == 'This role is in use and cannot be deleted.'- refute_nil Role.find_by(id: 1)- end-- it 'gets report' do- get :report- assert_response :success- assert_template 'report'-- refute_nil assigns(:roles)- assert_equal Role.order(Arel.sql('builtin, position')), assigns(:roles)-- assert_select 'input', attributes: { type: 'checkbox',- name: 'permissions[3][]',- value: 'add_work_packages',- checked: 'checked' }-- assert_select 'input', attributes: { type: 'checkbox',- name: 'permissions[3][]',- value: 'delete_work_packages',- checked: nil }- end-enddiff --git a/spec_legacy/unit/version_spec.rb b/spec_legacy/unit/version_spec.rbindex 12757bcb450..8f1ab58c6bd 100644--- a/spec_legacy/unit/version_spec.rb+++ b/spec_legacy/unit/version_spec.rb@@ -30,37 +30,6 @@ require_relative '../legacy_spec_helper'describe Version, type: :model dofixtures :all- it 'creates' do- (v = Version.new.tap do |v|- v.attributes = { project: Project.find(1), name: '1.1', effective_date: '2011-03-25' }- end)- assert v.save- assert_equal 'open', v.status- end-- it 'invalids effective date validation' do- (v = Version.new.tap do |v|- v.attributes = { project: Project.find(1), name: '1.1', effective_date: '99999-01-01' }- end)- assert !v.save- assert_includes v.errors[:effective_date], I18n.t('activerecord.errors.messages.not_a_date')- end-- describe '#start_date' do- context 'with a value saved' do- it 'is the value' do- project = Project.find(1)- (v = Version.new.tap do |v|- v.attributes = { project:, name: 'Progress', start_date: '2010-01-05' }- end).save!-- add_work_package(v, estimated_hours: 10, start_date: '2010-03-01')-- assert_equal '2010-01-05', v.start_date.to_s- end- end- end-it 'progresses should be 0 with no assigned issues' doproject = Project.find(1)(v = Version.new.tap do |v|@@ -145,36 +114,6 @@ describe Version, type: :model doassert_progress_equal 25.0 / 100.0 * 100, v.closed_percentend- describe '#estimated_hours' do- before do- (@version = Version.new.tap do |v|- v.attributes = { project_id: 1, name: '#estimated_hours' }- end).save!- end-- it 'returns 0 with no assigned issues' do- assert_equal 0, @version.estimated_hours- end-- it 'returns 0 with no estimated hours' do- add_work_package(@version)- assert_equal 0, @version.estimated_hours- end-- it 'returns the sum of estimated hours' do- add_work_package(@version, estimated_hours: 2.5)- add_work_package(@version, estimated_hours: 5)- assert_equal 7.5, @version.estimated_hours- end-- it 'returns the sum of leaves estimated hours' do- parent = add_work_package(@version)- add_work_package(@version, estimated_hours: 2.5, parent_id: parent.id)- add_work_package(@version, estimated_hours: 5, parent_id: parent.id)- assert_equal 7.5, @version.estimated_hours- end- end-privatedef add_work_package(version, attributes = {})