From: Jean-Philippe Lang Date: Tue, 14 Dec 2010 18:29:24 +0000 (+0000) Subject: Fixed: 404 when entering time with blank issue id (#7099). X-Git-Tag: 1.1.0~85 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=335f8da5e81e1974baa13e18be579a8007788dfd;p=redmine.git Fixed: 404 when entering time with blank issue id (#7099). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4511 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index 300b28f11..f75d5833e 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -200,10 +200,10 @@ private end def find_project - if issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id]) + if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present? @issue = Issue.find(issue_id) @project = @issue.project - elsif project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id]) + elsif (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present? @project = Project.find(project_id) else render_404 diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 80eaf707c..634363dd1 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -94,6 +94,26 @@ class TimelogControllerTest < ActionController::TestCase assert_equal i, t.issue assert_equal i.project, t.project end + + def test_post_create_with_blank_issue + # TODO: should POST to issues’ time log instead of project. change form + # and routing + @request.session[:user_id] = 3 + post :create, :project_id => 1, + :time_entry => {:comments => 'Some work on TimelogControllerTest', + # Not the default activity + :activity_id => '11', + :issue_id => '', + :spent_on => '2008-03-14', + :hours => '7.3'} + assert_redirected_to :action => 'index', :project_id => 'ecookbook' + + t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') + assert_not_nil t + assert_equal 11, t.activity_id + assert_equal 7.3, t.hours + assert_equal 3, t.user_id + end def test_update entry = TimeEntry.find(1)