diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index cdbb7f64f..e7c123ab7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -295,7 +295,9 @@ class ProjectsController < ApplicationController @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] - @versions = @project.shared_versions.sort + @versions = @project.shared_versions || [] + @versions += @project.rolled_up_versions.visible if @with_subprojects + @versions = @versions.uniq.sort @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed] @issues_by_version = {} diff --git a/app/models/project.rb b/app/models/project.rb index 8d6303224..931f89b55 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -336,6 +336,13 @@ class Project < ActiveRecord::Base end end end + + # Returns a scope of the Versions on subprojects + def rolled_up_versions + @rolled_up_versions ||= + Version.scoped(:include => :project, + :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt]) + end # Returns a scope of the Versions used by the project def shared_versions diff --git a/test/functional/projects_controller_test.rb b/test/functional/projects_controller_test.rb index ded7b8b1b..ac639d737 100644 --- a/test/functional/projects_controller_test.rb +++ b/test/functional/projects_controller_test.rb @@ -364,12 +364,14 @@ class ProjectsControllerTest < ActionController::TestCase end def test_roadmap_showing_subprojects_versions + @subproject_version = Version.generate!(:project => Project.find(3)) get :roadmap, :id => 1, :with_subprojects => 1 assert_response :success assert_template 'roadmap' assert_not_nil assigns(:versions) - # Version on subproject appears - assert assigns(:versions).include?(Version.find(4)) + + assert assigns(:versions).include?(Version.find(4)), "Shared version not found" + assert assigns(:versions).include?(@subproject_version), "Subproject version not found" end def test_project_activity get :activity, :id => 1, :with_subprojects => 0 diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index fc08bb1f7..7870dc2a5 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -360,6 +360,59 @@ class ProjectTest < ActiveSupport::TestCase assert_equal [1,2], parent.rolled_up_trackers.collect(&:id) end + + context "#rolled_up_versions" do + setup do + @project = Project.generate! + @parent_version_1 = Version.generate!(:project => @project) + @parent_version_2 = Version.generate!(:project => @project) + end + + should "include the versions for the current project" do + assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions + end + + should "include versions for a subproject" do + @subproject = Project.generate! + @subproject.set_parent!(@project) + @subproject_version = Version.generate!(:project => @subproject) + + assert_same_elements [ + @parent_version_1, + @parent_version_2, + @subproject_version + ], @project.rolled_up_versions + end + + should "include versions for a sub-subproject" do + @subproject = Project.generate! + @subproject.set_parent!(@project) + @sub_subproject = Project.generate! + @sub_subproject.set_parent!(@subproject) + @sub_subproject_version = Version.generate!(:project => @sub_subproject) + + @project.reload + + assert_same_elements [ + @parent_version_1, + @parent_version_2, + @sub_subproject_version + ], @project.rolled_up_versions + end + + + should "only check active projects" do + @subproject = Project.generate! + @subproject.set_parent!(@project) + @subproject_version = Version.generate!(:project => @subproject) + assert @subproject.archive + + @project.reload + + assert !@subproject.active? + assert_same_elements [@parent_version_1, @parent_version_2], @project.rolled_up_versions + end + end def test_shared_versions_none_sharing p = Project.find(5)