Project

General

Profile

Feature #10989 » cant_close_before_sub_issues_closed.patch

Marius BĂLTEANU, 2016-09-20 10:15

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|
......
757 757
    end
758 758
  end
759 759

  
760
  # Validates the issue against open subtasks
761
  def validate_subtasks
762
    if closing? && descendants.open.any?
763
      errors.add :base, I18n.t(:error_can_not_close_issue_with_open_subtasks)
764
    end
765
  end
766

  
760 767
  # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
761 768
  # even if the user turns off the setting later
762 769
  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: "An issue with open subtasks cannot be closed"
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
306 306
    parent.generate_child!(:estimated_hours => 7)
307 307
    assert_equal 12, parent.reload.total_estimated_hours
308 308
  end
309

  
310
  def test_parent_with_open_subtasks_cannot_be_closed
311
    parent = Issue.generate!
312
    parent.generate_child!()
313
    parent.reload
314
    parent.status = IssueStatus.where(:is_closed => true).first
315
    parent.save
316

  
317
    assert_include 'An issue with open subtasks cannot be closed', parent.errors.full_messages
318
  end
319

  
320
  def test_parent_with_closed_subtasks_can_be_closed
321
    parent = Issue.generate!
322
    parent.generate_child!(:status => IssueStatus.where(:is_closed => true).first)
323
    parent.reload
324
    closed_status = IssueStatus.where(:is_closed => true).first
325
    parent.status = closed_status
326

  
327
    assert_save parent
328
    assert parent.status, closed_status
329
  end
309 330
end
(1-1/3)