@@ -85,6 +85,10 class Issue < ActiveRecord::Base | |||
|
85 | 85 | scope :on_active_project, lambda { |
|
86 | 86 | includes(:status, :project, :tracker).where("#{Project.table_name}.status = ?", Project::STATUS_ACTIVE) |
|
87 | 87 | } |
|
88 | scope :fixed_version, lambda {|versions| | |
|
89 | ids = [versions].flatten.compact.map {|v| v.is_a?(Version) ? v.id : v} | |
|
90 | ids.any? ? where(:fixed_version_id => ids) : where('1=0') | |
|
91 | } | |
|
88 | 92 | |
|
89 | 93 | before_create :default_assign |
|
90 | 94 | before_save :close_duplicates, :update_done_ratio_from_issue_status, :force_updated_on_change |
@@ -289,6 +289,8 class Project < ActiveRecord::Base | |||
|
289 | 289 | @allowed_parents = nil |
|
290 | 290 | @allowed_permissions = nil |
|
291 | 291 | @actions_allowed = nil |
|
292 | @start_date = nil | |
|
293 | @due_date = nil | |
|
292 | 294 | super |
|
293 | 295 | end |
|
294 | 296 | |
@@ -538,20 +540,20 class Project < ActiveRecord::Base | |||
|
538 | 540 | |
|
539 | 541 | # The earliest start date of a project, based on it's issues and versions |
|
540 | 542 | def start_date |
|
541 | [ | |
|
543 | @start_date ||= [ | |
|
542 | 544 | issues.minimum('start_date'), |
|
543 |
shared_versions. |
|
|
544 |
shared_versions. |
|
|
545 |
] |
|
|
545 | shared_versions.minimum('effective_date'), | |
|
546 | Issue.fixed_version(shared_versions).minimum('start_date') | |
|
547 | ].compact.min | |
|
546 | 548 | end |
|
547 | 549 | |
|
548 | 550 | # The latest due date of an issue or version |
|
549 | 551 | def due_date |
|
550 | [ | |
|
552 | @due_date ||= [ | |
|
551 | 553 | issues.maximum('due_date'), |
|
552 |
shared_versions. |
|
|
553 |
shared_versions |
|
|
554 |
] |
|
|
554 | shared_versions.maximum('effective_date'), | |
|
555 | Issue.fixed_version(shared_versions).maximum('due_date') | |
|
556 | ].compact.max | |
|
555 | 557 | end |
|
556 | 558 | |
|
557 | 559 | def overdue? |
@@ -309,6 +309,16 class IssueTest < ActiveSupport::TestCase | |||
|
309 | 309 | assert_equal issues, issues.select(&:closed?) |
|
310 | 310 | end |
|
311 | 311 | |
|
312 | def test_fixed_version_scope_with_a_version_should_return_its_fixed_issues | |
|
313 | version = Version.find(2) | |
|
314 | assert version.fixed_issues.any? | |
|
315 | assert_equal version.fixed_issues.to_a.sort, Issue.fixed_version(version).to_a.sort | |
|
316 | end | |
|
317 | ||
|
318 | def test_fixed_version_scope_with_empty_array_should_return_no_result | |
|
319 | assert_equal 0, Issue.fixed_version([]).count | |
|
320 | end | |
|
321 | ||
|
312 | 322 | def test_errors_full_messages_should_include_custom_fields_errors |
|
313 | 323 | field = IssueCustomField.find_by_name('Database') |
|
314 | 324 |
General Comments 0
You need to be logged in to leave comments.
Login now