@@ -180,20 +180,20 module IssuesHelper | |||
|
180 | 180 | s.html_safe |
|
181 | 181 | end |
|
182 | 182 | |
|
183 | # Returns the number of descendants for an array of issues | |
|
184 | def issues_descendant_count(issues) | |
|
185 | ids = issues.reject(&:leaf?).map {|issue| issue.descendants.ids}.flatten.uniq | |
|
186 | ids -= issues.map(&:id) | |
|
187 | ids.size | |
|
188 | end | |
|
189 | ||
|
183 | 190 | def issues_destroy_confirmation_message(issues) |
|
184 | 191 | issues = [issues] unless issues.is_a?(Array) |
|
185 | 192 | message = l(:text_issues_destroy_confirmation) |
|
186 | descendant_count = issues.inject(0) {|memo, i| memo += (i.right - i.left - 1)/2} | |
|
193 | ||
|
194 | descendant_count = issues_descendant_count(issues) | |
|
187 | 195 | if descendant_count > 0 |
|
188 | issues.each do |issue| | |
|
189 | next if issue.root? | |
|
190 | issues.each do |other_issue| | |
|
191 | descendant_count -= 1 if issue.is_descendant_of?(other_issue) | |
|
192 | end | |
|
193 | end | |
|
194 | if descendant_count > 0 | |
|
195 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
|
196 | end | |
|
196 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
|
197 | 197 | end |
|
198 | 198 | message |
|
199 | 199 | end |
@@ -68,6 +68,16 class IssuesHelperTest < ActionView::TestCase | |||
|
68 | 68 | issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | def test_issues_destroy_confirmation_message_with_issues_that_share_descendants | |
|
72 | root = Issue.generate! | |
|
73 | child = Issue.generate!(:parent_issue_id => root.id) | |
|
74 | Issue.generate!(:parent_issue_id => child.id) | |
|
75 | ||
|
76 | assert_equal l(:text_issues_destroy_confirmation) + "\n" + | |
|
77 | l(:text_issues_destroy_descendants_confirmation, :count => 1), | |
|
78 | issues_destroy_confirmation_message([root.reload, child.reload]) | |
|
79 | end | |
|
80 | ||
|
71 | 81 | test 'show_detail with no_html should show a changing attribute' do |
|
72 | 82 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
73 | 83 | :value => '100', :prop_key => 'done_ratio') |
General Comments 0
You need to be logged in to leave comments.
Login now