Merged r9740 and r9741 from trunk.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.0-stable@9753 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-06-03 08:10:00 +00:00
parent 93d8f99884
commit b88c95b0fb
3 changed files with 34 additions and 12 deletions

View File

@ -18,12 +18,13 @@
class TimelogController < ApplicationController
menu_item :issues
before_filter :find_project, :only => [:create]
before_filter :find_project_for_new_time_entry, :only => [:create]
before_filter :find_time_entry, :only => [:show, :edit, :update]
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
before_filter :authorize, :except => [:new, :index, :report]
before_filter :find_optional_project, :only => [:new, :index, :report]
before_filter :find_optional_project, :only => [:index, :report]
before_filter :find_optional_project_for_new_time_entry, :only => [:new]
before_filter :authorize_global, :only => [:new, :index, :report]
accept_rss_auth :index
@ -133,9 +134,13 @@ class TimelogController < ApplicationController
flash[:notice] = l(:notice_successful_create)
if params[:continue]
if params[:project_id]
redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue, :back_url => params[:back_url]
redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue,
:time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
:back_url => params[:back_url]
else
redirect_to :action => 'new', :back_url => params[:back_url]
redirect_to :action => 'new',
:time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
:back_url => params[:back_url]
end
else
redirect_back_or_default :action => 'index', :project_id => @time_entry.project
@ -258,7 +263,7 @@ private
end
end
def find_project
def find_optional_project_for_new_time_entry
if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
@project = Project.find(project_id)
end
@ -266,14 +271,17 @@ private
@issue = Issue.find(issue_id)
@project ||= @issue.project
end
if @project.nil?
render_404
return false
end
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project_for_new_time_entry
find_optional_project_for_new_time_entry
if @project.nil?
render_404
end
end
def find_optional_project
if !params[:issue_id].blank?
@issue = Issue.find(params[:issue_id])

View File

@ -1,6 +1,7 @@
<h2><%= l(:label_spent_time) %></h2>
<%= labelled_form_for @time_entry, :url => time_entries_path do |f| %>
<%= hidden_field_tag 'project_id', params[:project_id] if params[:project_id] %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>

View File

@ -44,6 +44,7 @@ class TimelogControllerTest < ActionController::TestCase
# Default activity selected
assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
:content => 'Development'
assert_select 'input[name=project_id][value=1]'
end
def test_get_new_should_only_show_active_time_entry_activities
@ -61,6 +62,18 @@ class TimelogControllerTest < ActionController::TestCase
assert_response :success
assert_template 'new'
assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
assert_select 'input[name=project_id]', 0
end
def test_new_without_project_should_prefill_the_form
@request.session[:user_id] = 3
get :new, :time_entry => {:project_id => '1'}
assert_response :success
assert_template 'new'
assert_select 'select[name=?]', 'time_entry[project_id]' do
assert_select 'option[value=1][selected=selected]'
end
assert_select 'input[name=project_id]', 0
end
def test_new_without_project_should_deny_without_permission
@ -144,7 +157,7 @@ class TimelogControllerTest < ActionController::TestCase
:spent_on => '2008-03-14',
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/projects/ecookbook/time_entries/new'
assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
end
def test_create_and_continue_with_issue_id
@ -155,7 +168,7 @@ class TimelogControllerTest < ActionController::TestCase
:spent_on => '2008-03-14',
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
end
def test_create_and_continue_without_project
@ -167,7 +180,7 @@ class TimelogControllerTest < ActionController::TestCase
:hours => '7.3'},
:continue => '1'
assert_redirected_to '/time_entries/new'
assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
end
def test_create_without_log_time_permission_should_be_denied