mirror of
https://github.com/redmine/redmine.git
synced 2026-01-07 16:12:59 +01:00
Custom field values for enumerations not saved (#28925).
Patch by Mizuki ISHIKAWA. git-svn-id: http://svn.redmine.org/redmine/trunk@17484 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -91,8 +91,10 @@ class EnumerationsController < ApplicationController
|
||||
|
||||
def build_new_enumeration
|
||||
class_name = params[:enumeration] && params[:enumeration][:type] || params[:type]
|
||||
@enumeration = Enumeration.new_subclass_instance(class_name, enumeration_params)
|
||||
if @enumeration.nil?
|
||||
@enumeration = Enumeration.new_subclass_instance(class_name)
|
||||
if @enumeration
|
||||
@enumeration.attributes = enumeration_params || {}
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
@@ -105,6 +107,7 @@ class EnumerationsController < ApplicationController
|
||||
|
||||
def enumeration_params
|
||||
# can't require enumeration on #new action
|
||||
params.permit(:enumeration => [:name, :active, :is_default, :position])[:enumeration]
|
||||
cf_ids = @enumeration.available_custom_fields.map{|c| c.id.to_s}
|
||||
params.permit(:enumeration => [:name, :active, :is_default, :position, :custom_field_values => cf_ids])[:enumeration]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -67,6 +67,21 @@ class EnumerationsControllerTest < Redmine::ControllerTest
|
||||
assert_not_nil e
|
||||
end
|
||||
|
||||
def test_create_with_custom_field_values
|
||||
custom_field = CustomField.generate!(:type => "TimeEntryActivityCustomField")
|
||||
assert_difference 'TimeEntryActivity.count' do
|
||||
post :create, :params => {
|
||||
:enumeration => {
|
||||
:type => 'TimeEntryActivity',
|
||||
:name => 'Sample',
|
||||
:custom_field_values => {custom_field.id.to_s => "sample"}
|
||||
}
|
||||
}
|
||||
end
|
||||
assert_redirected_to '/enumerations'
|
||||
assert_equal "sample", Enumeration.find_by(:name => 'Sample').custom_field_values.last.value
|
||||
end
|
||||
|
||||
def test_create_with_failure
|
||||
assert_no_difference 'IssuePriority.count' do
|
||||
post :create, :params => {
|
||||
@@ -136,6 +151,20 @@ class EnumerationsControllerTest < Redmine::ControllerTest
|
||||
assert_equal 1, Enumeration.find(2).position
|
||||
end
|
||||
|
||||
def test_update_custom_field_values
|
||||
custom_field = CustomField.generate!(:type => "TimeEntryActivityCustomField")
|
||||
enumeration = Enumeration.find(9)
|
||||
assert_nil enumeration.custom_field_values.last.value
|
||||
put :update, :params => {
|
||||
:id => enumeration.id,
|
||||
:enumeration => {
|
||||
:custom_field_values => {custom_field.id.to_s => "sample"}
|
||||
}
|
||||
}
|
||||
assert_response 302
|
||||
assert_equal "sample", enumeration.reload.custom_field_values.last.value
|
||||
end
|
||||
|
||||
def test_destroy_enumeration_not_in_use
|
||||
assert_difference 'IssuePriority.count', -1 do
|
||||
delete :destroy, :params => {
|
||||
|
||||
Reference in New Issue
Block a user