summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-10-21 22:34:34 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-10-21 22:34:34 +0000
commit29301c8a381aa5995a0ce2e10ad91f210dc6464f (patch)
tree5d855e29cb37ca5e2dc28a76a9b1bd4c781cce08
parente76d4c5c4c3f2beb8be1f441148e4627a14d37d1 (diff)
downloadredmine-29301c8a381aa5995a0ce2e10ad91f210dc6464f.tar.gz
redmine-29301c8a381aa5995a0ce2e10ad91f210dc6464f.zip
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
-rw-r--r--app/models/enumeration.rb8
-rw-r--r--db/migrate/20090403001910_add_project_to_enumerations.rb11
-rw-r--r--db/migrate/20090406161854_add_parent_id_to_enumerations.rb9
-rw-r--r--test/unit/enumeration_test.rb22
4 files changed, 50 insertions, 0 deletions
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 436e82373..2d27d2f86 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -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
diff --git a/db/migrate/20090403001910_add_project_to_enumerations.rb b/db/migrate/20090403001910_add_project_to_enumerations.rb
new file mode 100644
index 000000000..a3db6d51e
--- /dev/null
+++ b/db/migrate/20090403001910_add_project_to_enumerations.rb
@@ -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
index 000000000..2c1b1780d
--- /dev/null
+++ b/db/migrate/20090406161854_add_parent_id_to_enumerations.rb
@@ -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
diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb
index 663077352..abb15353a 100644
--- a/test/unit/enumeration_test.rb
+++ b/test/unit/enumeration_test.rb
@@ -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