2025-05-05 09:29:55 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2013-06-05 16:27:56 +02:00
|
|
|
#-- copyright
|
2020-01-15 11:31:26 +01:00
|
|
|
# OpenProject is an open source project management software.
|
2024-07-30 13:42:36 +02:00
|
|
|
# Copyright (C) the OpenProject GmbH
|
2013-06-05 16:27:56 +02:00
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License version 3.
|
|
|
|
|
#
|
2013-09-16 17:59:31 +02:00
|
|
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
2021-01-13 17:47:45 +01:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2013-09-16 17:59:31 +02:00
|
|
|
# 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.
|
|
|
|
|
#
|
2021-09-02 21:49:06 +02:00
|
|
|
# See COPYRIGHT and LICENSE files for more details.
|
2013-06-05 16:27:56 +02:00
|
|
|
#++
|
|
|
|
|
|
2013-05-14 13:31:47 +02:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
2023-05-31 12:15:15 +02:00
|
|
|
RSpec.describe VersionsController do
|
2022-01-24 19:22:35 +01:00
|
|
|
let(:user) { create(:admin) }
|
|
|
|
|
let(:project) { create(:public_project) }
|
|
|
|
|
let(:version1) { create(:version, project:, effective_date: nil) }
|
|
|
|
|
let(:version2) { create(:version, project:) }
|
|
|
|
|
let(:version3) { create(:version, project:, effective_date: (Date.today - 14.days)) }
|
2013-05-14 13:31:47 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#index" do
|
2013-05-14 13:31:47 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
version1
|
|
|
|
|
version2
|
|
|
|
|
version3
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
context "without additional params" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
get :index, params: { project_id: project.id }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2018-11-23 15:06:32 +01:00
|
|
|
it { expect(response).to be_successful }
|
2014-11-03 23:43:33 +01:00
|
|
|
it { expect(response).to render_template("index") }
|
2013-05-14 13:31:47 +02:00
|
|
|
|
|
|
|
|
subject { assigns(:versions) }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "shows Version with no date set" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version1)).to be_truthy
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "shows Version with date set" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version2)).to be_truthy
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "not shows Completed version" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version3)).to be_falsey
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2019-05-29 10:12:49 +01:00
|
|
|
context "with showing selected types" do
|
2023-03-07 15:04:32 +01:00
|
|
|
let(:type_a) { create(:type) }
|
|
|
|
|
let(:type_b) { create(:type) }
|
2019-05-29 10:12:49 +01:00
|
|
|
|
2023-03-07 15:04:32 +01:00
|
|
|
let(:wp_a) { create(:work_package, type: type_a, project:, version: version1) }
|
|
|
|
|
let(:wp_b) { create(:work_package, type: type_b, project:, version: version1) }
|
2019-05-29 10:12:49 +01:00
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
project.types = [type_a, type_b]
|
|
|
|
|
project.save!
|
|
|
|
|
|
|
|
|
|
[wp_a, wp_b] # create work packages
|
|
|
|
|
|
|
|
|
|
login_as(user)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with all types" do
|
|
|
|
|
before do
|
|
|
|
|
get :index, params: { project_id: project, completed: "1" }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response).to be_successful }
|
|
|
|
|
it { expect(response).to render_template("index") }
|
|
|
|
|
|
|
|
|
|
it "shows all work packages" do
|
2020-03-25 14:39:27 +01:00
|
|
|
issues_by_version = assigns(:wps_by_version)
|
2019-05-29 10:12:49 +01:00
|
|
|
work_packages = issues_by_version[version1]
|
|
|
|
|
|
|
|
|
|
expect(work_packages).to include wp_a
|
|
|
|
|
expect(work_packages).to include wp_b
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe "with selected types" do
|
|
|
|
|
before do
|
|
|
|
|
get :index, params: { project_id: project, completed: "1", type_ids: [type_b.id] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { expect(response).to be_successful }
|
|
|
|
|
it { expect(response).to render_template("index") }
|
|
|
|
|
|
|
|
|
|
it "shows only work packages of the selected type" do
|
2020-03-25 14:39:27 +01:00
|
|
|
issues_by_version = assigns(:wps_by_version)
|
2019-05-29 10:12:49 +01:00
|
|
|
work_packages = issues_by_version[version1]
|
|
|
|
|
|
|
|
|
|
expect(work_packages).not_to include wp_a
|
|
|
|
|
expect(work_packages).to include wp_b
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
context "with showing completed versions" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
get :index, params: { project_id: project, completed: "1" }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2018-11-23 15:06:32 +01:00
|
|
|
it { expect(response).to be_successful }
|
2014-11-03 23:43:33 +01:00
|
|
|
it { expect(response).to render_template("index") }
|
2013-05-14 13:31:47 +02:00
|
|
|
|
|
|
|
|
subject { assigns(:versions) }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "shows Version with no date set" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version1)).to be_truthy
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "shows Version with date set" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version2)).to be_truthy
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "not shows Completed version" do
|
2014-04-17 23:35:32 +02:00
|
|
|
expect(subject.include?(version3)).to be_truthy
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-08-09 15:01:15 -05:00
|
|
|
describe "Sub Project Versions" do
|
|
|
|
|
let!(:sub_project) { create(:public_project, parent_id: project.id) }
|
|
|
|
|
let!(:sub_project_version) { create(:version, project: sub_project) }
|
|
|
|
|
|
|
|
|
|
current_user { user }
|
2013-05-14 13:31:47 +02:00
|
|
|
|
|
|
|
|
before do
|
2023-08-09 15:01:15 -05:00
|
|
|
get :index, params:
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
subject { assigns(:versions) }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2023-08-09 15:01:15 -05:00
|
|
|
shared_examples "is successful" do
|
|
|
|
|
it { expect(response).to be_successful }
|
|
|
|
|
it { expect(response).to render_template("index") }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2023-08-09 15:01:15 -05:00
|
|
|
shared_examples "shows versions with and without a date set" do
|
|
|
|
|
it do
|
|
|
|
|
expect(subject).to include(version1, version2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
shared_examples "shows sub project's' version" do
|
|
|
|
|
it "sets @with_subprojects to true" do
|
|
|
|
|
expect(assigns(:with_subprojects)).to be_truthy
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "shows sub project's version" do
|
|
|
|
|
expect(subject).to include(sub_project_version)
|
|
|
|
|
end
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2023-08-09 15:01:15 -05:00
|
|
|
shared_examples "does not show sub project's versions" do
|
|
|
|
|
it "sets @with_subprojects to false" do
|
|
|
|
|
expect(assigns(:with_subprojects)).to be_falsey
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it "does not show sub project's version" do
|
|
|
|
|
expect(subject).not_to include(sub_project_version)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when with_subprojects param is set to 1" do
|
|
|
|
|
let(:params) { { project_id: project.id, with_subprojects: 1 } }
|
|
|
|
|
|
|
|
|
|
include_examples "is successful"
|
|
|
|
|
include_examples "shows sub project's' version"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "when with_subprojects param is set to 0" do
|
|
|
|
|
let(:params) { { project_id: project.id, with_subprojects: 0 } }
|
|
|
|
|
|
|
|
|
|
include_examples "is successful"
|
|
|
|
|
include_examples "does not show sub project's versions"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "with sub projects included by default",
|
|
|
|
|
with_settings: { display_subprojects_work_packages: true } do
|
|
|
|
|
context "and with_subprojects is not a param" do
|
|
|
|
|
let(:params) { { project_id: project.id } }
|
|
|
|
|
|
|
|
|
|
include_examples "is successful"
|
|
|
|
|
include_examples "shows sub project's' version"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "and with_subprojects is set to 0" do
|
|
|
|
|
let(:params) { { project_id: project.id, with_subprojects: 0 } }
|
|
|
|
|
|
|
|
|
|
include_examples "is successful"
|
|
|
|
|
include_examples "does not show sub project's versions"
|
|
|
|
|
end
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#show" do
|
2013-05-14 13:31:47 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2013-05-14 13:31:47 +02:00
|
|
|
version2
|
2016-10-17 10:21:42 +02:00
|
|
|
get :show, params: { id: version2.id }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2018-11-23 15:06:32 +01:00
|
|
|
it { expect(response).to be_successful }
|
2014-11-03 23:43:33 +01:00
|
|
|
it { expect(response).to render_template("show") }
|
2024-11-26 11:08:17 +01:00
|
|
|
it { assert_select "h1", content: version2.name }
|
2013-05-14 13:31:47 +02:00
|
|
|
|
|
|
|
|
subject { assigns(:version) }
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2014-04-17 23:35:32 +02:00
|
|
|
it { is_expected.to eq(version2) }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2015-10-23 17:57:16 +02:00
|
|
|
describe "#new" do
|
|
|
|
|
# This spec is here because at one point the `new` action was requiring
|
|
|
|
|
# the `version` key in params, so visiting it without one failed.
|
|
|
|
|
it "renders correctly" do
|
|
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
get :new, params: { project_id: project.id }
|
2024-06-24 17:35:16 +02:00
|
|
|
expect(response).to have_http_status(:ok)
|
2015-10-23 17:57:16 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#create" do
|
2021-01-22 09:14:21 -05:00
|
|
|
context "with valid attributes" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
post :create, params: { project_id: project.id, version: { name: "test_add_version" } }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2021-10-29 14:41:12 +02:00
|
|
|
it { expect(response).to redirect_to(project_settings_versions_path(project)) }
|
2021-10-28 12:28:37 +02:00
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "generates the new version" do
|
2015-06-26 11:23:13 +02:00
|
|
|
version = Version.find_by(name: "test_add_version")
|
2014-03-29 14:50:29 +01:00
|
|
|
expect(version).not_to be_nil
|
|
|
|
|
expect(version.project).to eq(project)
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#edit" do
|
2013-05-14 13:31:47 +02:00
|
|
|
render_views
|
|
|
|
|
|
|
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2013-05-14 13:31:47 +02:00
|
|
|
version2
|
2016-10-17 10:21:42 +02:00
|
|
|
get :edit, params: { id: version2.id }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
context "when resource is found" do
|
2018-11-23 15:06:32 +01:00
|
|
|
it { expect(response).to be_successful }
|
2014-11-03 23:43:33 +01:00
|
|
|
it { expect(response).to render_template("edit") }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#close_completed" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2013-05-14 13:31:47 +02:00
|
|
|
version1.update_attribute :status, "open"
|
|
|
|
|
version2.update_attribute :status, "open"
|
|
|
|
|
version3.update_attribute :status, "open"
|
2016-10-17 10:21:42 +02:00
|
|
|
put :close_completed, params: { project_id: project.id }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2021-10-29 14:41:12 +02:00
|
|
|
it { expect(response).to redirect_to(project_settings_versions_path(project)) }
|
2015-06-26 11:23:13 +02:00
|
|
|
it { expect(Version.find_by(status: "closed")).to eq(version3) }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#update" do
|
|
|
|
|
context "with valid params" do
|
2019-12-10 09:35:16 +01:00
|
|
|
let(:params) do
|
2016-10-17 10:21:42 +02:00
|
|
|
{
|
|
|
|
|
id: version1.id,
|
|
|
|
|
version: {
|
|
|
|
|
name: "New version name",
|
|
|
|
|
effective_date: Date.today.strftime("%Y-%m-%d")
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-10 09:35:16 +01:00
|
|
|
end
|
2022-05-31 11:55:27 +02:00
|
|
|
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
patch :update, params:
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2021-10-29 14:41:12 +02:00
|
|
|
it { expect(response).to redirect_to(project_settings_versions_path(project)) }
|
2015-06-26 11:23:13 +02:00
|
|
|
it { expect(Version.find_by(name: "New version name")).to eq(version1) }
|
2014-03-29 14:50:29 +01:00
|
|
|
it { expect(version1.reload.effective_date).to eq(Date.today) }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2024-07-29 16:37:43 +02:00
|
|
|
context "with valid params with a redirect url" do
|
2014-02-21 19:26:27 +01:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
patch :update,
|
|
|
|
|
params: {
|
|
|
|
|
id: version1.id,
|
|
|
|
|
version: { name: "New version name",
|
|
|
|
|
effective_date: Date.today.strftime("%Y-%m-%d") },
|
|
|
|
|
back_url: home_path
|
|
|
|
|
}
|
2014-02-21 19:26:27 +01:00
|
|
|
end
|
|
|
|
|
|
2014-03-29 14:50:29 +01:00
|
|
|
it { expect(response).to redirect_to(home_path) }
|
2014-02-21 19:26:27 +01:00
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
context "with invalid params" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2016-10-17 10:21:42 +02:00
|
|
|
patch :update,
|
|
|
|
|
params: {
|
|
|
|
|
id: version1.id,
|
|
|
|
|
version: { name: "",
|
|
|
|
|
effective_date: Date.today.strftime("%Y-%m-%d") }
|
|
|
|
|
}
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2024-08-28 12:43:09 +02:00
|
|
|
it { expect(response).to have_http_status(:unprocessable_entity) }
|
2014-11-03 23:43:33 +01:00
|
|
|
it { expect(response).to render_template("edit") }
|
2023-10-23 16:47:28 +02:00
|
|
|
it { expect(assigns(:version).errors.symbols_for(:name)).to contain_exactly(:blank) }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
describe "#destroy" do
|
2013-05-14 13:31:47 +02:00
|
|
|
before do
|
2015-10-02 12:01:17 +02:00
|
|
|
login_as(user)
|
2013-05-14 13:31:47 +02:00
|
|
|
@deleted = version3.id
|
2016-10-17 10:21:42 +02:00
|
|
|
delete :destroy, params: { id: @deleted }
|
2013-05-14 13:31:47 +02:00
|
|
|
end
|
|
|
|
|
|
2014-11-03 23:43:33 +01:00
|
|
|
it "redirects to projects versions and the version is deleted" do
|
2026-04-30 09:26:27 +02:00
|
|
|
expect(flash[:notice]).to eq(I18n.t(:notice_successful_delete))
|
2021-10-29 14:41:12 +02:00
|
|
|
expect(response).to redirect_to(project_settings_versions_path(project))
|
2013-05-14 13:31:47 +02:00
|
|
|
expect { Version.find(@deleted) }.to raise_error ActiveRecord::RecordNotFound
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|