Defect #28925 » fix_28925.patch
app/controllers/enumerations_controller.rb | ||
---|---|---|
91 | 91 | |
92 | 92 |
def build_new_enumeration |
93 | 93 |
class_name = params[:enumeration] && params[:enumeration][:type] || params[:type] |
94 |
@enumeration = Enumeration.new_subclass_instance(class_name, enumeration_params) |
|
95 |
if @enumeration.nil? |
|
94 |
@enumeration = Enumeration.new_subclass_instance(class_name) |
|
95 |
if @enumeration |
|
96 |
@enumeration.attributes = enumeration_params || {} |
|
97 |
else |
|
96 | 98 |
render_404 |
97 | 99 |
end |
98 | 100 |
end |
... | ... | |
105 | 107 | |
106 | 108 |
def enumeration_params |
107 | 109 |
# can't require enumeration on #new action |
108 |
params.permit(:enumeration => [:name, :active, :is_default, :position])[:enumeration] |
|
110 |
custom_field_keys = (@enumeration.try(:custom_field_values) || []).map{|c| c.custom_field_id.to_s} |
|
111 |
params.permit(:enumeration => [:name, :active, :is_default, :position, :custom_field_values => custom_field_keys])[:enumeration] |
|
109 | 112 |
end |
110 | 113 |
end |
test/functional/enumerations_controller_test.rb | ||
---|---|---|
67 | 67 |
assert_not_nil e |
68 | 68 |
end |
69 | 69 | |
70 |
def test_create_with_custom_field_values |
|
71 |
custom_field_id = CustomField.find_by(:type => "TimeEntryActivityCustomField").id |
|
72 |
assert_difference 'TimeEntryActivity.count' do |
|
73 |
post :create, :params => { |
|
74 |
:enumeration => { |
|
75 |
:type => 'TimeEntryActivity', |
|
76 |
:name => 'Sample', |
|
77 |
:custom_field_values => {custom_field_id.to_s => "1"} |
|
78 |
} |
|
79 |
} |
|
80 |
end |
|
81 |
assert_redirected_to '/enumerations' |
|
82 |
assert_equal "1", Enumeration.find_by(:name => 'Sample').custom_field_values.first.value |
|
83 |
end |
|
84 | ||
70 | 85 |
def test_create_with_failure |
71 | 86 |
assert_no_difference 'IssuePriority.count' do |
72 | 87 |
post :create, :params => { |
... | ... | |
136 | 151 |
assert_equal 1, Enumeration.find(2).position |
137 | 152 |
end |
138 | 153 | |
154 |
def test_update_custom_field_values |
|
155 |
enumeration = Enumeration.find(9) |
|
156 |
assert_equal "", enumeration.custom_field_values.first.value |
|
157 |
custom_field_id = enumeration.custom_field_values.first.custom_field.id |
|
158 |
put :update, :params => { |
|
159 |
:id => enumeration.id, |
|
160 |
:enumeration => { |
|
161 |
:custom_field_values => {custom_field_id.to_s => "1"} |
|
162 |
} |
|
163 |
} |
|
164 |
assert_response 302 |
|
165 |
assert_equal "1", enumeration.reload.custom_field_values.first.value |
|
166 |
end |
|
167 | ||
139 | 168 |
def test_destroy_enumeration_not_in_use |
140 | 169 |
assert_difference 'IssuePriority.count', -1 do |
141 | 170 |
delete :destroy, :params => { |