end
def new
- case params[:type]
- when "IssueCustomField"
- @custom_field = IssueCustomField.new(params[:custom_field])
- when "UserCustomField"
- @custom_field = UserCustomField.new(params[:custom_field])
- when "ProjectCustomField"
- @custom_field = ProjectCustomField.new(params[:custom_field])
- when "TimeEntryCustomField"
- @custom_field = TimeEntryCustomField.new(params[:custom_field])
- else
- redirect_to :action => 'list'
- return
- end
+ @custom_field = begin
+ if params[:type].to_s.match(/.+CustomField$/)
+ params[:type].to_s.constantize.new(params[:custom_field])
+ end
+ rescue
+ end
+ redirect_to(:action => 'list') and return unless @custom_field.is_a?(CustomField)
+
if request.post? and @custom_field.save
flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list', :tab => @custom_field.class.name
class CustomFieldsController; def rescue_action(e) raise e end; end\r
\r
class CustomFieldsControllerTest < Test::Unit::TestCase\r
- fixtures :custom_fields, :trackers\r
+ fixtures :custom_fields, :trackers, :users\r
\r
def setup\r
@controller = CustomFieldsController.new\r
assert_equal ["0.1", "0.2"], field.possible_values\r
assert_equal 1, field.trackers.size\r
end\r
+ \r
+ def test_invalid_custom_field_class_should_redirect_to_list\r
+ get :new, :type => 'UnknownCustomField'\r
+ assert_redirected_to '/custom_fields/list'\r
+ end\r
end\r