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

[#63594] Primerize Project copy form

Alexander Brandon Coles2a30b50e6e45
diff --git a/app/components/projects/copy_form_component.html.erb b/app/components/projects/copy_form_component.html.erb
new file mode 100644
index 00000000000..421806db994
--- /dev/null
+++ b/app/components/projects/copy_form_component.html.erb
@@ -0,0 +1,56 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ component_wrapper do
+ settings_primer_form_with(model: target_project, url: copy_project_path(source_project), method: :post) do |f|
+ flex_layout do |container|
+ container.with_row(mb: 3) do
+ render(
+ Primer::Forms::FormList.new(
+ Projects::Settings::NameForm.new(f),
+ Projects::Settings::RelationsForm.new(f),
+ Projects::Settings::CustomFieldsForm.new(f)
+ )
+ )
+ end
+
+ container.with_row(mb: 3) do
+ render(Primer::Box.new(border: true, border_radius: 2, bg: :inset, p: 3)) do
+ render(Projects::CopyForm.new(f, copy_options:))
+ end
+ end
+
+ container.with_row(mb: 3) do
+ render Projects::SubmitOrCancel.new(f, submit_options: { label: I18n.t(:button_copy) })
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/copy_form_component.rb b/app/components/projects/copy_form_component.rb
new file mode 100644
index 00000000000..9d1cefd0d77
--- /dev/null
+++ b/app/components/projects/copy_form_component.rb
@@ -0,0 +1,39 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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.
+# ++
+
+module Projects
+ class CopyFormComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ options :source_project, :target_project, :copy_options
+ end
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 3000fd9c615..c17764d57ab 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -34,7 +36,7 @@ class ProjectsController < ApplicationController
before_action :find_project, except: %i[index new create export_list_modal]
before_action :load_query_or_deny_access, only: %i[index export_list_modal]
- before_action :authorize, only: %i[copy deactivate_work_package_attachments]
+ before_action :authorize, only: %i[copy_form copy deactivate_work_package_attachments]
before_action :authorize_global, only: %i[new create]
before_action :require_admin, only: %i[destroy destroy_info]
before_action :find_optional_template, only: %i[new create]
@@ -105,10 +107,37 @@ class ProjectsController < ApplicationController
end
end
- def copy
+ def copy_form
+ @copy_options = Projects::CopyOptions.new
+ @target_project = Projects::CopyService
+ .new(user: current_user, source: @project, contract_options: { validate_model: false })
+ .call(target_project_params: {}, attributes_only: true)
+ .result
+
render
end
+ def copy # rubocop:disable Metrics/AbcSize
+ @copy_options = Projects::CopyOptions.new(permitted_params.copy_project_options)
+
+ service_call = Projects::EnqueueCopyService
+ .new(user: current_user, model: @project)
+ .call(
+ target_project_params: permitted_params.new_project.to_h,
+ only: @copy_options.dependencies,
+ send_notifications: @copy_options.send_notifications
+ )
+
+ if service_call.success?
+ job = service_call.result
+ redirect_to job_status_path(job.job_id)
+ else
+ @target_project = service_call.result
+ flash.now[:error] = I18n.t(:notice_unsuccessful_create_with_reason, reason: service_call.message)
+ render action: :copy_form, status: :unprocessable_entity
+ end
+ end
+
# Delete @project
def destroy
service_call = ::Projects::ScheduleDeletionService
diff --git a/app/forms/projects/copy_form.rb b/app/forms/projects/copy_form.rb
new file mode 100644
index 00000000000..a57dd38cd55
--- /dev/null
+++ b/app/forms/projects/copy_form.rb
@@ -0,0 +1,43 @@
+# 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.
+#++
+
+module Projects
+ class CopyForm < ApplicationForm
+ extend Dry::Initializer
+
+ option :copy_options
+
+ form do |f|
+ f.fields_for(:copy_options, copy_options, nested: false) do |builder|
+ CopyOptionsForm.new(builder)
+ end
+ end
+ end
+end
diff --git a/app/views/projects/copy.html.erb b/app/views/projects/copy_form.html.erb
similarity index 91%
rename from app/views/projects/copy.html.erb
rename to app/views/projects/copy_form.html.erb
index 1ab2ee5fd15..5a6d4b3d265 100644
--- a/app/views/projects/copy.html.erb
+++ b/app/views/projects/copy_form.html.erb
@@ -40,4 +40,11 @@ See COPYRIGHT and LICENSE files for more details.
)
end
%>
-<%= angular_component_tag "opce-copy-project" %>
+
+<%=
+ render Projects::CopyFormComponent.new(
+ source_project: @project,
+ target_project: @target_project,
+ copy_options: @copy_options
+ )
+%>
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 5b30b6f7391..26e78d11e0d 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -205,7 +205,7 @@ Rails.application.reloader.to_prepare do
map.permission :copy_projects,
{
- projects: %i[copy]
+ projects: %i[copy_form copy]
},
permissible_on: :project,
require: :member,
diff --git a/config/routes.rb b/config/routes.rb
index 41a3cbaabe2..b858e2172f3 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -307,7 +307,8 @@ Rails.application.routes.draw do
member do
get "settings", to: redirect("projects/%{id}/settings/general/")
- get :copy
+ get :copy, to: "projects#copy_form"
+ post :copy
patch :types
diff --git a/spec/components/projects/copy_form_component_spec.rb b/spec/components/projects/copy_form_component_spec.rb
new file mode 100644
index 00000000000..b1933497ebc
--- /dev/null
+++ b/spec/components/projects/copy_form_component_spec.rb
@@ -0,0 +1,45 @@
+# 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 "rails_helper"
+
+RSpec.describe Projects::CopyFormComponent, type: :component do
+ let(:source_project) { build_stubbed(:project) }
+ let(:target_project) { Project.new(attributes_for(:project).except(:name)) }
+
+ def render_component(**params)
+ render_inline(described_class.new(source_project:, target_project:, **params))
+ page
+ end
+
+ it "renders a form" do
+ expect(render_component).to have_css "form"
+ end
+end
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 705c40da3e1..f00c105db89 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -305,25 +305,89 @@ RSpec.describe ProjectsController do
end
end
- describe "#copy" do
+ describe "#copy_form" do
let(:project) { create(:project, identifier: "blog") }
- it "renders 'copy'" do
- get "copy", params: { id: project.id }
- expect(response).to be_successful
- expect(response).to render_template "copy"
+ shared_examples_for "successful request" do
+ it "renders 'copy_form'", :aggregate_failures do
+ expect(response).to be_successful
+ expect(assigns(:target_project)).to be_a_new(Project)
+ expect(assigns(:project)).to eq project
+ expect(response).to render_template "copy_form"
+ end
end
- context "as non authorized user" do
+ before do
+ get "copy_form", params: { id: project.identifier }
+ end
+
+ context "as an admin" do
+ it_behaves_like "successful request"
+ end
+
+ context "as a non-admin with copy_projects permissions" do
+ let(:user) { create(:user, member_with_roles: { project => project_role }) }
+ let(:project_role) { build(:project_role, permissions: [:copy_projects]) }
+
+ it_behaves_like "successful request"
+ end
+
+ context "as a non-admin without copy_projects permissions" do
let(:user) { build_stubbed(:user) }
- before do
- login_as user
+ it "returns 403 Not Authorized" do
+ expect(response).not_to be_successful
+ expect(response).to have_http_status :forbidden
end
+ end
+ end
- it "shows an error" do
- get "copy", params: { id: project.id }
- expect(response).to have_http_status :forbidden
+ describe "#copy" do
+ let(:project) { create(:project, identifier: "blog") }
+
+ before do
+ copy_service = instance_double(Projects::EnqueueCopyService, call: service_result)
+
+ allow(Projects::EnqueueCopyService)
+ .to receive(:new)
+ .with(user: admin, model: project)
+ .and_return(copy_service)
+ end
+
+ context "when service call succeeds" do
+ let(:job) { CopyProjectJob.new }
+ let(:service_result) { ServiceResult.success(result: job) }
+
+ it "redirects to job status" do
+ post :copy, params: {
+ id: project.identifier,
+ project: { name: "Copied project" },
+ copy_options: { dependencies: [], send_notifications: false }
+ }
+
+ expect(response).to redirect_to job_status_path(job.job_id)
+ end
+ end
+
+ context "when service call fails" do
+ let(:target_project) { Project.new }
+ let(:service_result) { ServiceResult.failure(result: target_project, message: "") }
+
+ it "renders copy_form template with errors", :aggregate_failures do
+ post :copy, params: {
+ id: project.identifier,
+ project: { name: "" },
+ copy_options: { dependencies: [], send_notifications: false }
+ }
+
+ expect(response).not_to be_successful
+ expect(response).to have_http_status :unprocessable_entity
+ expect(assigns(:target_project)).to be_a_new(Project)
+ expect(assigns(:target_project)).not_to be_valid
+ expect(assigns(:project)).to eq project
+ expect(assigns(:copy_options)).not_to be_nil
+ expect(flash[:error]).to start_with I18n.t(:notice_unsuccessful_create_with_reason, reason: "")
+ expect(response).to render_template "copy_form"
end
end
end
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rb
index 30a018e3737..6bad3fd98de 100644
--- a/spec/features/projects/copy_spec.rb
+++ b/spec/features/projects/copy_spec.rb
@@ -177,17 +177,12 @@ RSpec.describe "Projects copy", :js,
general_settings_page.click_copy_action
end
- it "separates optional and required custom fields for new" do
+ it "renders only required project attribute" do
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
expect(page).to have_content "Required Foo"
expect(page).to have_content "Required User"
-
- click_on "Advanced settings"
-
- within(".op-fieldset", match: :first) do
- expect(page).to have_text "Optional Foo"
- expect(page).to have_no_text "Required Foo"
- expect(page).to have_no_text "Required User"
- end
+ expect(page).to have_no_text "Optional Foo"
end
end
@@ -196,39 +191,20 @@ RSpec.describe "Projects copy", :js,
general_settings_page = Pages::Projects::Settings::General.new(project)
general_settings_page.visit!
general_settings_page.click_copy_action
-
- expect(page).to have_text "Copy project \"#{project.name}\""
-
- fill_in "Name", with: "Copied project"
end
it "enables the same project custom fields as activated on the source project if untouched" do
- expect(project.project_custom_field_ids).to contain_exactly(
- project_custom_field.id,
- optional_project_custom_field.id,
- optional_project_custom_field_with_default.id
- )
+ expect(page).to have_heading "Copy project \"#{project.name}\""
- click_button "Save"
-
- wait_for_copy_to_finish
-
- copied_project = Project.find_by(name: "Copied project")
-
- expect(copied_project.project_custom_field_ids).to contain_exactly(
+ expect(project.project_custom_field_ids).to contain_exactly(
project_custom_field.id,
optional_project_custom_field.id,
optional_project_custom_field_with_default.id
)
- end
- it "does not disable optional project custom fields if explicitly set to blank" do
- # Expand advanced settings
- click_on "Advanced settings"
- editor = Components::WysiwygEditor.new "[data-qa-field-name='customField#{optional_project_custom_field.id}']"
- editor.clear
+ fill_in "Name", with: "Copied project"
- click_button "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -239,9 +215,6 @@ RSpec.describe "Projects copy", :js,
optional_project_custom_field.id,
optional_project_custom_field_with_default.id
)
-
- # the optional custom field is activated, but set to blank value
- expect(copied_project.custom_value_for(optional_project_custom_field).typed_value).to eq("")
end
it "does enable project custom fields if set to blank in source project" do
@@ -261,11 +234,11 @@ RSpec.describe "Projects copy", :js,
general_settings_page.visit!
general_settings_page.click_copy_action
- expect(page).to have_text "Copy project \"#{project.name}\""
+ expect(page).to have_heading "Copy project \"#{project.name}\""
fill_in "Name", with: "Copied project"
- click_button "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -294,6 +267,8 @@ RSpec.describe "Projects copy", :js,
end
it "does not enable optional project custom fields with default values when not enabled in source project" do
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
# the optional boolean and string fields are not activated in the source project
expect(project.project_custom_field_ids).to contain_exactly(
project_custom_field.id,
@@ -301,7 +276,9 @@ RSpec.describe "Projects copy", :js,
optional_project_custom_field_with_default.id
)
- click_button "Save"
+ fill_in "Name", with: "Copied project"
+
+ click_on "Copy"
wait_for_copy_to_finish
@@ -321,6 +298,7 @@ RSpec.describe "Projects copy", :js,
let!(:invisible_field) do
create(:string_project_custom_field, name: "Text for Admins only",
admin_only: true,
+ is_required: true,
project_custom_field_section:,
projects: [project])
end
@@ -332,22 +310,21 @@ RSpec.describe "Projects copy", :js,
general_settings_page = Pages::Projects::Settings::General.new(project)
general_settings_page.visit!
general_settings_page.click_copy_action
-
- expect(page).to have_text "Copy project \"#{project.name}\""
-
- fill_in "Name", with: "Copied project"
- click_on "Advanced settings"
end
context "with an admin user" do
let(:user) { create(:admin) }
it "shows invisible fields in the form and allows their activation" do
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
expect(page).to have_content "Text for Admins only"
+ fill_in "Name", with: "Copied project"
+
# don't touch the source value
- click_button "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -366,9 +343,15 @@ RSpec.describe "Projects copy", :js,
context "with non-admin user" do
it "does not show invisible fields in the form and but still activates them" do
+ pending "Admin-only project attributes currently prevent users from creating projects (OP#64479)"
+
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
expect(page).to have_no_content "Text for Admins only"
- click_button "Save"
+ fill_in "Name", with: "Copied project"
+
+ click_on "Copy"
wait_for_copy_to_finish
@@ -402,29 +385,36 @@ RSpec.describe "Projects copy", :js,
create(:version_project_custom_field,
name: "Version CF",
multi_value: true,
+ is_required: true,
project_custom_field_section:,
projects: [project])
end
- let(:version_field) { FormFields::SelectFormField.new version_custom_field }
+ let(:version_field) do
+ FormFields::SelectFormField.new(
+ version_custom_field,
+ selector: "[data-qa-field-name='#{version_custom_field.attribute_name(:kebab_case)}'"
+ )
+ end
before do
general_settings_page = Pages::Projects::Settings::General.new(project)
general_settings_page.visit!
general_settings_page.click_copy_action
-
- fill_in "Name", with: "Copied project"
- click_on "Advanced settings"
end
it "can create a project" do
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
+ fill_in "Name", with: "Copied project"
+
# expect the versions are grouped by the project name
version_field.expect_option(versions.first.name, grouping: project.name)
version_field.expect_option(versions.last.name, grouping: public_project.name)
version_field.select_option(versions.first.name, versions.last.name)
- click_button "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -454,10 +444,10 @@ RSpec.describe "Projects copy", :js,
general_settings_page.visit!
general_settings_page.click_copy_action
- expect(page).to have_text "Copy project \"#{project.name}\""
+ expect(page).to have_heading "Copy project \"#{project.name}\""
fill_in "Name", with: "Copied project"
- click_on "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -486,18 +476,14 @@ RSpec.describe "Projects copy", :js,
general_settings_page.visit!
general_settings_page.click_copy_action
- expect(page).to have_text "Copy project \"#{project.name}\""
+ expect(page).to have_heading "Copy project \"#{project.name}\""
fill_in "Name", with: "Copied project"
- # Expand advanced settings
- click_on "Advanced settings"
-
# the value of the custom field should be preselected
- editor = Components::WysiwygEditor.new "[data-qa-field-name='customField#{project_custom_field.id}']"
- editor.expect_value "some text cf"
+ expect(page).to have_selector :rich_text, "Required Foo", text: "some text cf"
- click_on "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -615,8 +601,10 @@ RSpec.describe "Projects copy", :js,
general_settings_page.visit!
general_settings_page.click_copy_action
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
fill_in "Name", with: "Copied project"
- click_on "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -672,8 +660,10 @@ RSpec.describe "Projects copy", :js,
general_settings_page.visit!
general_settings_page.click_copy_action
+ expect(page).to have_heading "Copy project \"#{project.name}\""
+
fill_in "Name", with: "Copied project"
- click_on "Save"
+ click_on "Copy"
wait_for_copy_to_finish
@@ -698,7 +688,12 @@ RSpec.describe "Projects copy", :js,
end
def wait_for_copy_to_finish
- expect(page).to have_text "The job has been queued and will be processed shortly."
+ expect(page).to have_dialog "Background job status"
+
+ within_dialog "Background job status" do
+ expect(page).to have_heading "Copy project"
+ expect(page).to have_text "The job has been queued and will be processed shortly."
+ end
# ensure all jobs are run especially emails which might be sent later on
GoodJob.perform_inline
diff --git a/spec/forms/projects/copy_form_spec.rb b/spec/forms/projects/copy_form_spec.rb
new file mode 100644
index 00000000000..6720ac1f2fe
--- /dev/null
+++ b/spec/forms/projects/copy_form_spec.rb
@@ -0,0 +1,54 @@
+# 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"
+
+RSpec.describe Projects::CopyForm, type: :forms do
+ include ViewComponent::TestHelpers
+
+ def render_form
+ render_in_view_context(model, copy_options, described_class) do |model, copy_options, described_class|
+ primer_form_with(url: "/foo", model:) do |f|
+ render(described_class.new(f, copy_options:))
+ end
+ end
+ end
+
+ before do
+ render_form
+ end
+
+ let(:model) { build_stubbed(:project) }
+ let(:copy_options) { Projects::CopyOptions.new }
+
+ it "renders Copy options" do
+ expect(page).to have_selector :fieldset, "Copy options"
+ end
+end
diff --git a/spec/permissions/copy_projects_spec.rb b/spec/permissions/copy_projects_spec.rb
index 8293b9dc880..0ff1e611407 100644
--- a/spec/permissions/copy_projects_spec.rb
+++ b/spec/permissions/copy_projects_spec.rb
@@ -34,5 +34,6 @@ require "support/permission_specs"
RSpec.describe ProjectsController, "copy_projects permission", type: :controller do
include PermissionSpecs
+ check_permission_required_for("projects#copy_form", :copy_projects)
check_permission_required_for("projects#copy", :copy_projects)
end
diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb
index 103c3c62734..51764d8dfee 100644
--- a/spec/routing/project_routing_spec.rb
+++ b/spec/routing/project_routing_spec.rb
@@ -67,6 +67,22 @@ RSpec.describe ProjectsController do
end
end
+ describe "copy_form" do
+ it do
+ expect(get("projects/123/copy")).to route_to(
+ controller: "projects", action: "copy_form", id: "123"
+ )
+ end
+ end
+
+ describe "copy" do
+ it do
+ expect(post("projects/123/copy")).to route_to(
+ controller: "projects", action: "copy", id: "123"
+ )
+ end
+ end
+
describe "destroy_info" do
it do
expect(get("/projects/123/destroy_info")).to route_to(
@@ -121,12 +137,6 @@ RSpec.describe ProjectsController do
controller: "projects/archive", action: "destroy", project_id: "123"
)
end
-
- it do
- expect(get("projects/123/copy")).to route_to(
- controller: "projects", action: "copy", id: "123"
- )
- end
end
describe "types" do