1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 15:01:14 +00:00

CustomFieldsController refactoring.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2273 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-01-17 08:41:30 +00:00
parent 5ed2e78ae2
commit 48295a6c4b
2 changed files with 14 additions and 14 deletions

View File

@ -30,19 +30,14 @@ class CustomFieldsController < ApplicationController
end end
def new def new
case params[:type] @custom_field = begin
when "IssueCustomField" if params[:type].to_s.match(/.+CustomField$/)
@custom_field = IssueCustomField.new(params[:custom_field]) params[:type].to_s.constantize.new(params[:custom_field])
when "UserCustomField" end
@custom_field = UserCustomField.new(params[:custom_field]) rescue
when "ProjectCustomField" end
@custom_field = ProjectCustomField.new(params[:custom_field]) redirect_to(:action => 'list') and return unless @custom_field.is_a?(CustomField)
when "TimeEntryCustomField"
@custom_field = TimeEntryCustomField.new(params[:custom_field])
else
redirect_to :action => 'list'
return
end
if request.post? and @custom_field.save if request.post? and @custom_field.save
flash[:notice] = l(:notice_successful_create) flash[:notice] = l(:notice_successful_create)
redirect_to :action => 'list', :tab => @custom_field.class.name redirect_to :action => 'list', :tab => @custom_field.class.name

View File

@ -22,7 +22,7 @@ require 'custom_fields_controller'
class CustomFieldsController; def rescue_action(e) raise e end; end class CustomFieldsController; def rescue_action(e) raise e end; end
class CustomFieldsControllerTest < Test::Unit::TestCase class CustomFieldsControllerTest < Test::Unit::TestCase
fixtures :custom_fields, :trackers fixtures :custom_fields, :trackers, :users
def setup def setup
@controller = CustomFieldsController.new @controller = CustomFieldsController.new
@ -53,4 +53,9 @@ class CustomFieldsControllerTest < Test::Unit::TestCase
assert_equal ["0.1", "0.2"], field.possible_values assert_equal ["0.1", "0.2"], field.possible_values
assert_equal 1, field.trackers.size assert_equal 1, field.trackers.size
end end
def test_invalid_custom_field_class_should_redirect_to_list
get :new, :type => 'UnknownCustomField'
assert_redirected_to '/custom_fields/list'
end
end end