@@ -30,19 +30,14 class CustomFieldsController < ApplicationController | |||
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def new |
|
33 | case params[:type] | |
|
34 | when "IssueCustomField" | |
|
35 |
|
|
|
36 | when "UserCustomField" | |
|
37 | @custom_field = UserCustomField.new(params[:custom_field]) | |
|
38 | when "ProjectCustomField" | |
|
39 | @custom_field = ProjectCustomField.new(params[:custom_field]) | |
|
40 | when "TimeEntryCustomField" | |
|
41 | @custom_field = TimeEntryCustomField.new(params[:custom_field]) | |
|
42 | else | |
|
43 | redirect_to :action => 'list' | |
|
44 | return | |
|
45 | end | |
|
33 | @custom_field = begin | |
|
34 | if params[:type].to_s.match(/.+CustomField$/) | |
|
35 | params[:type].to_s.constantize.new(params[:custom_field]) | |
|
36 | end | |
|
37 | rescue | |
|
38 | end | |
|
39 | redirect_to(:action => 'list') and return unless @custom_field.is_a?(CustomField) | |
|
40 | ||
|
46 | 41 | if request.post? and @custom_field.save |
|
47 | 42 | flash[:notice] = l(:notice_successful_create) |
|
48 | 43 | redirect_to :action => 'list', :tab => @custom_field.class.name |
@@ -22,7 +22,7 require 'custom_fields_controller' | |||
|
22 | 22 | class CustomFieldsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class CustomFieldsControllerTest < Test::Unit::TestCase |
|
25 | fixtures :custom_fields, :trackers | |
|
25 | fixtures :custom_fields, :trackers, :users | |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | @controller = CustomFieldsController.new |
@@ -53,4 +53,9 class CustomFieldsControllerTest < Test::Unit::TestCase | |||
|
53 | 53 | assert_equal ["0.1", "0.2"], field.possible_values |
|
54 | 54 | assert_equal 1, field.trackers.size |
|
55 | 55 | end |
|
56 | ||
|
57 | def test_invalid_custom_field_class_should_redirect_to_list | |
|
58 | get :new, :type => 'UnknownCustomField' | |
|
59 | assert_redirected_to '/custom_fields/list' | |
|
60 | end | |
|
56 | 61 | end |
General Comments 0
You need to be logged in to leave comments.
Login now