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