Added project specific Enumeration overrides.

These will be used to track if Enumeration's custom data or active state
is overridden on a project.  An overridden Enumeration is one that is associated
with a parent Enumeration.

  #4077

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2947 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Eric Davis 2009-10-21 22:34:34 +00:00
parent e76d4c5c4c
commit 29301c8a38
4 changed files with 50 additions and 0 deletions

View File

@ -16,8 +16,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class Enumeration < ActiveRecord::Base
belongs_to :project
acts_as_list :scope => 'type = \'#{type}\''
acts_as_customizable
acts_as_tree :order => 'position ASC'
before_destroy :check_integrity
@ -101,6 +104,11 @@ class Enumeration < ActiveRecord::Base
def in_use?
self.objects_count != 0
end
# Is this enumeration overiding a system level enumeration?
def is_override?
!self.parent.nil?
end
alias :destroy_without_reassign :destroy

View File

@ -0,0 +1,11 @@
class AddProjectToEnumerations < ActiveRecord::Migration
def self.up
add_column :enumerations, :project_id, :integer, :null => true, :default => nil
add_index :enumerations, :project_id
end
def self.down
remove_index :enumerations, :project_id
remove_column :enumerations, :project_id
end
end

View File

@ -0,0 +1,9 @@
class AddParentIdToEnumerations < ActiveRecord::Migration
def self.up
add_column :enumerations, :parent_id, :integer, :null => true, :default => nil
end
def self.down
remove_column :enumerations, :parent_id
end
end

View File

@ -86,4 +86,26 @@ class EnumerationTest < ActiveSupport::TestCase
assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
end
def test_should_belong_to_a_project
association = Enumeration.reflect_on_association(:project)
assert association, "No Project association found"
assert_equal :belongs_to, association.macro
end
def test_should_act_as_tree
enumeration = Enumeration.find(4)
assert enumeration.respond_to?(:parent)
assert enumeration.respond_to?(:children)
end
def test_is_override
# Defaults to off
enumeration = Enumeration.find(4)
assert !enumeration.is_override?
# Setup as an override
enumeration.parent = Enumeration.find(5)
assert enumeration.is_override?
end
end