Merge pull request #8048 from opf/feature/32267/bulk-copy-set-version

[32267] Allow setting version on bulk copy

[ci skip]
pull/8052/head
Oliver Günther 5 years ago committed by GitHub
commit a909937866
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/controllers/work_packages/moves_controller.rb
  2. 8
      app/views/work_packages/moves/new.html.erb
  3. 13
      spec/controllers/work_packages/moves_controller_spec.rb
  4. 51
      spec/features/work_packages/bulk/copy_work_package_spec.rb

@ -132,6 +132,7 @@ class WorkPackages::MovesController < ApplicationController
@target_project = @allowed_projects.detect { |p| p.id.to_s == params[:new_project_id].to_s } if params[:new_project_id]
@target_project ||= @project
@types = @target_project.types
@available_versions = @target_project.shared_versions.order_by_newest_date
@available_statuses = Workflow.available_statuses(@project)
@notes = params[:notes]
@notes ||= ''
@ -160,6 +161,7 @@ class WorkPackages::MovesController < ApplicationController
:start_date,
:due_date,
:status_id,
:fixed_version_id,
:priority_id)
.to_h
.reject { |_, v| v.blank? }

@ -79,6 +79,14 @@ See docs/COPYRIGHT.rdoc for more details.
options_from_collection_for_select(@available_statuses, :id, :name)) %>
</div>
</div>
<div class="form--field">
<label class="form--label" for='fixed_version_id'><%= WorkPackage.human_attribute_name(:version) %></label>
<div class="form--field-container">
<%= styled_select_tag('fixed_version_id',
content_tag('option', l(:label_no_change_option), value: '') +
version_options_for_select(@available_versions)) %>
</div>
</div>
<div class="form--field">
<label class="form--label" for='priority_id'><%= WorkPackage.human_attribute_name(:priority) %></label>
<div class="form--field-container">

@ -36,6 +36,7 @@ describe WorkPackages::MovesController, type: :controller do
view_work_packages
add_work_packages
edit_work_packages
assign_versions
manage_subtasks)
end
let(:type) { FactoryBot.create :type }
@ -316,6 +317,10 @@ describe WorkPackages::MovesController, type: :controller do
expect(subject.status_id).to eq(work_package.status_id)
end
it 'did not change the status' do
expect(subject.fixed_version_id).to eq(work_package.fixed_version_id)
end
it 'did not change the assignee' do
expect(subject.assigned_to_id).to eq(work_package.assigned_to_id)
end
@ -328,6 +333,7 @@ describe WorkPackages::MovesController, type: :controller do
context "with changing the work package's attribute" do
let(:start_date) { Date.today }
let(:due_date) { Date.today + 1 }
let(:target_version) { FactoryBot.create(:version, project: target_project) }
let(:target_user) do
user = FactoryBot.create :user
@ -349,6 +355,7 @@ describe WorkPackages::MovesController, type: :controller do
assigned_to_id: target_user.id,
responsible_id: target_user.id,
status_id: target_status,
fixed_version_id: target_version.id,
start_date: start_date,
due_date: due_date
}
@ -384,6 +391,12 @@ describe WorkPackages::MovesController, type: :controller do
end
end
it 'did change the version' do
subject.map(&:fixed_version_id).each do |id|
expect(id).to eq(target_version.id)
end
end
it 'did change the start date' do
subject.map(&:start_date).each do |date|
expect(date).to eq(start_date)

@ -8,7 +8,7 @@ describe 'Copy work packages through Rails view', js: true do
end
let(:mover_role) do
FactoryBot.create :role,
permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks add_work_packages]
permissions: %i[view_work_packages copy_work_packages move_work_packages manage_subtasks assign_versions add_work_packages]
end
let(:dev) do
FactoryBot.create :user,
@ -45,6 +45,7 @@ describe 'Copy work packages through Rails view', js: true do
}
let(:status) { work_package.status }
let!(:version) { FactoryBot.create :version, project: project2 }
let!(:status2) { FactoryBot.create :default_status }
let!(:workflow) do
FactoryBot.create :workflow,
@ -73,36 +74,62 @@ describe 'Copy work packages through Rails view', js: true do
let(:current_user) { mover }
before do
wp_table.expect_work_package_count 2
context_menu.open_for work_package
context_menu.choose 'Bulk copy'
# On work packages move page
expect(page).to have_selector('#new_project_id')
select 'Target', from: 'new_project_id'
click_on 'Copy and follow'
sleep 1
expect(page).to have_select('Project', selected: 'Target')
end
it 'moves parent and child wp to a new project' do
expect_angular_frontend_initialized
it 'sets the version on copy' do
select version.name, from: 'fixed_version_id'
click_on 'Copy and follow'
wp_table.expect_work_package_count 2
expect(page).to have_selector('#projects-menu', text: 'Target')
# Should not move the sources
work_package2.reload
work_package.reload
expect(work_package.project_id).to eq(project.id)
expect(work_package2.project_id).to eq(project.id)
# Check project of last two created wps
copied_wps = WorkPackage.last(2)
expect(copied_wps.map(&:project_id)).to eq([project2.id, project2.id])
expect(copied_wps.map(&:project_id).uniq).to eq([project2.id])
expect(copied_wps.map(&:fixed_version_id).uniq).to eq([version.id])
end
context 'when the target project does not have the type' do
let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type2]) }
describe 'copy and follow' do
before do
click_on 'Copy and follow'
end
it 'moves parent and child wp to a new project' do
expect_angular_frontend_initialized
wp_table.expect_work_package_count 2
expect(page).to have_selector('#projects-menu', text: 'Target')
# Should not move the sources
work_package2.reload
work_package.reload
expect(work_package.project_id).to eq(project.id)
expect(work_package2.project_id).to eq(project.id)
# Check project of last two created wps
copied_wps = WorkPackage.last(2)
expect(copied_wps.map(&:project_id)).to eq([project2.id, project2.id])
end
context 'when the target project does not have the type' do
let!(:project2) { FactoryBot.create(:project, name: 'Target', types: [type2]) }
it 'does moves the work package and changes the type' do
expect(page).to have_selector('.flash.error', text: "Failed to save 2 work package(s) on 2 selected:")
it 'does moves the work package and changes the type' do
expect(page).to have_selector('.flash.error', text: "Failed to save 2 work package(s) on 2 selected:")
end
end
end
end

Loading…
Cancel
Save