diff --git a/app/views/issues/show.rhtml b/app/views/issues/show.rhtml
index b78908b00..c07fa921b 100644
--- a/app/views/issues/show.rhtml
+++ b/app/views/issues/show.rhtml
@@ -4,7 +4,10 @@
<%= avatar(@issue.author, :size => "50") %>
-
<%=h @issue.subject %>
+
+
+<%= render_issue_subject_with_tree(@issue) %>
+
<%= authoring @issue.created_on, @issue.author %>.
<% if @issue.created_on != @issue.updated_on %>
@@ -56,6 +59,17 @@
<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>
+<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
+
+
+
+ <%= link_to(l(:button_add), {:controller => 'issues', :action => 'new', :project_id => @project, :issue => {:parent_issue_id => @issue}}) if User.current.allowed_to?(:manage_subtasks, @project) %>
+
+
<%=l(:label_subtask_pural)%>
+<%= render_descendants_tree(@issue) unless @issue.leaf? %>
+
+<% end %>
+
<% if authorize_for('issue_relations', 'new') || @issue.relations.any? %>
@@ -113,4 +127,8 @@
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %>
<%= stylesheet_link_tag 'scm' %>
+ <%= javascript_include_tag 'context_menu' %>
+ <%= stylesheet_link_tag 'context_menu' %>
<% end %>
+
+<%= javascript_tag "new ContextMenu('#{url_for(:controller => 'issues', :action => 'context_menu')}')" %>
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 95dd45244..f636c9d99 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -112,6 +112,7 @@ en:
greater_than_start_date: "must be greater than start date"
not_same_project: "doesn't belong to the same project"
circular_dependency: "This relation would create a circular dependency"
+ cant_link_an_issue_with_a_descendant: "An issue can not be linked to one of its subtasks"
actionview_instancetag_blank_option: Please select
@@ -277,6 +278,7 @@ en:
field_content: Content
field_group_by: Group results by
field_sharing: Sharing
+ field_parent_issue: Parent task
setting_app_title: Application title
setting_app_subtitle: Application subtitle
@@ -386,6 +388,7 @@ en:
permission_delete_messages: Delete messages
permission_delete_own_messages: Delete own messages
permission_export_wiki_pages: Export wiki pages
+ permission_manage_subtasks: Manage subtasks
project_module_issue_tracking: Issue tracking
project_module_time_tracking: Time tracking
@@ -750,6 +753,7 @@ en:
label_missing_api_access_key: Missing an API access key
label_api_access_key_created_on: "API access key created {{value}} ago"
label_profile: Profile
+ label_subtask_plural: Subtasks
button_login: Login
button_submit: Submit
diff --git a/config/locales/fr.yml b/config/locales/fr.yml
index ad665235e..06f645600 100644
--- a/config/locales/fr.yml
+++ b/config/locales/fr.yml
@@ -136,6 +136,7 @@ fr:
greater_than_start_date: "doit être postérieure à la date de début"
not_same_project: "n'appartient pas au même projet"
circular_dependency: "Cette relation créerait une dépendance circulaire"
+ cant_link_an_issue_with_a_descendant: "Une demande ne peut pas être liée à l'une de ses sous-tâches"
actionview_instancetag_blank_option: Choisir
@@ -299,6 +300,7 @@ fr:
field_group_by: Grouper par
field_sharing: Partage
field_active: Actif
+ field_parent_issue: Tâche parente
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
@@ -408,6 +410,7 @@ fr:
permission_delete_own_messages: Supprimer ses propres messages
permission_export_wiki_pages: Exporter les pages
permission_manage_project_activities: Gérer les activités
+ permission_manage_subtasks: Gérer les sous-tâches
project_module_issue_tracking: Suivi des demandes
project_module_time_tracking: Suivi du temps passé
@@ -765,6 +768,7 @@ fr:
label_close_versions: Fermer les versions terminées
label_revision_id: Revision {{value}}
label_profile: Profil
+ label_subtask_pural: Sous-tâches
button_login: Connexion
button_submit: Soumettre
diff --git a/db/migrate/20100313132032_add_issues_nested_sets_columns.rb b/db/migrate/20100313132032_add_issues_nested_sets_columns.rb
new file mode 100644
index 000000000..e7d03e980
--- /dev/null
+++ b/db/migrate/20100313132032_add_issues_nested_sets_columns.rb
@@ -0,0 +1,17 @@
+class AddIssuesNestedSetsColumns < ActiveRecord::Migration
+ def self.up
+ add_column :issues, :parent_id, :integer, :default => nil
+ add_column :issues, :root_id, :integer, :default => nil
+ add_column :issues, :lft, :integer, :default => nil
+ add_column :issues, :rgt, :integer, :default => nil
+
+ Issue.update_all("parent_id = NULL, root_id = id, lft = 1, rgt = 2")
+ end
+
+ def self.down
+ remove_column :issues, :parent_id
+ remove_column :issues, :root_id
+ remove_column :issues, :lft
+ remove_column :issues, :rgt
+ end
+end
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 1205f6fa4..df57b08dc 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -47,13 +47,14 @@ Redmine::AccessControl.map do |map|
map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
# Issues
map.permission :view_issues, {:projects => :roadmap,
- :issues => [:index, :changes, :show, :context_menu],
+ :issues => [:index, :changes, :show, :context_menu, :auto_complete],
:versions => [:show, :status_by],
:queries => :index,
:reports => [:issue_report, :issue_report_details]}
map.permission :add_issues, {:issues => [:new, :update_form]}
map.permission :edit_issues, {:issues => [:edit, :update, :reply, :bulk_edit, :update_form]}
map.permission :manage_issue_relations, {:issue_relations => [:new, :destroy]}
+ map.permission :manage_subtasks, {}
map.permission :add_issue_notes, {:issues => [:edit, :update, :reply]}
map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
diff --git a/lib/redmine/default_data/loader.rb b/lib/redmine/default_data/loader.rb
index 7baeb976c..5eed3d9b0 100644
--- a/lib/redmine/default_data/loader.rb
+++ b/lib/redmine/default_data/loader.rb
@@ -53,6 +53,7 @@ module Redmine
:add_issues,
:edit_issues,
:manage_issue_relations,
+ :manage_subtasks,
:add_issue_notes,
:save_queries,
:view_gantt,
diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb
index e24be1cae..330b58ee7 100644
--- a/lib/redmine/helpers/gantt.rb
+++ b/lib/redmine/helpers/gantt.rb
@@ -52,8 +52,29 @@ module Redmine
@date_to = (@date_from >> @months) - 1
end
+
def events=(e)
- @events = e.sort {|x,y| x.start_date <=> y.start_date }
+ @events = e
+ # Adds all ancestors
+ root_ids = e.select {|i| i.is_a?(Issue) && i.parent_id? }.collect(&:root_id).uniq
+ if root_ids.any?
+ # Retrieves all nodes
+ parents = Issue.find_all_by_root_id(root_ids, :conditions => ["rgt - lft > 1"])
+ # Only add ancestors
+ @events += parents.select {|p| @events.detect {|i| i.is_a?(Issue) && p.is_ancestor_of?(i)}}
+ end
+ @events.uniq!
+ # Sort issues by hierarchy and start dates
+ @events.sort! {|x,y|
+ if x.is_a?(Issue) && y.is_a?(Issue)
+ gantt_issue_compare(x, y, @events)
+ else
+ gantt_start_compare(x, y)
+ end
+ }
+ # Removes issues that have no start or end date
+ @events.reject! {|i| i.is_a?(Issue) && (i.start_date.nil? || i.due_before.nil?) }
+ @events
end
def params
@@ -218,6 +239,36 @@ module Redmine
imgl.format = format
imgl.to_blob
end if Object.const_defined?(:Magick)
+
+ private
+
+ def gantt_issue_compare(x, y, issues)
+ if x.parent_id == y.parent_id
+ gantt_start_compare(x, y)
+ elsif x.is_ancestor_of?(y)
+ -1
+ elsif y.is_ancestor_of?(x)
+ 1
+ else
+ ax = issues.select {|i| i.is_a?(Issue) && i.is_ancestor_of?(x) && !i.is_ancestor_of?(y) }.sort_by(&:lft).first
+ ay = issues.select {|i| i.is_a?(Issue) && i.is_ancestor_of?(y) && !i.is_ancestor_of?(x) }.sort_by(&:lft).first
+ if ax.nil? && ay.nil?
+ gantt_start_compare(x, y)
+ else
+ gantt_issue_compare(ax || x, ay || y, issues)
+ end
+ end
+ end
+
+ def gantt_start_compare(x, y)
+ if x.start_date.nil?
+ -1
+ elsif y.start_date.nil?
+ 1
+ else
+ x.start_date <=> y.start_date
+ end
+ end
end
end
end
diff --git a/public/images/task_parent_end.png b/public/images/task_parent_end.png
new file mode 100644
index 000000000..fc9205643
Binary files /dev/null and b/public/images/task_parent_end.png differ
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 787b9904c..4cd34c2f2 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -194,6 +194,18 @@ function randomKey(size) {
return key;
}
+function observeParentIssueField(url) {
+ new Ajax.Autocompleter('issue_parent_issue_id',
+ 'parent_issue_candidates',
+ url,
+ { minChars: 3,
+ frequency: 0.5,
+ paramName: 'q',
+ updateElement: function(value) {
+ document.getElementById('issue_parent_issue_id').value = value.id;
+ }});
+}
+
/* shows and hides ajax indicator */
Ajax.Responders.register({
onCreate: function(){
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index ec31c95c3..cd8e98699 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -237,6 +237,13 @@ p.breadcrumb { font-size: 0.9em; margin: 4px 0 4px 0;}
p.subtitle { font-size: 0.9em; margin: -6px 0 12px 0; font-style: italic; }
p.footnote { font-size: 0.9em; margin-top: 0px; margin-bottom: 0px; }
+div.issue div.subject div div { padding-left: 16px; }
+div.issue div.subject p {margin: 0; margin-bottom: 0.1em; font-size: 90%; color: #999;}
+div.issue div.subject>div>p { margin-top: 0.5em; }
+div.issue div.subject h3 {margin: 0; margin-bottom: 0.1em;}
+
+#issue_tree table.issues { border: 0; }
+
fieldset.collapsible { border-width: 1px 0 0 0; font-size: 0.9em; }
fieldset.collapsible legend { padding-left: 16px; background: url(../images/arrow_expanded.png) no-repeat 0% 40%; cursor:pointer; }
fieldset.collapsible.collapsed legend { background-image: url(../images/arrow_collapsed.png); }
@@ -588,8 +595,7 @@ button.tab-right {
/***** Auto-complete *****/
div.autocomplete {
position:absolute;
- width:250px;
- background-color:white;
+ width:400px;
margin:0;
padding:0;
}
@@ -598,23 +604,26 @@ div.autocomplete ul {
margin:0;
padding:0;
}
-div.autocomplete ul li.selected { background-color: #ffb;}
div.autocomplete ul li {
list-style-type:none;
display:block;
- margin:0;
+ margin:-1px 0 0 0;
padding:2px;
cursor:pointer;
font-size: 90%;
- border-bottom: 1px solid #ccc;
+ border: 1px solid #ccc;
border-left: 1px solid #ccc;
border-right: 1px solid #ccc;
+ background-color:white;
}
+div.autocomplete ul li.selected { background-color: #ffb;}
div.autocomplete ul li span.informal {
font-size: 80%;
color: #aaa;
}
+#parent_issue_candidates ul li {width: 500px;}
+
/***** Diff *****/
.diff_out { background: #fcc; }
.diff_in { background: #cfc; }
@@ -741,6 +750,12 @@ background-image:url('../images/close_hl.png');
.task_late { background:#f66 url(../images/task_late.png); border: 1px solid #f66; }
.task_done { background:#66f url(../images/task_done.png); border: 1px solid #66f; }
.task_todo { background:#aaa url(../images/task_todo.png); border: 1px solid #aaa; }
+
+.task_todo.parent { background: #888; border: 1px solid #888; height: 6px;}
+.task_late.parent, .task_done.parent { height: 3px;}
+.task_todo.parent .left { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-left: -5px; left: 0px; top: -1px;}
+.task_todo.parent .right { position: absolute; background: url(../images/task_parent_end.png) no-repeat 0 0; width: 8px; height: 16px; margin-right: -5px; right: 0px; top: -1px;}
+
.milestone { background-image:url(../images/milestone.png); background-repeat: no-repeat; border: 0; }
/***** Icons *****/
diff --git a/test/fixtures/enumerations.yml b/test/fixtures/enumerations.yml
index 650a48c3e..c4a25d954 100644
--- a/test/fixtures/enumerations.yml
+++ b/test/fixtures/enumerations.yml
@@ -19,27 +19,32 @@ enumerations_004:
id: 4
type: IssuePriority
active: true
+ position: 1
enumerations_005:
name: Normal
id: 5
type: IssuePriority
is_default: true
active: true
+ position: 2
enumerations_006:
name: High
id: 6
type: IssuePriority
active: true
+ position: 3
enumerations_007:
name: Urgent
id: 7
type: IssuePriority
active: true
+ position: 4
enumerations_008:
name: Immediate
id: 8
type: IssuePriority
active: true
+ position: 5
enumerations_009:
name: Design
id: 9
diff --git a/test/fixtures/issues.yml b/test/fixtures/issues.yml
index 4b61b41a3..6ec671e58 100644
--- a/test/fixtures/issues.yml
+++ b/test/fixtures/issues.yml
@@ -15,6 +15,9 @@ issues_001:
status_id: 1
start_date: <%= 1.day.ago.to_date.to_s(:db) %>
due_date: <%= 10.day.from_now.to_date.to_s(:db) %>
+ root_id: 1
+ lft: 1
+ rgt: 2
issues_002:
created_on: 2006-07-19 21:04:21 +02:00
project_id: 1
@@ -31,6 +34,9 @@ issues_002:
status_id: 2
start_date: <%= 2.day.ago.to_date.to_s(:db) %>
due_date:
+ root_id: 2
+ lft: 1
+ rgt: 2
issues_003:
created_on: 2006-07-19 21:07:27 +02:00
project_id: 1
@@ -47,6 +53,9 @@ issues_003:
status_id: 1
start_date: <%= 1.day.from_now.to_date.to_s(:db) %>
due_date: <%= 40.day.ago.to_date.to_s(:db) %>
+ root_id: 3
+ lft: 1
+ rgt: 2
issues_004:
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
project_id: 2
@@ -61,6 +70,9 @@ issues_004:
assigned_to_id: 2
author_id: 2
status_id: 1
+ root_id: 4
+ lft: 1
+ rgt: 2
issues_005:
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
project_id: 3
@@ -75,6 +87,9 @@ issues_005:
assigned_to_id:
author_id: 2
status_id: 1
+ root_id: 5
+ lft: 1
+ rgt: 2
issues_006:
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
project_id: 5
@@ -91,6 +106,9 @@ issues_006:
status_id: 1
start_date: <%= Date.today.to_s(:db) %>
due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
+ root_id: 6
+ lft: 1
+ rgt: 2
issues_007:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
@@ -108,6 +126,9 @@ issues_007:
start_date: <%= 10.days.ago.to_s(:db) %>
due_date: <%= Date.today.to_s(:db) %>
lock_version: 0
+ root_id: 7
+ lft: 1
+ rgt: 2
issues_008:
created_on: <%= 10.days.ago.to_date.to_s(:db) %>
project_id: 1
@@ -125,6 +146,9 @@ issues_008:
start_date:
due_date:
lock_version: 0
+ root_id: 8
+ lft: 1
+ rgt: 2
issues_009:
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
project_id: 5
@@ -141,6 +165,9 @@ issues_009:
status_id: 1
start_date: <%= Date.today.to_s(:db) %>
due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
+ root_id: 9
+ lft: 1
+ rgt: 2
issues_010:
created_on: <%= 1.minute.ago.to_date.to_s(:db) %>
project_id: 5
@@ -157,6 +184,9 @@ issues_010:
status_id: 1
start_date: <%= Date.today.to_s(:db) %>
due_date: <%= 1.days.from_now.to_date.to_s(:db) %>
+ root_id: 10
+ lft: 1
+ rgt: 2
issues_011:
created_on: <%= 3.days.ago.to_date.to_s(:db) %>
project_id: 1
@@ -173,6 +203,9 @@ issues_011:
status_id: 5
start_date: <%= 1.day.ago.to_date.to_s(:db) %>
due_date:
+ root_id: 11
+ lft: 1
+ rgt: 2
issues_012:
created_on: <%= 3.days.ago.to_date.to_s(:db) %>
project_id: 1
@@ -189,6 +222,9 @@ issues_012:
status_id: 5
start_date: <%= 1.day.ago.to_date.to_s(:db) %>
due_date:
+ root_id: 12
+ lft: 1
+ rgt: 2
issues_013:
created_on: <%= 5.days.ago.to_date.to_s(:db) %>
project_id: 3
@@ -203,3 +239,6 @@ issues_013:
assigned_to_id:
author_id: 2
status_id: 1
+ root_id: 13
+ lft: 1
+ rgt: 2
diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml
index e3dc3645f..f63203ae3 100644
--- a/test/fixtures/roles.yml
+++ b/test/fixtures/roles.yml
@@ -14,6 +14,7 @@ roles_001:
- :add_issues
- :edit_issues
- :manage_issue_relations
+ - :manage_subtasks
- :add_issue_notes
- :move_issues
- :delete_issues
@@ -66,6 +67,7 @@ roles_002:
- :add_issues
- :edit_issues
- :manage_issue_relations
+ - :manage_subtasks
- :add_issue_notes
- :move_issues
- :delete_issues
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index b2f75eaba..11d35f500 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -476,7 +476,7 @@ class IssuesControllerTest < ActionController::TestCase
:subject => 'This is first issue',
:priority_id => 5},
:continue => ''
- assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
+ assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3}
end
def test_post_new_without_custom_fields_param
@@ -533,6 +533,20 @@ class IssuesControllerTest < ActionController::TestCase
assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
end
+ def test_post_new_subissue
+ @request.session[:user_id] = 2
+
+ assert_difference 'Issue.count' do
+ post :new, :project_id => 1,
+ :issue => {:tracker_id => 1,
+ :subject => 'This is a child issue',
+ :parent_issue_id => 2}
+ end
+ issue = Issue.find_by_subject('This is a child issue')
+ assert_not_nil issue
+ assert_equal Issue.find(2), issue.parent
+ end
+
def test_post_new_should_send_a_notification
ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2
@@ -1214,6 +1228,34 @@ class IssuesControllerTest < ActionController::TestCase
:attributes => { :href => '#',
:class => 'icon-del disabled' }
end
+
+ def test_auto_complete_routing
+ assert_routing(
+ {:method => :get, :path => '/issues/auto_complete'},
+ :controller => 'issues', :action => 'auto_complete'
+ )
+ end
+
+ def test_auto_complete_should_not_be_case_sensitive
+ get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
+ end
+
+ def test_auto_complete_should_return_issue_with_given_id
+ get :auto_complete, :project_id => 'subproject1', :q => '13'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).include?(Issue.find(13))
+ end
+
+ def test_destroy_routing
+ assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
+ {:controller => 'issues', :action => 'destroy', :id => '1'},
+ {:method => :post, :path => '/issues/1/destroy'}
+ )
+ end
def test_destroy_issue_with_no_time_entries
assert_nil TimeEntry.find_by_issue_id(2)
diff --git a/test/unit/issue_nested_set_test.rb b/test/unit/issue_nested_set_test.rb
new file mode 100644
index 000000000..d82a42d28
--- /dev/null
+++ b/test/unit/issue_nested_set_test.rb
@@ -0,0 +1,300 @@
+# redMine - project management software
+# Copyright (C) 2006-2007 Jean-Philippe Lang
+#
+# 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.
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class IssueNestedSetTest < ActiveSupport::TestCase
+ fixtures :projects, :users, :members, :member_roles, :roles,
+ :trackers, :projects_trackers,
+ :versions,
+ :issue_statuses, :issue_categories, :issue_relations, :workflows,
+ :enumerations,
+ :issues,
+ :custom_fields, :custom_fields_projects, :custom_fields_trackers, :custom_values,
+ :time_entries
+
+ self.use_transactional_fixtures = false
+
+ def test_create_root_issue
+ issue1 = create_issue!
+ issue2 = create_issue!
+ issue1.reload
+ issue2.reload
+
+ assert_equal [issue1.id, nil, 1, 2], [issue1.root_id, issue1.parent_id, issue1.lft, issue1.rgt]
+ assert_equal [issue2.id, nil, 1, 2], [issue2.root_id, issue2.parent_id, issue2.lft, issue2.rgt]
+ end
+
+ def test_create_child_issue
+ parent = create_issue!
+ child = create_issue!(:parent_issue_id => parent.id)
+ parent.reload
+ child.reload
+
+ assert_equal [parent.id, nil, 1, 4], [parent.root_id, parent.parent_id, parent.lft, parent.rgt]
+ assert_equal [parent.id, parent.id, 2, 3], [child.root_id, child.parent_id, child.lft, child.rgt]
+ end
+
+ def test_creating_a_child_in_different_project_should_not_validate
+ issue = create_issue!
+ child = Issue.new(:project_id => 2, :tracker_id => 1, :author_id => 1, :subject => 'child', :parent_issue_id => issue.id)
+ assert !child.save
+ assert_not_nil child.errors.on(:parent_issue_id)
+ end
+
+ def test_move_a_root_to_child
+ parent1 = create_issue!
+ parent2 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+
+ parent2.parent_issue_id = parent1.id
+ parent2.save!
+ child.reload
+ parent1.reload
+ parent2.reload
+
+ assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent1.id, 4, 5], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent1.id, 2, 3], [child.root_id, child.lft, child.rgt]
+ end
+
+ def test_move_a_child_to_root
+ parent1 = create_issue!
+ parent2 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+
+ child.parent_issue_id = nil
+ child.save!
+ child.reload
+ parent1.reload
+ parent2.reload
+
+ assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [child.id, 1, 2], [child.root_id, child.lft, child.rgt]
+ end
+
+ def test_move_a_child_to_another_issue
+ parent1 = create_issue!
+ parent2 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+
+ child.parent_issue_id = parent2.id
+ child.save!
+ child.reload
+ parent1.reload
+ parent2.reload
+
+ assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, 1, 4], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent2.id, 2, 3], [child.root_id, child.lft, child.rgt]
+ end
+
+ def test_move_a_child_with_descendants_to_another_issue
+ parent1 = create_issue!
+ parent2 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+ grandchild = create_issue!(:parent_issue_id => child.id)
+
+ parent1.reload
+ parent2.reload
+ child.reload
+ grandchild.reload
+
+ assert_equal [parent1.id, 1, 6], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, 1, 2], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent1.id, 2, 5], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent1.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
+
+ child.reload.parent_issue_id = parent2.id
+ child.save!
+ child.reload
+ grandchild.reload
+ parent1.reload
+ parent2.reload
+
+ assert_equal [parent1.id, 1, 2], [parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [parent2.id, 1, 6], [parent2.root_id, parent2.lft, parent2.rgt]
+ assert_equal [parent2.id, 2, 5], [child.root_id, child.lft, child.rgt]
+ assert_equal [parent2.id, 3, 4], [grandchild.root_id, grandchild.lft, grandchild.rgt]
+ end
+
+ def test_move_a_child_with_descendants_to_another_project
+ parent1 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+ grandchild = create_issue!(:parent_issue_id => child.id)
+
+ assert child.reload.move_to_project(Project.find(2))
+ child.reload
+ grandchild.reload
+ parent1.reload
+
+ assert_equal [1, parent1.id, 1, 2], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [2, child.id, 1, 4], [child.project_id, child.root_id, child.lft, child.rgt]
+ assert_equal [2, child.id, 2, 3], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
+ end
+
+ def test_invalid_move_to_another_project
+ parent1 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+ grandchild = create_issue!(:parent_issue_id => child.id, :tracker_id => 2)
+ Project.find(2).tracker_ids = [1]
+
+ parent1.reload
+ assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+
+ # child can not be moved to Project 2 because its child is on a disabled tracker
+ assert_equal false, Issue.find(child.id).move_to_project(Project.find(2))
+ child.reload
+ grandchild.reload
+ parent1.reload
+
+ # no change
+ assert_equal [1, parent1.id, 1, 6], [parent1.project_id, parent1.root_id, parent1.lft, parent1.rgt]
+ assert_equal [1, parent1.id, 2, 5], [child.project_id, child.root_id, child.lft, child.rgt]
+ assert_equal [1, parent1.id, 3, 4], [grandchild.project_id, grandchild.root_id, grandchild.lft, grandchild.rgt]
+ end
+
+ def test_moving_an_issue_to_a_descendant_should_not_validate
+ parent1 = create_issue!
+ parent2 = create_issue!
+ child = create_issue!(:parent_issue_id => parent1.id)
+ grandchild = create_issue!(:parent_issue_id => child.id)
+
+ child.reload
+ child.parent_issue_id = grandchild.id
+ assert !child.save
+ assert_not_nil child.errors.on(:parent_issue_id)
+ end
+
+ def test_moving_an_issue_should_keep_valid_relations_only
+ issue1 = create_issue!
+ issue2 = create_issue!
+ issue3 = create_issue!(:parent_issue_id => issue2.id)
+ issue4 = create_issue!
+ r1 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue2, :relation_type => IssueRelation::TYPE_PRECEDES)
+ r2 = IssueRelation.create!(:issue_from => issue1, :issue_to => issue3, :relation_type => IssueRelation::TYPE_PRECEDES)
+ r3 = IssueRelation.create!(:issue_from => issue2, :issue_to => issue4, :relation_type => IssueRelation::TYPE_PRECEDES)
+ issue2.reload
+ issue2.parent_issue_id = issue1.id
+ issue2.save!
+ assert !IssueRelation.exists?(r1.id)
+ assert !IssueRelation.exists?(r2.id)
+ assert IssueRelation.exists?(r3.id)
+ end
+
+ def test_destroy_should_destroy_children
+ issue1 = create_issue!
+ issue2 = create_issue!
+ issue3 = create_issue!(:parent_issue_id => issue2.id)
+ issue4 = create_issue!(:parent_issue_id => issue1.id)
+ issue2.reload.destroy
+ issue1.reload
+ issue4.reload
+ assert !Issue.exists?(issue2.id)
+ assert !Issue.exists?(issue3.id)
+ assert_equal [issue1.id, 1, 4], [issue1.root_id, issue1.lft, issue1.rgt]
+ assert_equal [issue1.id, 2, 3], [issue4.root_id, issue4.lft, issue4.rgt]
+ end
+
+ def test_parent_priority_should_be_the_highest_child_priority
+ parent = create_issue!(:priority => IssuePriority.find_by_name('Normal'))
+ # Create children
+ child1 = create_issue!(:priority => IssuePriority.find_by_name('High'), :parent_issue_id => parent.id)
+ assert_equal 'High', parent.reload.priority.name
+ child2 = create_issue!(:priority => IssuePriority.find_by_name('Immediate'), :parent_issue_id => child1.id)
+ assert_equal 'Immediate', child1.reload.priority.name
+ assert_equal 'Immediate', parent.reload.priority.name
+ child3 = create_issue!(:priority => IssuePriority.find_by_name('Low'), :parent_issue_id => parent.id)
+ assert_equal 'Immediate', parent.reload.priority.name
+ # Destroy a child
+ child1.destroy
+ assert_equal 'Low', parent.reload.priority.name
+ # Update a child
+ child3.reload.priority = IssuePriority.find_by_name('Normal')
+ child3.save!
+ assert_equal 'Normal', parent.reload.priority.name
+ end
+
+ def test_parent_dates_should_be_lowest_start_and_highest_due_dates
+ parent = create_issue!
+ create_issue!(:start_date => '2010-01-25', :due_date => '2010-02-15', :parent_issue_id => parent.id)
+ create_issue!( :due_date => '2010-02-13', :parent_issue_id => parent.id)
+ create_issue!(:start_date => '2010-02-01', :due_date => '2010-02-22', :parent_issue_id => parent.id)
+ parent.reload
+ assert_equal Date.parse('2010-01-25'), parent.start_date
+ assert_equal Date.parse('2010-02-22'), parent.due_date
+ end
+
+ def test_parent_done_ratio_should_be_average_done_ratio_of_leaves
+ parent = create_issue!
+ create_issue!(:done_ratio => 20, :parent_issue_id => parent.id)
+ assert_equal 20, parent.reload.done_ratio
+ create_issue!(:done_ratio => 70, :parent_issue_id => parent.id)
+ assert_equal 45, parent.reload.done_ratio
+
+ child = create_issue!(:done_ratio => 0, :parent_issue_id => parent.id)
+ assert_equal 30, parent.reload.done_ratio
+
+ create_issue!(:done_ratio => 30, :parent_issue_id => child.id)
+ assert_equal 30, child.reload.done_ratio
+ assert_equal 40, parent.reload.done_ratio
+ end
+
+ def test_parent_done_ratio_should_be_weighted_by_estimated_times_if_any
+ parent = create_issue!
+ create_issue!(:estimated_hours => 10, :done_ratio => 20, :parent_issue_id => parent.id)
+ assert_equal 20, parent.reload.done_ratio
+ create_issue!(:estimated_hours => 20, :done_ratio => 50, :parent_issue_id => parent.id)
+ assert_equal (50 * 20 + 20 * 10) / 30, parent.reload.done_ratio
+ end
+
+ def test_parent_estimate_should_be_sum_of_leaves
+ parent = create_issue!
+ create_issue!(:estimated_hours => nil, :parent_issue_id => parent.id)
+ assert_equal nil, parent.reload.estimated_hours
+ create_issue!(:estimated_hours => 5, :parent_issue_id => parent.id)
+ assert_equal 5, parent.reload.estimated_hours
+ create_issue!(:estimated_hours => 7, :parent_issue_id => parent.id)
+ assert_equal 12, parent.reload.estimated_hours
+ end
+
+ def test_project_copy_should_copy_issue_tree
+ p = Project.create!(:name => 'Tree copy', :identifier => 'tree-copy', :tracker_ids => [1, 2])
+ i1 = create_issue!(:project_id => p.id, :subject => 'i1')
+ i2 = create_issue!(:project_id => p.id, :subject => 'i2', :parent_issue_id => i1.id)
+ i3 = create_issue!(:project_id => p.id, :subject => 'i3', :parent_issue_id => i1.id)
+ i4 = create_issue!(:project_id => p.id, :subject => 'i4', :parent_issue_id => i2.id)
+ i5 = create_issue!(:project_id => p.id, :subject => 'i5')
+ c = Project.new(:name => 'Copy', :identifier => 'copy', :tracker_ids => [1, 2])
+ c.copy(p, :only => 'issues')
+ c.reload
+
+ assert_equal 5, c.issues.count
+ ic1, ic2, ic3, ic4, ic5 = c.issues.find(:all, :order => 'subject')
+ assert ic1.root?
+ assert_equal ic1, ic2.parent
+ assert_equal ic1, ic3.parent
+ assert_equal ic2, ic4.parent
+ assert ic5.root?
+ end
+
+ # Helper that creates an issue with default attributes
+ def create_issue!(attributes={})
+ Issue.create!({:project_id => 1, :tracker_id => 1, :author_id => 1, :subject => 'test'}.merge(attributes))
+ end
+end
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index cf5369726..de53125f5 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -329,7 +329,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_with_same_category
issue = Issue.find(1)
- assert issue.move_to(Project.find(2))
+ assert issue.move_to_project(Project.find(2))
issue.reload
assert_equal 2, issue.project_id
# Category changes
@@ -340,7 +340,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_without_same_category
issue = Issue.find(2)
- assert issue.move_to(Project.find(2))
+ assert issue.move_to_project(Project.find(2))
issue.reload
assert_equal 2, issue.project_id
# Category cleared
@@ -350,7 +350,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_should_clear_fixed_version_when_not_shared
issue = Issue.find(1)
issue.update_attribute(:fixed_version_id, 1)
- assert issue.move_to(Project.find(2))
+ assert issue.move_to_project(Project.find(2))
issue.reload
assert_equal 2, issue.project_id
# Cleared fixed_version
@@ -360,7 +360,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_should_keep_fixed_version_when_shared_with_the_target_project
issue = Issue.find(1)
issue.update_attribute(:fixed_version_id, 4)
- assert issue.move_to(Project.find(5))
+ assert issue.move_to_project(Project.find(5))
issue.reload
assert_equal 5, issue.project_id
# Keep fixed_version
@@ -370,7 +370,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_should_clear_fixed_version_when_not_shared_with_the_target_project
issue = Issue.find(1)
issue.update_attribute(:fixed_version_id, 1)
- assert issue.move_to(Project.find(5))
+ assert issue.move_to_project(Project.find(5))
issue.reload
assert_equal 5, issue.project_id
# Cleared fixed_version
@@ -380,7 +380,7 @@ class IssueTest < ActiveSupport::TestCase
def test_move_to_another_project_should_keep_fixed_version_when_shared_systemwide
issue = Issue.find(1)
issue.update_attribute(:fixed_version_id, 7)
- assert issue.move_to(Project.find(2))
+ assert issue.move_to_project(Project.find(2))
issue.reload
assert_equal 2, issue.project_id
# Keep fixed_version
@@ -392,7 +392,7 @@ class IssueTest < ActiveSupport::TestCase
target = Project.find(2)
target.tracker_ids = [3]
target.save
- assert_equal false, issue.move_to(target)
+ assert_equal false, issue.move_to_project(target)
issue.reload
assert_equal 1, issue.project_id
end
@@ -401,7 +401,7 @@ class IssueTest < ActiveSupport::TestCase
issue = Issue.find(1)
copy = nil
assert_difference 'Issue.count' do
- copy = issue.move_to(issue.project, nil, :copy => true)
+ copy = issue.move_to_project(issue.project, nil, :copy => true)
end
assert_kind_of Issue, copy
assert_equal issue.project, copy.project
@@ -412,8 +412,9 @@ class IssueTest < ActiveSupport::TestCase
issue = Issue.find(1)
copy = nil
assert_difference 'Issue.count' do
- copy = issue.move_to(Project.find(3), Tracker.find(2), :copy => true)
+ copy = issue.move_to_project(Project.find(3), Tracker.find(2), :copy => true)
end
+ copy.reload
assert_kind_of Issue, copy
assert_equal Project.find(3), copy.project
assert_equal Tracker.find(2), copy.tracker
@@ -421,7 +422,7 @@ class IssueTest < ActiveSupport::TestCase
assert_nil copy.custom_value_for(2)
end
- context "#move_to" do
+ context "#move_to_project" do
context "as a copy" do
setup do
@issue = Issue.find(1)
@@ -429,24 +430,24 @@ class IssueTest < ActiveSupport::TestCase
end
should "allow assigned_to changes" do
- @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
+ @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:assigned_to_id => 3}})
assert_equal 3, @copy.assigned_to_id
end
should "allow status changes" do
- @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}})
+ @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:status_id => 2}})
assert_equal 2, @copy.status_id
end
should "allow start date changes" do
date = Date.today
- @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
+ @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:start_date => date}})
assert_equal date, @copy.start_date
end
should "allow due date changes" do
date = Date.today
- @copy = @issue.move_to(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}})
+ @copy = @issue.move_to_project(Project.find(3), Tracker.find(2), {:copy => true, :attributes => {:due_date => date}})
assert_equal date, @copy.due_date
end
@@ -457,7 +458,7 @@ class IssueTest < ActiveSupport::TestCase
issue = Issue.find(12)
assert issue.recipients.include?(issue.author.mail)
# move the issue to a private project
- copy = issue.move_to(Project.find(5), Tracker.find(2), :copy => true)
+ copy = issue.move_to_project(Project.find(5), Tracker.find(2), :copy => true)
# author is not a member of project anymore
assert !copy.recipients.include?(copy.author.mail)
end
diff --git a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
index a5598dbd2..01a61bf48 100644
--- a/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
+++ b/vendor/plugins/acts_as_customizable/lib/acts_as_customizable.rb
@@ -77,6 +77,13 @@ module Redmine
@custom_field_values = nil
end
+ def reset_custom_values!
+ @custom_field_values = nil
+ @custom_field_values_changed = true
+ values = custom_values.inject({}) {|h,v| h[v.custom_field_id] = v.value; h}
+ custom_values.each {|cv| cv.destroy unless custom_field_values.include?(cv)}
+ end
+
module ClassMethods
end
end
diff --git a/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb b/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
index 6be3c5e42..9c4ee0f22 100644
--- a/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
+++ b/vendor/plugins/awesome_nested_set/lib/awesome_nested_set.rb
@@ -256,7 +256,7 @@ module CollectiveIdea #:nodoc:
end
def leaf?
- right - left == 1
+ new_record? || (right - left == 1)
end
# Returns true is this is a child node