Fixed: error when creating a project with a version format custom field (#10218).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8865 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-02-13 18:57:12 +00:00
parent 7fa18cad57
commit cccfed7006
2 changed files with 16 additions and 4 deletions

View File

@ -411,16 +411,21 @@ class Project < ActiveRecord::Base
# Returns a scope of the Versions used by the project # Returns a scope of the Versions used by the project
def shared_versions def shared_versions
@shared_versions ||= begin if new_record?
r = root? ? self : root
Version.scoped(:include => :project, Version.scoped(:include => :project,
:conditions => "#{Project.table_name}.id = #{id}" + :conditions => "#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND #{Version.table_name}.sharing = 'system'")
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" + else
@shared_versions ||= begin
r = root? ? self : root
Version.scoped(:include => :project,
:conditions => "#{Project.table_name}.id = #{id}" +
" OR (#{Project.table_name}.status = #{Project::STATUS_ACTIVE} AND (" +
" #{Version.table_name}.sharing = 'system'" + " #{Version.table_name}.sharing = 'system'" +
" OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" + " OR (#{Project.table_name}.lft >= #{r.lft} AND #{Project.table_name}.rgt <= #{r.rgt} AND #{Version.table_name}.sharing = 'tree')" +
" 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')" + " OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt} AND #{Version.table_name}.sharing = 'hierarchy')" +
"))") "))")
end
end end
end end

View File

@ -598,6 +598,13 @@ class ProjectTest < ActiveSupport::TestCase
assert !versions.collect(&:id).include?(6) assert !versions.collect(&:id).include?(6)
end end
def test_shared_versions_for_new_project_should_include_system_shared_versions
p = Project.find(5)
v = Version.create!(:name => 'system_sharing', :project => p, :sharing => 'system')
assert_include v, Project.new.shared_versions
end
def test_next_identifier def test_next_identifier
ProjectCustomField.delete_all ProjectCustomField.delete_all
Project.create!(:name => 'last', :identifier => 'p2008040') Project.create!(:name => 'last', :identifier => 'p2008040')