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