Skip to content

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

move specs on templated into main spec structure

ulfertsae0e4af967e7
diff --git a/spec/contracts/projects/base_contract_spec.rb b/spec/contracts/projects/base_contract_spec.rb
deleted file mode 100644
index 7d87c4efef9..00000000000
--- a/spec/contracts/projects/base_contract_spec.rb
+++ /dev/null
@@ -1,70 +0,0 @@
-# frozen_string_literal: true
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 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 "spec_helper"
-require_relative "shared_contract_examples"
-
-RSpec.describe Projects::BaseContract do
- let(:project) { Project.new(name: "Foo", identifier: "foo", templated: false) }
- let(:contract) { described_class.new(project, current_user) }
-
- subject { contract.validate }
-
- describe "templated attribute" do
- before do
- # Assume the user may manage the project
- allow(contract)
- .to(receive(:validate_user_allowed_to_manage))
- .and_return true
-
- # Assume templated attribute got changed
- project.templated = true
- expect(project.templated_changed?).to be true
- end
-
- context "as admin" do
- let(:current_user) { build_stubbed(:admin) }
-
- it "validates the contract" do
- expect(subject).to be true
- end
- end
-
- context "as regular user" do
- let(:current_user) { build_stubbed(:user) }
-
- it "returns an error on validation" do
- expect(subject).to be false
- expect(contract.errors.symbols_for(:templated))
- .to contain_exactly(:error_unauthorized)
- end
- end
- end
-end
diff --git a/spec/contracts/projects/create_contract_spec.rb b/spec/contracts/projects/create_contract_spec.rb
index c9253a92d0d..a10016e3f20 100644
--- a/spec/contracts/projects/create_contract_spec.rb
+++ b/spec/contracts/projects/create_contract_spec.rb
@@ -42,6 +42,7 @@ RSpec.describe Projects::CreateContract do
parent: project_parent,
status_code: project_status_code,
status_explanation: project_status_explanation,
+ templated: project_templated,
workspace_type: project_workspace_type)
end
let(:global_permissions) { %i[add_project add_portfolios] }
diff --git a/spec/contracts/projects/shared_contract_examples.rb b/spec/contracts/projects/shared_contract_examples.rb
index a1473007e92..d076559019d 100644
--- a/spec/contracts/projects/shared_contract_examples.rb
+++ b/spec/contracts/projects/shared_contract_examples.rb
@@ -53,6 +53,7 @@ RSpec.shared_examples_for "project contract" do
let(:project_status_code) { "on_track" }
let(:project_status_explanation) { "some explanation" }
let(:project_workspace_type) { "project" }
+ let(:project_templated) { false }
let(:project_parent) do
build_stubbed(:project)
end
@@ -201,6 +202,19 @@ RSpec.shared_examples_for "project contract" do
it_behaves_like "contract is invalid", identifier: %i(exclusion)
end
+ context "when changing templated as an admin" do
+ let(:current_user) { build_stubbed(:admin) }
+ let(:project_templated) { true }
+
+ it_behaves_like "contract is valid"
+ end
+
+ context "when changing templated as a user" do
+ let(:project_templated) { true }
+
+ it_behaves_like "contract is invalid", templated: %i(error_unauthorized)
+ end
+
context "if the user lacks permission" do
let(:global_permissions) { [] }
let(:project_permissions) { [] }
diff --git a/spec/contracts/projects/update_contract_spec.rb b/spec/contracts/projects/update_contract_spec.rb
index 4d576e8fe75..45cb20f0671 100644
--- a/spec/contracts/projects/update_contract_spec.rb
+++ b/spec/contracts/projects/update_contract_spec.rb
@@ -57,6 +57,7 @@ RSpec.describe Projects::UpdateContract do
p.name = project_name
p.parent = project_parent
p.identifier = project_identifier
+ p.templated = project_templated
end
end
let(:project_permissions) { %i(edit_project) }