]> source.dussan.org Git - redmine.git/commitdiff
Fixes Project#shared_versions for descendants sharing (#465).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 7 Dec 2009 19:28:47 +0000 (19:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Mon, 7 Dec 2009 19:28:47 +0000 (19:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3130 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/project_test.rb

index 77de59f44bb8cd2bf06c8a044a9e9612b51f62c1..593e60c9e078c20e560498c3d8acd97014057fb6 100644 (file)
@@ -340,8 +340,8 @@ class Project < ActiveRecord::Base
                                     " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
                                           " #{Version.table_name}.sharing = 'system'" +
                                           " OR (#{Project.table_name}.lft >= #{root.lft} AND #{Project.table_name}.rgt <= #{root.rgt} AND #{Version.table_name}.sharing = 'tree')" +
-                                          " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
-                                          " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
+                                          " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" +
+                                          " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
                                           "))")
   end
 
index cbf9ce54f80b7c3219c785f459ebe9bf825ab9ad..748065ae78715ee4ea6bcc0fbf482f67e7e21fe7 100644 (file)
@@ -317,6 +317,56 @@ class ProjectTest < ActiveSupport::TestCase
     
     assert_equal [1,2], parent.rolled_up_trackers.collect(&:id)
   end
+  
+  def test_shared_versions_none_sharing
+    p = Project.find(5)
+    v = Version.create!(:name => 'none_sharing', :project => p, :sharing => 'none')
+    assert p.shared_versions.include?(v)
+    assert !p.children.first.shared_versions.include?(v)
+    assert !p.root.shared_versions.include?(v)
+    assert !p.siblings.first.shared_versions.include?(v)
+    assert !p.root.siblings.first.shared_versions.include?(v)
+  end
+
+  def test_shared_versions_descendants_sharing
+    p = Project.find(5)
+    v = Version.create!(:name => 'descendants_sharing', :project => p, :sharing => 'descendants')
+    assert p.shared_versions.include?(v)
+    assert p.children.first.shared_versions.include?(v)
+    assert !p.root.shared_versions.include?(v)
+    assert !p.siblings.first.shared_versions.include?(v)
+    assert !p.root.siblings.first.shared_versions.include?(v)
+  end
+  
+  def test_shared_versions_hierarchy_sharing
+    p = Project.find(5)
+    v = Version.create!(:name => 'hierarchy_sharing', :project => p, :sharing => 'hierarchy')
+    assert p.shared_versions.include?(v)
+    assert p.children.first.shared_versions.include?(v)
+    assert p.root.shared_versions.include?(v)
+    assert !p.siblings.first.shared_versions.include?(v)
+    assert !p.root.siblings.first.shared_versions.include?(v)
+  end
+
+  def test_shared_versions_tree_sharing
+    p = Project.find(5)
+    v = Version.create!(:name => 'tree_sharing', :project => p, :sharing => 'tree')
+    assert p.shared_versions.include?(v)
+    assert p.children.first.shared_versions.include?(v)
+    assert p.root.shared_versions.include?(v)
+    assert p.siblings.first.shared_versions.include?(v)
+    assert !p.root.siblings.first.shared_versions.include?(v)
+  end
+
+  def test_shared_versions_system_sharing
+    p = Project.find(5)
+    v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
+    assert p.shared_versions.include?(v)
+    assert p.children.first.shared_versions.include?(v)
+    assert p.root.shared_versions.include?(v)
+    assert p.siblings.first.shared_versions.include?(v)
+    assert p.root.siblings.first.shared_versions.include?(v)
+  end
 
   def test_shared_versions
     parent = Project.find(1)