@@ -0,0 +1,11 | |||
|
1 | class AddProjectToEnumerations < ActiveRecord::Migration | |
|
2 | def self.up | |
|
3 | add_column :enumerations, :project_id, :integer, :null => true, :default => nil | |
|
4 | add_index :enumerations, :project_id | |
|
5 | end | |
|
6 | ||
|
7 | def self.down | |
|
8 | remove_index :enumerations, :project_id | |
|
9 | remove_column :enumerations, :project_id | |
|
10 | end | |
|
11 | end |
@@ -0,0 +1,9 | |||
|
1 | class AddParentIdToEnumerations < ActiveRecord::Migration | |
|
2 | def self.up | |
|
3 | add_column :enumerations, :parent_id, :integer, :null => true, :default => nil | |
|
4 | end | |
|
5 | ||
|
6 | def self.down | |
|
7 | remove_column :enumerations, :parent_id | |
|
8 | end | |
|
9 | end |
@@ -16,8 +16,11 | |||
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class Enumeration < ActiveRecord::Base |
|
19 | belongs_to :project | |
|
20 | ||
|
19 | 21 | acts_as_list :scope => 'type = \'#{type}\'' |
|
20 | 22 | acts_as_customizable |
|
23 | acts_as_tree :order => 'position ASC' | |
|
21 | 24 | |
|
22 | 25 | before_destroy :check_integrity |
|
23 | 26 | |
@@ -101,6 +104,11 class Enumeration < ActiveRecord::Base | |||
|
101 | 104 | def in_use? |
|
102 | 105 | self.objects_count != 0 |
|
103 | 106 | end |
|
107 | ||
|
108 | # Is this enumeration overiding a system level enumeration? | |
|
109 | def is_override? | |
|
110 | !self.parent.nil? | |
|
111 | end | |
|
104 | 112 | |
|
105 | 113 | alias :destroy_without_reassign :destroy |
|
106 | 114 |
@@ -86,4 +86,26 class EnumerationTest < ActiveSupport::TestCase | |||
|
86 | 86 | assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods) |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | def test_should_belong_to_a_project | |
|
90 | association = Enumeration.reflect_on_association(:project) | |
|
91 | assert association, "No Project association found" | |
|
92 | assert_equal :belongs_to, association.macro | |
|
93 | end | |
|
94 | ||
|
95 | def test_should_act_as_tree | |
|
96 | enumeration = Enumeration.find(4) | |
|
97 | ||
|
98 | assert enumeration.respond_to?(:parent) | |
|
99 | assert enumeration.respond_to?(:children) | |
|
100 | end | |
|
101 | ||
|
102 | def test_is_override | |
|
103 | # Defaults to off | |
|
104 | enumeration = Enumeration.find(4) | |
|
105 | assert !enumeration.is_override? | |
|
106 | ||
|
107 | # Setup as an override | |
|
108 | enumeration.parent = Enumeration.find(5) | |
|
109 | assert enumeration.is_override? | |
|
110 | end | |
|
89 | 111 | end |
General Comments 0
You need to be logged in to leave comments.
Login now