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
# 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
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
--- /dev/null
+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
--- /dev/null
+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
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