@@ -180,20 +180,20 module IssuesHelper | |||||
180 | s.html_safe |
|
180 | s.html_safe | |
181 | end |
|
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 | def issues_destroy_confirmation_message(issues) |
|
190 | def issues_destroy_confirmation_message(issues) | |
184 | issues = [issues] unless issues.is_a?(Array) |
|
191 | issues = [issues] unless issues.is_a?(Array) | |
185 | message = l(:text_issues_destroy_confirmation) |
|
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 | if descendant_count > 0 |
|
195 | if descendant_count > 0 | |
188 | issues.each do |issue| |
|
196 | message << "\n" + l(:text_issues_destroy_descendants_confirmation, :count => descendant_count) | |
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 |
|
|||
197 | end |
|
197 | end | |
198 | message |
|
198 | message | |
199 | end |
|
199 | end |
@@ -68,6 +68,16 class IssuesHelperTest < ActionView::TestCase | |||||
68 | issues_destroy_confirmation_message(Issue.find([1, 2])) |
|
68 | issues_destroy_confirmation_message(Issue.find([1, 2])) | |
69 | end |
|
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 | test 'show_detail with no_html should show a changing attribute' do |
|
81 | test 'show_detail with no_html should show a changing attribute' do | |
72 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', |
|
82 | detail = JournalDetail.new(:property => 'attr', :old_value => '40', | |
73 | :value => '100', :prop_key => 'done_ratio') |
|
83 | :value => '100', :prop_key => 'done_ratio') |
General Comments 0
You need to be logged in to leave comments.
Login now