OSDN Git Service

Added project specific Enumeration overrides.
authorEric Davis <edavis@littlestreamsoftware.com>
Wed, 21 Oct 2009 22:34:34 +0000 (22:34 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Wed, 21 Oct 2009 22:34:34 +0000 (22:34 +0000)
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

app/models/enumeration.rb
db/migrate/20090403001910_add_project_to_enumerations.rb [new file with mode: 0644]
db/migrate/20090406161854_add_parent_id_to_enumerations.rb [new file with mode: 0644]
test/unit/enumeration_test.rb

index 436e823..2d27d2f 100644 (file)
 # 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
   
diff --git a/db/migrate/20090403001910_add_project_to_enumerations.rb b/db/migrate/20090403001910_add_project_to_enumerations.rb
new file mode 100644 (file)
index 0000000..a3db6d5
--- /dev/null
@@ -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
diff --git a/db/migrate/20090406161854_add_parent_id_to_enumerations.rb b/db/migrate/20090406161854_add_parent_id_to_enumerations.rb
new file mode 100644 (file)
index 0000000..2c1b178
--- /dev/null
@@ -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
index 6630773..abb1535 100644 (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