Defect #28925 » fix_28925_v3.patch
| app/controllers/enumerations_controller.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
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
|
||
| test/functional/enumerations_controller_test.rb | ||
|---|---|---|
|
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 => {
|
||
| ... | ... | |
|
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 => {
|
||
- « Previous
- 1
- 2
- 3
- Next »