@@ -411,16 +411,21 class Project < ActiveRecord::Base | |||||
411 |
|
411 | |||
412 | # Returns a scope of the Versions used by the project |
|
412 | # Returns a scope of the Versions used by the project | |
413 | def shared_versions |
|
413 | def shared_versions | |
414 | @shared_versions ||= begin |
|
414 | if new_record? | |
415 | r = root? ? self : root |
|
|||
416 | Version.scoped(:include => :project, |
|
415 | Version.scoped(:include => :project, | |
417 |
:conditions => "#{Project.table_name}. |
|
416 | :conditions => "#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND #{Version.table_name}.sharing = 'system'") | |
418 | " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" + |
|
417 | else | |
|
418 | @shared_versions ||= begin | |||
|
419 | r = root? ? self : root | |||
|
420 | Version.scoped(:include => :project, | |||
|
421 | :conditions => "#{Project.table_name}.id = #{id}" + | |||
|
422 | " OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" + | |||
419 | " #{Version.table_name}.sharing = 'system'" + |
|
423 | " #{Version.table_name}.sharing = 'system'" + | |
420 | " OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" + |
|
424 | " OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" + | |
421 | " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" + |
|
425 | " OR (#{Project.table_name}.lft < #{lft} AND #{Project.table_name}.rgt > #{rgt} AND #{Version.table_name}.sharing IN ('hierarchy', 'descendants'))" + | |
422 | " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" + |
|
426 | " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" + | |
423 | "))") |
|
427 | "))") | |
|
428 | end | |||
424 | end |
|
429 | end | |
425 | end |
|
430 | end | |
426 |
|
431 |
@@ -598,6 +598,13 class ProjectTest < ActiveSupport::TestCase | |||||
598 | assert !versions.collect(&:id).include?(6) |
|
598 | assert !versions.collect(&:id).include?(6) | |
599 | end |
|
599 | end | |
600 |
|
600 | |||
|
601 | def test_shared_versions_for_new_project_should_include_system_shared_versions | |||
|
602 | p = Project.find(5) | |||
|
603 | v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system') | |||
|
604 | ||||
|
605 | assert_include v, Project.new.shared_versions | |||
|
606 | end | |||
|
607 | ||||
601 | def test_next_identifier |
|
608 | def test_next_identifier | |
602 | ProjectCustomField.delete_all |
|
609 | ProjectCustomField.delete_all | |
603 | Project.create!(:name => 'last', :identifier => 'p2008040') |
|
610 | Project.create!(:name => 'last', :identifier => 'p2008040') |
General Comments 0
You need to be logged in to leave comments.
Login now