]> source.dussan.org Git - redmine.git/commitdiff
Fixed that project is ignored when entering an issue id on /time_entries/new form...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 Jan 2012 10:37:57 +0000 (10:37 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 22 Jan 2012 10:37:57 +0000 (10:37 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8693 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/timelog_controller.rb
test/functional/timelog_controller_test.rb

index 277b730a1c550e66800a5c751273de7cfe1fd71b..dfa96d2d7837085d16498226af6be19e74358957 100644 (file)
@@ -262,12 +262,14 @@ private
   end
 
   def find_project
+    if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
+      @project = Project.find(project_id)
+    end
     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])).present?
-      @project = Project.find(project_id)
-    else
+      @project ||= @issue.project
+    end
+    if @project.nil?
       render_404
       return false
     end
index 8a68a5dbfa2f41aaa6406b4f3ea337882d9a2543..b5af1b5b8d87bbc51863243f8dd8eea54cc9787e 100644 (file)
@@ -209,6 +209,20 @@ class TimelogControllerTest < ActionController::TestCase
     assert_equal 1, time_entry.project_id
   end
 
+  def test_create_without_project_should_fail_with_issue_not_inside_project
+    @request.session[:user_id] = 2
+    assert_no_difference 'TimeEntry.count' do
+      post :create, :time_entry => {:project_id => '1',
+                                  :activity_id => '11',
+                                  :issue_id => '5',
+                                  :spent_on => '2008-03-14',
+                                  :hours => '7.3'}
+    end
+
+    assert_response :success
+    assert assigns(:time_entry).errors[:issue_id].present?
+  end
+
   def test_create_without_project_should_deny_without_permission
     @request.session[:user_id] = 2
     Project.find(3).disable_module!(:time_tracking)