Project

General

Profile

Feature #10989 » cant_close_before_sub_issues_closed_v2.patch

Marius BĂLTEANU, 2016-10-20 14:53

View differences:

app/models/issue.rb
73 73
  validates :estimated_hours, :numericality => {:greater_than_or_equal_to => 0, :allow_nil => true, :message => :invalid}
74 74
  validates :start_date, :date => true
75 75
  validates :due_date, :date => true
76
  validate :validate_issue, :validate_required_fields
76
  validate :validate_issue, :validate_required_fields, :validate_subtasks
77 77
  attr_protected :id
78 78

  
79 79
  scope :visible, lambda {|*args|
......
762 762
    end
763 763
  end
764 764

  
765
  # Validates the issue against open subtasks
766
  def validate_subtasks
767
    if closing? && descendants.open.any?
768
      errors.add :base, I18n.t(:error_can_not_close_issue_with_open_subtasks)
769
    end
770
  end
771

  
765 772
  # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
766 773
  # even if the user turns off the setting later
767 774
  def update_done_ratio_from_issue_status
config/locales/en.yml
215 215
  error_ldap_bind_credentials: "Invalid LDAP Account/Password"
216 216
  error_no_tracker_allowed_for_new_issue_in_project: "The project doesn't have any trackers for which you can create an issue"
217 217
  error_no_projects_with_tracker_allowed_for_new_issue: "There are no projects with trackers for which you can create an issue"
218
  error_can_not_close_issue_with_open_subtasks: "You cannot close an issue with open subtasks"
218 219

  
219 220
  mail_subject_lost_password: "Your %{value} password"
220 221
  mail_body_lost_password: 'To change your password, click on the following link:'
test/unit/issue_subtasking_test.rb
330 330
    parent.generate_child!(:estimated_hours => 7)
331 331
    assert_equal 12, parent.reload.total_estimated_hours
332 332
  end
333

  
334
  def test_parent_with_open_subtasks_cannot_be_closed
335
    parent = Issue.generate!
336
    parent.generate_child!()
337
    parent.reload
338
    parent.status = IssueStatus.where(:is_closed => true).first
339
    parent.save
340

  
341
    assert_include 'An issue with open subtasks cannot be closed', parent.errors.full_messages
342
  end
343

  
344
  def test_parent_with_closed_subtasks_can_be_closed
345
    parent = Issue.generate!
346
    parent.generate_child!(:status => IssueStatus.where(:is_closed => true).first)
347
    parent.reload
348
    closed_status = IssueStatus.where(:is_closed => true).first
349
    parent.status = closed_status
350

  
351
    assert_save parent
352
    assert parent.status, closed_status
353
  end
333 354
end
(2-2/3)