summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/enumerations_controller.rb3
-rw-r--r--app/helpers/custom_fields_helper.rb5
-rw-r--r--app/models/document_category_custom_field.rb23
-rw-r--r--app/models/enumeration.rb1
-rw-r--r--app/models/issue_priority_custom_field.rb23
-rw-r--r--app/models/time_entry_activity_custom_field.rb23
-rw-r--r--app/views/custom_fields/_form.rhtml3
-rw-r--r--app/views/enumerations/_form.rhtml4
-rw-r--r--test/fixtures/custom_fields.yml15
-rw-r--r--test/fixtures/custom_values.yml7
-rw-r--r--test/unit/enumeration_test.rb7
-rw-r--r--test/unit/time_entry_activity_test.rb49
12 files changed, 159 insertions, 4 deletions
diff --git a/app/controllers/enumerations_controller.rb b/app/controllers/enumerations_controller.rb
index 63965fae1..8070df03d 100644
--- a/app/controllers/enumerations_controller.rb
+++ b/app/controllers/enumerations_controller.rb
@@ -17,6 +17,9 @@
class EnumerationsController < ApplicationController
before_filter :require_admin
+
+ helper :custom_fields
+ include CustomFieldsHelper
def index
list
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rb
index 6e99b6a7c..2545dd893 100644
--- a/app/helpers/custom_fields_helper.rb
+++ b/app/helpers/custom_fields_helper.rb
@@ -22,7 +22,10 @@ module CustomFieldsHelper
{:name => 'TimeEntryCustomField', :partial => 'custom_fields/index', :label => :label_spent_time},
{:name => 'ProjectCustomField', :partial => 'custom_fields/index', :label => :label_project_plural},
{:name => 'UserCustomField', :partial => 'custom_fields/index', :label => :label_user_plural},
- {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural}
+ {:name => 'GroupCustomField', :partial => 'custom_fields/index', :label => :label_group_plural},
+ {:name => 'TimeEntryActivityCustomField', :label => TimeEntryActivity::OptionName},
+ {:name => 'IssuePriorityCustomField', :label => IssuePriority::OptionName},
+ {:name => 'DocumentCategoryCustomField', :label => DocumentCategory::OptionName}
]
end
diff --git a/app/models/document_category_custom_field.rb b/app/models/document_category_custom_field.rb
new file mode 100644
index 000000000..5cde029c2
--- /dev/null
+++ b/app/models/document_category_custom_field.rb
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class DocumentCategoryCustomField < CustomField
+ def type_name
+ :enumeration_doc_categories
+ end
+end
+
diff --git a/app/models/enumeration.rb b/app/models/enumeration.rb
index 380a4d3d2..4fb7d6d07 100644
--- a/app/models/enumeration.rb
+++ b/app/models/enumeration.rb
@@ -17,6 +17,7 @@
class Enumeration < ActiveRecord::Base
acts_as_list :scope => 'type = \'#{type}\''
+ acts_as_customizable
before_destroy :check_integrity
diff --git a/app/models/issue_priority_custom_field.rb b/app/models/issue_priority_custom_field.rb
new file mode 100644
index 000000000..559bafeb9
--- /dev/null
+++ b/app/models/issue_priority_custom_field.rb
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class IssuePriorityCustomField < CustomField
+ def type_name
+ :enumeration_issue_priorities
+ end
+end
+
diff --git a/app/models/time_entry_activity_custom_field.rb b/app/models/time_entry_activity_custom_field.rb
new file mode 100644
index 000000000..149bbb5c8
--- /dev/null
+++ b/app/models/time_entry_activity_custom_field.rb
@@ -0,0 +1,23 @@
+# redMine - project management software
+# Copyright (C) 2006 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+class TimeEntryActivityCustomField < CustomField
+ def type_name
+ :enumeration_time_entry_activities
+ end
+end
+
diff --git a/app/views/custom_fields/_form.rhtml b/app/views/custom_fields/_form.rhtml
index b9d7ec017..f82d28784 100644
--- a/app/views/custom_fields/_form.rhtml
+++ b/app/views/custom_fields/_form.rhtml
@@ -94,6 +94,9 @@ when "IssueCustomField" %>
<% when "TimeEntryCustomField" %>
<p><%= f.check_box :is_required %></p>
+<% else %>
+ <p><%= f.check_box :is_required %></p>
+
<% end %>
<%= call_hook(:"view_custom_fields_form_#{@custom_field.type.to_s.underscore}", :custom_field => @custom_field, :form => f) %>
</div>
diff --git a/app/views/enumerations/_form.rhtml b/app/views/enumerations/_form.rhtml
index dac0c9331..741bbc5d9 100644
--- a/app/views/enumerations/_form.rhtml
+++ b/app/views/enumerations/_form.rhtml
@@ -9,4 +9,8 @@
<p><label for="enumeration_is_default"><%=l(:field_is_default)%></label>
<%= check_box 'enumeration', 'is_default' %></p>
<!--[eoform:optvalue]-->
+
+<% @enumeration.custom_field_values.each do |value| %>
+ <p><%= custom_field_tag_with_label :enumeration, value %></p>
+<% end %>
</div> \ No newline at end of file
diff --git a/test/fixtures/custom_fields.yml b/test/fixtures/custom_fields.yml
index b4b58c4d4..dcbef29d6 100644
--- a/test/fixtures/custom_fields.yml
+++ b/test/fixtures/custom_fields.yml
@@ -87,4 +87,17 @@ custom_fields_006:
field_format: float
default_value: ""
editable: true
- \ No newline at end of file
+custom_fields_007:
+ name: Billable
+ min_length: 0
+ regexp: ""
+ is_for_all: false
+ is_filter: true
+ type: TimeEntryActivityCustomField
+ max_length: 0
+ possible_values: ""
+ id: 7
+ is_required: false
+ field_format: bool
+ default_value: ""
+ editable: true
diff --git a/test/fixtures/custom_values.yml b/test/fixtures/custom_values.yml
index 783aa75c9..4e6f4b3ff 100644
--- a/test/fixtures/custom_values.yml
+++ b/test/fixtures/custom_values.yml
@@ -83,4 +83,9 @@ custom_values_014:
customized_id: 5
id: 14
value: "-7.6"
- \ No newline at end of file
+custom_values_015:
+ customized_type: TimeEntryActivity
+ custom_field_id: 7
+ customized_id: 10
+ id: 15
+ value: true
diff --git a/test/unit/enumeration_test.rb b/test/unit/enumeration_test.rb
index 4dc6e15c3..663077352 100644
--- a/test/unit/enumeration_test.rb
+++ b/test/unit/enumeration_test.rb
@@ -18,7 +18,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class EnumerationTest < ActiveSupport::TestCase
- fixtures :enumerations, :issues
+ fixtures :enumerations, :issues, :custom_fields, :custom_values
def setup
end
@@ -81,4 +81,9 @@ class EnumerationTest < ActiveSupport::TestCase
assert_nil Issue.find(:first, :conditions => {:priority_id => 4})
assert_equal 5, Enumeration.find(6).objects_count
end
+
+ def test_should_be_customizable
+ assert Enumeration.included_modules.include?(Redmine::Acts::Customizable::InstanceMethods)
+ end
+
end
diff --git a/test/unit/time_entry_activity_test.rb b/test/unit/time_entry_activity_test.rb
index 9422a91ab..16077c0c9 100644
--- a/test/unit/time_entry_activity_test.rb
+++ b/test/unit/time_entry_activity_test.rb
@@ -32,5 +32,54 @@ class TimeEntryActivityTest < ActiveSupport::TestCase
def test_option_name
assert_equal :enumeration_activities, TimeEntryActivity.new.option_name
end
+
+ def test_create_with_custom_field
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ e.custom_field_values = {field.id => "1"}
+ assert e.save
+
+ e.reload
+ assert_equal "1", e.custom_value_for(field).value
+ end
+
+ def test_create_without_required_custom_field_should_fail
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ assert !e.save
+ assert_equal I18n.translate('activerecord.errors.messages.invalid'), e.errors.on(:custom_values)
+ end
+
+ def test_create_with_required_custom_field_should_succeed
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.new(:name => 'Custom Data')
+ e.custom_field_values = {field.id => "1"}
+ assert e.save
+ end
+
+ def test_update_issue_with_required_custom_field_change
+ field = TimeEntryActivityCustomField.find_by_name('Billable')
+ field.update_attribute(:is_required, true)
+
+ e = TimeEntryActivity.find(10)
+ assert e.available_custom_fields.include?(field)
+ # No change to custom field, record can be saved
+ assert e.save
+ # Blanking custom field, save should fail
+ e.custom_field_values = {field.id => ""}
+ assert !e.save
+ assert e.errors.on(:custom_values)
+
+ # Update custom field to valid value, save should succeed
+ e.custom_field_values = {field.id => "0"}
+ assert e.save
+ e.reload
+ assert_equal "0", e.custom_value_for(field).value
+ end
+
end