def parse_params_for_bulk_time_entry_attributes(params)
attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
- attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
+ if custom = attributes[:custom_field_values]
+ custom.reject! {|k,v| v.blank?}
+ custom.keys.each do |k|
+ if custom[k].is_a?(Array)
+ custom[k] << '' if custom[k].delete('__none__')
+ else
+ custom[k] = '' if custom[k] == '__none__'
+ end
+ end
+ end
attributes
end
end
assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value}
end
+ def test_bulk_update_clear_custom_field
+ field = TimeEntryCustomField.generate!(:field_format => 'string')
+ @request.session[:user_id] = 2
+ post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} }
+
+ assert_response 302
+ assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value}
+ end
+
def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
@request.session[:user_id] = 2
post :bulk_update, :ids => [1,2], :back_url => '/time_entries'