Merge pull request #486 from opf/feature/migrate_issues_controller_tests
[FEATURE] Migrate issues controller testspull/478/merge
commit
e12d484392
@ -0,0 +1,412 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe WorkPackageBulkController do |
||||
let(:user) { FactoryGirl.create(:user) } |
||||
let(:custom_field_value) { '125' } |
||||
let(:custom_field_1) { FactoryGirl.create(:work_package_custom_field, |
||||
field_format: 'string', |
||||
is_for_all: true) } |
||||
let(:custom_field_2) { FactoryGirl.create(:work_package_custom_field) } |
||||
let(:status) { FactoryGirl.create(:status) } |
||||
let(:type) { FactoryGirl.create(:type_standard, |
||||
custom_fields: [custom_field_1, custom_field_2]) } |
||||
let(:project_1) { FactoryGirl.create(:project, |
||||
types: [type], |
||||
work_package_custom_fields: [custom_field_2]) } |
||||
let(:project_2) { FactoryGirl.create(:project, |
||||
types: [type]) } |
||||
let(:role) { FactoryGirl.create(:role, |
||||
permissions: [:edit_work_packages, |
||||
:view_work_packages, |
||||
:manage_subtasks]) } |
||||
let(:member_1) { FactoryGirl.create(:member, |
||||
project: project_1, |
||||
principal: user, |
||||
roles: [role]) } |
||||
let(:member_2) { FactoryGirl.create(:member, |
||||
project: project_2, |
||||
principal: user, |
||||
roles: [role]) } |
||||
let(:work_package_1) { FactoryGirl.create(:work_package, |
||||
author: user, |
||||
assigned_to: user, |
||||
type: type, |
||||
status: status, |
||||
custom_field_values: { custom_field_1.id => custom_field_value }, |
||||
project: project_1) } |
||||
let(:work_package_2) { FactoryGirl.create(:work_package, |
||||
author: user, |
||||
assigned_to: user, |
||||
type: type, |
||||
status: status, |
||||
custom_field_values: { custom_field_1.id => custom_field_value }, |
||||
project: project_1) } |
||||
let(:work_package_3) { FactoryGirl.create(:work_package, |
||||
author: user, |
||||
type: type, |
||||
status: status, |
||||
custom_field_values: { custom_field_1.id => custom_field_value }, |
||||
project: project_2) } |
||||
|
||||
before do |
||||
custom_field_1 |
||||
member_1 |
||||
|
||||
User.stub(:current).and_return user |
||||
end |
||||
|
||||
describe :edit do |
||||
shared_examples_for :response do |
||||
subject { response } |
||||
|
||||
it { should be_success } |
||||
|
||||
it { should render_template('edit') } |
||||
end |
||||
|
||||
context "same project" do |
||||
before { get :edit, ids: [work_package_1.id, work_package_2.id] } |
||||
|
||||
it_behaves_like :response |
||||
|
||||
describe :view do |
||||
render_views |
||||
|
||||
subject { response } |
||||
|
||||
describe :parent do |
||||
it { assert_tag :input, attributes: { name: 'work_package[parent_id]' } } |
||||
end |
||||
|
||||
context :custom_field do |
||||
describe :type do |
||||
it { assert_tag :input, attributes: { name: "work_package[custom_field_values][#{custom_field_1.id}]" } } |
||||
end |
||||
|
||||
describe :project do |
||||
it { assert_tag :select, attributes: { name: "work_package[custom_field_values][#{custom_field_2.id}]" } } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "different projects" do |
||||
before do |
||||
member_2 |
||||
|
||||
get :edit, ids: [work_package_1.id, work_package_2.id, work_package_3.id] |
||||
end |
||||
|
||||
it_behaves_like :response |
||||
|
||||
describe :view do |
||||
render_views |
||||
|
||||
subject { response } |
||||
|
||||
describe :parent do |
||||
it { assert_no_tag :input, attributes: { name: 'work_package[parent_id]' } } |
||||
end |
||||
|
||||
context :custom_field do |
||||
describe :type do |
||||
it { assert_tag :input, attributes: { name: "work_package[custom_field_values][#{custom_field_1.id}]" } } |
||||
end |
||||
|
||||
describe :project do |
||||
it { assert_no_tag :select, attributes: { name: "work_package[custom_field_values][#{custom_field_2.id}]" } } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe :update do |
||||
let(:work_package_ids) { [work_package_1.id, work_package_2.id] } |
||||
let(:work_packages) { WorkPackage.find_all_by_id(work_package_ids) } |
||||
let(:priority) { FactoryGirl.create(:priority_immediate) } |
||||
let(:group_id) { '' } |
||||
|
||||
describe :redirect do |
||||
context "in host" do |
||||
let(:url) { '/work_packages' } |
||||
|
||||
before { put :update, ids: work_package_ids, back_url: url } |
||||
|
||||
subject { response } |
||||
|
||||
it { should be_redirect } |
||||
|
||||
it { should redirect_to(url) } |
||||
end |
||||
|
||||
context "of host" do |
||||
let(:url) { 'http://google.com' } |
||||
|
||||
before { put :update, ids: work_package_ids, back_url: url } |
||||
|
||||
subject { response } |
||||
|
||||
it { should be_redirect } |
||||
|
||||
it { should redirect_to(controller: 'work_packages', |
||||
action: :index, |
||||
project_id: project_1.identifier) } |
||||
end |
||||
end |
||||
|
||||
shared_context :update_request do |
||||
before do |
||||
put :update, |
||||
ids: work_package_ids, |
||||
notes: 'Bulk editing', |
||||
work_package: { priority_id: priority.id, |
||||
assigned_to_id: group_id, |
||||
custom_field_values: { custom_field_1.id.to_s => '' }, |
||||
send_notification: send_notification } |
||||
end |
||||
end |
||||
|
||||
shared_examples_for :delivered do |
||||
subject { ActionMailer::Base.deliveries.size } |
||||
|
||||
it { delivery_size } |
||||
end |
||||
|
||||
context "with notification" do |
||||
let(:send_notification) { '1' } |
||||
let(:delivery_size) { 2 } |
||||
|
||||
shared_examples_for "updated work package" do |
||||
describe :priority do |
||||
subject { WorkPackage.find_all_by_priority_id(priority.id).collect(&:id) } |
||||
|
||||
it { should =~ work_package_ids } |
||||
end |
||||
|
||||
describe :custom_fields do |
||||
let(:result) { [custom_field_value] } |
||||
|
||||
subject { WorkPackage.find_all_by_id(work_package_ids) |
||||
.collect {|w| w.custom_value_for(custom_field_1.id).value } |
||||
.uniq } |
||||
|
||||
it { should =~ result } |
||||
end |
||||
|
||||
describe :journal do |
||||
describe :notes do |
||||
let(:result) { ['Bulk editing'] } |
||||
|
||||
subject { WorkPackage.find_all_by_id(work_package_ids) |
||||
.collect {|w| w.last_journal.notes } |
||||
.uniq } |
||||
|
||||
it { should =~ result } |
||||
end |
||||
|
||||
describe :details do |
||||
let(:result) { [1] } |
||||
|
||||
subject { WorkPackage.find_all_by_id(work_package_ids) |
||||
.collect {|w| w.last_journal.details.size } |
||||
.uniq } |
||||
|
||||
it { should =~ result } |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "single project" do |
||||
include_context :update_request |
||||
|
||||
it { response.response_code.should == 302 } |
||||
|
||||
it_behaves_like :delivered |
||||
|
||||
it_behaves_like "updated work package" |
||||
end |
||||
|
||||
context "different projects" do |
||||
let(:work_package_ids) { [work_package_1.id, work_package_2.id, work_package_3.id] } |
||||
|
||||
context "with permission" do |
||||
before { member_2 } |
||||
|
||||
include_context :update_request |
||||
|
||||
it { response.response_code.should == 302 } |
||||
|
||||
it_behaves_like :delivered |
||||
|
||||
it_behaves_like "updated work package" |
||||
end |
||||
|
||||
context "w/o permission" do |
||||
include_context :update_request |
||||
|
||||
it { response.response_code.should == 403 } |
||||
|
||||
describe :journal do |
||||
subject { Journal.count } |
||||
|
||||
it { should eq(work_package_ids.count) } |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe :properties do |
||||
describe :groups do |
||||
let(:group) { FactoryGirl.create(:group) } |
||||
let(:group_id) { group.id } |
||||
|
||||
include_context :update_request |
||||
|
||||
subject { work_packages.collect {|w| w.assigned_to_id }.uniq } |
||||
|
||||
it { should =~ [group_id] } |
||||
end |
||||
|
||||
describe :status do |
||||
let(:closed_status) { FactoryGirl.create(:closed_status) } |
||||
let(:workflow) { FactoryGirl.create(:workflow, |
||||
role: role, |
||||
type_id: type.id, |
||||
old_status: status, |
||||
new_status: closed_status) } |
||||
|
||||
before do |
||||
workflow |
||||
|
||||
put :update, |
||||
ids: work_package_ids, |
||||
work_package: { status_id: closed_status.id } |
||||
end |
||||
|
||||
subject { work_packages.collect(&:status_id).uniq } |
||||
|
||||
it { should =~ [closed_status.id] } |
||||
end |
||||
|
||||
describe :parent do |
||||
let(:parent) { FactoryGirl.create(:work_package, |
||||
author: user, |
||||
project: project_1) } |
||||
|
||||
before do |
||||
put :update, |
||||
ids: work_package_ids, |
||||
work_package: { parent_id: parent.id } |
||||
end |
||||
|
||||
subject { work_packages.collect(&:parent_id).uniq } |
||||
|
||||
it { should =~ [parent.id] } |
||||
end |
||||
|
||||
describe :custom_fields do |
||||
let(:result) { '777' } |
||||
|
||||
before do |
||||
put :update, |
||||
ids: work_package_ids, |
||||
work_package: { custom_field_values: { custom_field_1.id.to_s => result } } |
||||
end |
||||
|
||||
subject { work_packages.collect {|w| w.custom_value_for(custom_field_1.id).value } |
||||
.uniq } |
||||
|
||||
it { should =~ [result] } |
||||
end |
||||
|
||||
describe :unassign do |
||||
before do |
||||
put :update, |
||||
ids: work_package_ids, |
||||
work_package: { assigned_to_id: 'none' } |
||||
end |
||||
|
||||
subject { work_packages.collect(&:assigned_to_id).uniq } |
||||
|
||||
it { should =~ [nil] } |
||||
end |
||||
|
||||
describe :version do |
||||
let(:version) { FactoryGirl.create(:version, |
||||
status: 'open', |
||||
sharing: 'tree', |
||||
project: subproject) } |
||||
let(:subproject) { FactoryGirl.create(:project, |
||||
parent: project_1, |
||||
types: [type]) } |
||||
|
||||
before do |
||||
put :update, |
||||
ids: work_package_ids, |
||||
work_package: { fixed_version_id: version.id.to_s } |
||||
end |
||||
|
||||
subject { response } |
||||
|
||||
it { should be_redirect } |
||||
|
||||
describe :work_package do |
||||
describe :fixed_version do |
||||
subject { work_packages.collect(&:fixed_version_id).uniq } |
||||
|
||||
it { should =~ [version.id] } |
||||
end |
||||
|
||||
describe :project do |
||||
subject { work_packages.collect(&:project_id).uniq } |
||||
|
||||
it { should_not =~ [subproject.id] } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
context "w/o notification" do |
||||
let(:send_notification) { '0' } |
||||
|
||||
describe :delivery do |
||||
include_context :update_request |
||||
|
||||
it { response.response_code.should == 302 } |
||||
|
||||
let(:delivery_size) { 0 } |
||||
|
||||
it_behaves_like :delivered |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,37 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require_relative '../support/permission_specs' |
||||
|
||||
describe WorkPackageBulkController, "edit_work_packages permission", type: :controller do |
||||
include PermissionSpecs |
||||
|
||||
check_permission_required_for('work_package_bulk#edit', :edit_work_packages) |
||||
check_permission_required_for('work_package_bulk#update', :edit_work_packages) |
||||
end |
@ -0,0 +1,42 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe WorkPackageBulkController do |
||||
|
||||
it "should connect GET /work_package_bulk/edit to work_package_bulk/edit" do |
||||
get("/work_package_bulk/edit").should route_to(controller: 'work_package_bulk', |
||||
action: 'edit') |
||||
end |
||||
|
||||
it "should connect PUT /work_package_bulk/update to work_package_bulk#update" do |
||||
put("/work_package_bulk/update").should route_to(controller: 'work_package_bulk', |
||||
action: 'update') |
||||
end |
||||
end |
@ -1,282 +0,0 @@ |
||||
#-- encoding: UTF-8 |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF) |
||||
# |
||||
# 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 doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
require File.expand_path('../../test_helper', __FILE__) |
||||
require 'issues_controller' |
||||
|
||||
# Re-raise errors caught by the controller. |
||||
class IssuesController; def rescue_action(e) raise e end; end |
||||
|
||||
class IssuesControllerTest < ActionController::TestCase |
||||
fixtures :all |
||||
|
||||
def setup |
||||
super |
||||
@controller = IssuesController.new |
||||
@request = ActionController::TestRequest.new |
||||
@response = ActionController::TestResponse.new |
||||
User.current = nil |
||||
end |
||||
|
||||
def test_get_bulk_edit |
||||
@request.session[:user_id] = 2 |
||||
get :bulk_edit, :ids => [1, 2] |
||||
assert_response :success |
||||
assert_template 'bulk_edit' |
||||
|
||||
assert_tag :input, :attributes => {:name => 'issue[parent_id]'} |
||||
|
||||
# Project specific custom field, date type |
||||
field = CustomField.find(9) |
||||
assert !field.is_for_all? |
||||
assert_equal 'date', field.field_format |
||||
assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
||||
|
||||
# System wide custom field |
||||
assert CustomField.find(1).is_for_all? |
||||
assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
||||
end |
||||
|
||||
def test_get_bulk_edit_on_different_projects |
||||
@request.session[:user_id] = 2 |
||||
get :bulk_edit, :ids => [1, 2, 6] |
||||
assert_response :success |
||||
assert_template 'bulk_edit' |
||||
|
||||
# Can not set issues from different projects as children of an issue |
||||
assert_no_tag :input, :attributes => {:name => 'issue[parent_id]'} |
||||
|
||||
# Project specific custom field, date type |
||||
field = CustomField.find(9) |
||||
assert !field.is_for_all? |
||||
assert !field.project_ids.include?(WorkPackage.find(6).project_id) |
||||
assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
||||
end |
||||
|
||||
def test_bulk_update |
||||
issue = WorkPackage.find(1) |
||||
issue.recreate_initial_journal! |
||||
|
||||
@request.session[:user_id] = 2 |
||||
# update issues priority |
||||
put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
||||
:issue => { :priority_id => 7, |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => ''} } |
||||
|
||||
assert_response 302 |
||||
# check that the issues were updated |
||||
assert_equal [7, 7], WorkPackage.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
||||
|
||||
issue.reload |
||||
journal = issue.journals.reorder('created_at DESC').first |
||||
assert_equal '125', issue.custom_value_for(2).value |
||||
assert_equal 'Bulk editing', journal.notes |
||||
assert_equal 1, journal.details.size |
||||
end |
||||
|
||||
def test_bullk_update_should_not_send_a_notification_if_send_notification_is_off |
||||
@request.session[:user_id] = 2 |
||||
ActionMailer::Base.deliveries.clear |
||||
put(:bulk_update, |
||||
{ |
||||
:ids => [1, 2], |
||||
:issue => { |
||||
:priority_id => 7, |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => ''} |
||||
}, |
||||
:notes => 'Bulk editing', |
||||
:send_notification => '0' |
||||
}) |
||||
|
||||
assert_response 302 |
||||
assert_equal 0, ActionMailer::Base.deliveries.size |
||||
end |
||||
|
||||
def test_bulk_update_with_group_assignee |
||||
group = Group.find(11) |
||||
project = Project.find(1) |
||||
project.members << Member.new(:principal => group, :roles => [Role.first]) |
||||
|
||||
@request.session[:user_id] = 2 |
||||
# update issues assignee |
||||
post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
||||
:issue => {:priority_id => '', |
||||
:assigned_to_id => group.id, |
||||
:custom_field_values => {'2' => ''}} |
||||
|
||||
assert_response 302 |
||||
assert_equal [group, group], WorkPackage.find_all_by_id([1, 2]).collect {|i| i.assigned_to} |
||||
end |
||||
|
||||
def test_bulk_update_on_different_projects |
||||
issue = WorkPackage.find(1) |
||||
issue.recreate_initial_journal! |
||||
|
||||
@request.session[:user_id] = 2 |
||||
# update issues priority |
||||
put :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
||||
:issue => {:priority_id => 7, |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => ''}} |
||||
|
||||
assert_response 302 |
||||
# check that the issues were updated |
||||
assert_equal [7, 7, 7], WorkPackage.find([1,2,6]).map(&:priority_id) |
||||
|
||||
issue.reload |
||||
journal = issue.journals.reorder('created_at DESC').first |
||||
assert_equal '125', issue.custom_value_for(2).value |
||||
assert_equal 'Bulk editing', journal.notes |
||||
assert_equal 1, journal.details.size |
||||
end |
||||
|
||||
def test_bulk_update_on_different_projects_without_rights |
||||
Journal.delete_all |
||||
|
||||
@request.session[:user_id] = 3 |
||||
user = User.find(3) |
||||
action = { :controller => "issues", :action => "bulk_update" } |
||||
assert user.allowed_to?(action, WorkPackage.find(1).project) |
||||
assert ! user.allowed_to?(action, WorkPackage.find(6).project) |
||||
put :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', |
||||
:issue => {:priority_id => 7, |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => ''}} |
||||
assert_response 403 |
||||
assert Journal.all.empty? |
||||
end |
||||
|
||||
def test_bulk_update_should_send_a_notification |
||||
WorkPackage.find(1).recreate_initial_journal! |
||||
WorkPackage.find(2).recreate_initial_journal! |
||||
|
||||
@request.session[:user_id] = 2 |
||||
ActionMailer::Base.deliveries.clear |
||||
put(:bulk_update, |
||||
{ |
||||
:ids => [1, 2], |
||||
:notes => 'Bulk editing', |
||||
:issue => { |
||||
:priority_id => 7, |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => ''} |
||||
} |
||||
}) |
||||
|
||||
assert_response 302 |
||||
assert_equal 5, ActionMailer::Base.deliveries.size |
||||
end |
||||
|
||||
def test_bulk_update_status |
||||
@request.session[:user_id] = 2 |
||||
# update issues priority |
||||
put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
||||
:issue => {:priority_id => '', |
||||
:assigned_to_id => '', |
||||
:status_id => '5'} |
||||
|
||||
assert_response 302 |
||||
issue = WorkPackage.find(1) |
||||
assert issue.closed? |
||||
end |
||||
|
||||
def test_bulk_update_parent_id |
||||
@request.session[:user_id] = 2 |
||||
put :bulk_update, :ids => [1, 3], |
||||
:notes => 'Bulk editing parent', |
||||
:issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_id => '2'} |
||||
|
||||
assert_response 302 |
||||
parent = WorkPackage.find(2) |
||||
assert_equal parent.id, WorkPackage.find(1).parent_id |
||||
assert_equal parent.id, WorkPackage.find(3).parent_id |
||||
assert_equal [1, 3], parent.children.collect(&:id).sort |
||||
end |
||||
|
||||
def test_bulk_update_custom_field |
||||
issue = WorkPackage.find(1) |
||||
issue.recreate_initial_journal! |
||||
|
||||
@request.session[:user_id] = 2 |
||||
# update issues priority |
||||
put :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
||||
:issue => {:priority_id => '', |
||||
:assigned_to_id => '', |
||||
:custom_field_values => {'2' => '777'}} |
||||
|
||||
assert_response 302 |
||||
|
||||
issue.reload |
||||
journal = issue.journals.last |
||||
assert_equal '777', issue.custom_value_for(2).value |
||||
assert_equal 1, journal.details.size |
||||
assert_equal '125', journal.old_value_for(:custom_fields_2) |
||||
assert_equal '777', journal.new_value_for(:custom_fields_2) |
||||
end |
||||
|
||||
def test_bulk_update_unassign |
||||
assert_not_nil WorkPackage.find(2).assigned_to |
||||
@request.session[:user_id] = 2 |
||||
# unassign issues |
||||
put :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
||||
assert_response 302 |
||||
# check that the issues were updated |
||||
assert_nil WorkPackage.find(2).assigned_to |
||||
end |
||||
|
||||
def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
||||
@request.session[:user_id] = 2 |
||||
|
||||
put :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
||||
|
||||
assert_response :redirect |
||||
issues = WorkPackage.find([1,2]) |
||||
issues.each do |issue| |
||||
assert_equal 4, issue.fixed_version_id |
||||
assert_not_equal issue.project_id, issue.fixed_version.project_id |
||||
end |
||||
end |
||||
|
||||
def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
||||
@request.session[:user_id] = 2 |
||||
put :bulk_update, :ids => [1,2], :back_url => '/issues' |
||||
|
||||
assert_response :redirect |
||||
assert_redirected_to '/issues' |
||||
end |
||||
|
||||
def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
||||
@request.session[:user_id] = 2 |
||||
put :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
||||
|
||||
assert_response :redirect |
||||
assert_redirected_to :controller => 'work_packages', :action => 'index', :project_id => Project.find(1).identifier |
||||
end |
||||
end |
Loading…
Reference in new issue