]> source.dussan.org Git - redmine.git/commitdiff
Prevent NoMethodError on nil class if custom_fields params is not present in IssuesCo...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 Apr 2008 17:48:11 +0000 (17:48 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 1 Apr 2008 17:48:11 +0000 (17:48 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1317 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
test/functional/issues_controller_test.rb

index 7d4212095e97fd4a254e016cb3d2c30c02a70871..269e988d90872f72699e6119090ce0038cd02a80 100644 (file)
@@ -140,7 +140,9 @@ class IssuesController < ApplicationController
       requested_status = IssueStatus.find_by_id(params[:issue][:status_id])
       # Check that the user is allowed to apply the requested status
       @issue.status = (@allowed_statuses.include? requested_status) ? requested_status : default_status
-      @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, :customized => @issue, :value => params["custom_fields"][x.id.to_s]) }
+      @custom_values = @project.custom_fields_for_issues(@issue.tracker).collect { |x| CustomValue.new(:custom_field => x, 
+                                                                                                       :customized => @issue,
+                                                                                                       :value => (params[:custom_fields] ? params[:custom_fields][x.id.to_s] : nil)) }
       @issue.custom_values = @custom_values
       if @issue.save
         attach_files(@issue, params[:attachments])
index 7d49f088dc74b7022bde2dd776ae872e6bfb6fd1..89769ffe247c6cfd67d9eac6aa854b2b727796c9 100644 (file)
@@ -181,6 +181,16 @@ class IssuesControllerTest < Test::Unit::TestCase
     assert_equal 'Value for field 2', v.value
   end
   
+  def test_post_new_without_custom_fields_param
+    @request.session[:user_id] = 2
+    post :new, :project_id => 1, 
+               :issue => {:tracker_id => 1,
+                          :subject => 'This is the test_new issue',
+                          :description => 'This is the description',
+                          :priority_id => 5}
+    assert_redirected_to 'issues/show'
+  end
+  
   def test_copy_issue
     @request.session[:user_id] = 2
     get :new, :project_id => 1, :copy_from => 1