Defect #26023 » 26023_test_added.patch
app/models/issue_category.rb | ||
---|---|---|
28 | 28 |
safe_attributes 'name', 'assigned_to_id' |
29 | 29 | |
30 | 30 |
scope :named, lambda {|arg| where("LOWER(#{table_name}.name) = LOWER(?)", arg.to_s.strip)} |
31 |
scope :visible, lambda {|*args| |
|
32 |
joins(:project). |
|
33 |
where(Project.allowed_to_condition(args.first || User.current, :view_issues)) |
|
34 |
} |
|
31 | 35 | |
32 | 36 |
alias :destroy_without_reassign :destroy |
33 | 37 |
app/models/issue_query.rb | ||
---|---|---|
124 | 124 | |
125 | 125 |
add_available_filter "category_id", |
126 | 126 |
:type => :list_optional, |
127 |
:values => lambda { project.issue_categories.collect{|s| [s.name, s.id.to_s] } } if project
|
|
127 |
:values => lambda { issue_category_values }
|
|
128 | 128 | |
129 | 129 |
add_available_filter "subject", :type => :text |
130 | 130 |
add_available_filter "description", :type => :text |
app/models/project.rb | ||
---|---|---|
330 | 330 |
@users = nil |
331 | 331 |
@shared_versions = nil |
332 | 332 |
@rolled_up_versions = nil |
333 |
@rolled_up_issue_categories = nil |
|
333 | 334 |
@rolled_up_trackers = nil |
334 | 335 |
@rolled_up_statuses = nil |
335 | 336 |
@rolled_up_custom_fields = nil |
... | ... | |
482 | 483 |
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED) |
483 | 484 |
end |
484 | 485 | |
486 |
def rolled_up_issue_categories |
|
487 |
@rolled_up_issue_categories ||= |
|
488 |
IssueCategory. |
|
489 |
joins(:project). |
|
490 |
where("#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status <> ?", lft, rgt, STATUS_ARCHIVED) |
|
491 |
end |
|
492 | ||
485 | 493 |
# Returns a scope of the Versions used by the project |
486 | 494 |
def shared_versions |
487 | 495 |
if new_record? |
app/models/query.rb | ||
---|---|---|
570 | 570 |
watcher_values |
571 | 571 |
end |
572 | 572 | |
573 |
def issue_category_values |
|
574 |
categories = [] |
|
575 |
if project |
|
576 |
categories = project.rolled_up_issue_categories.to_a |
|
577 |
else |
|
578 |
categories = IssueCategory.visible.to_a |
|
579 |
end |
|
580 |
categories.collect {|c| [c.name, c.id.to_s] } |
|
581 |
end |
|
582 | ||
573 | 583 |
# Returns a scope of issue custom fields that are available as columns or filters |
574 | 584 |
def issue_custom_fields |
575 | 585 |
if project |
test/unit/project_test.rb | ||
---|---|---|
555 | 555 |
project.rolled_up_versions.sort |
556 | 556 |
end |
557 | 557 | |
558 |
test "#rolled_up_issue_categories should include the categories for the current project" do |
|
559 |
project = Project.generate! |
|
560 |
current_category_1 = IssueCategory.create!(:name => 'Current Category 1' ,:project => project) |
|
561 |
current_category_2 = IssueCategory.create!(:name => 'Current Category 2' ,:project => project) |
|
562 |
expected_categories = [current_category_1, current_category_2].sort |
|
563 | ||
564 |
assert_equal expected_categories, project.rolled_up_issue_categories.sort |
|
565 |
end |
|
566 | ||
567 |
test "#rolled_up_issue_categories should include categories for a subproject" do |
|
568 |
project = Project.generate! |
|
569 |
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project) |
|
570 |
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project) |
|
571 |
subproject = Project.generate_with_parent!(project) |
|
572 |
subproject_category = IssueCategory.create!(:name => 'Subproject Category' ,:project => subproject) |
|
573 |
expected_categories = [parent_category_1, parent_category_2, subproject_category].sort |
|
574 | ||
575 |
assert_equal expected_categories, project.rolled_up_issue_categories.sort |
|
576 |
end |
|
577 | ||
578 |
test "#rolled_up_issue_categories should include categories for a sub-subproject" do |
|
579 |
project = Project.generate! |
|
580 |
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project) |
|
581 |
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project) |
|
582 |
subproject = Project.generate_with_parent!(project) |
|
583 |
sub_subproject = Project.generate_with_parent!(subproject) |
|
584 |
sub_subproject_category = IssueCategory.create!(:name => 'Sub Subproject Category' ,:project => sub_subproject) |
|
585 |
project.reload |
|
586 |
expected_categories = [parent_category_1, parent_category_2, sub_subproject_category].sort |
|
587 | ||
588 |
assert_equal expected_categories, project.rolled_up_issue_categories.sort |
|
589 |
end |
|
590 | ||
591 |
test "#rolled_up_issue_categories should only check active projects" do |
|
592 |
project = Project.generate! |
|
593 |
parent_category_1 = IssueCategory.create!(:name => 'Parent Category 1' ,:project => project) |
|
594 |
parent_category_2 = IssueCategory.create!(:name => 'Parent Category 2' ,:project => project) |
|
595 |
subproject = Project.generate_with_parent!(project) |
|
596 |
subproject_category = IssueCategory.create!(:name => 'Subproject Category' ,:project => subproject) |
|
597 |
assert subproject.archive |
|
598 |
project.reload |
|
599 |
expected_categories = [parent_category_1, parent_category_2].sort |
|
600 | ||
601 |
assert !subproject.active? |
|
602 |
assert_equal expected_categories, project.rolled_up_issue_categories.sort |
|
603 |
end |
|
604 | ||
558 | 605 |
def test_shared_versions_none_sharing |
559 | 606 |
p = Project.find(5) |
560 | 607 |
v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none') |