##// END OF EJS Templates
Merged r9740 and r9741 from trunk....
Jean-Philippe Lang -
r9570:b88c95b0fb94
parent child
Show More
@@ -18,12 +18,13
18 18 class TimelogController < ApplicationController
19 19 menu_item :issues
20 20
21 before_filter :find_project, :only => [:create]
21 before_filter :find_project_for_new_time_entry, :only => [:create]
22 22 before_filter :find_time_entry, :only => [:show, :edit, :update]
23 23 before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
24 24 before_filter :authorize, :except => [:new, :index, :report]
25 25
26 before_filter :find_optional_project, :only => [:new, :index, :report]
26 before_filter :find_optional_project, :only => [:index, :report]
27 before_filter :find_optional_project_for_new_time_entry, :only => [:new]
27 28 before_filter :authorize_global, :only => [:new, :index, :report]
28 29
29 30 accept_rss_auth :index
@@ -133,9 +134,13 class TimelogController < ApplicationController
133 134 flash[:notice] = l(:notice_successful_create)
134 135 if params[:continue]
135 136 if params[:project_id]
136 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue, :back_url => params[:back_url]
137 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue,
138 :time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
139 :back_url => params[:back_url]
137 140 else
138 redirect_to :action => 'new', :back_url => params[:back_url]
141 redirect_to :action => 'new',
142 :time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
143 :back_url => params[:back_url]
139 144 end
140 145 else
141 146 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
@@ -258,7 +263,7 private
258 263 end
259 264 end
260 265
261 def find_project
266 def find_optional_project_for_new_time_entry
262 267 if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
263 268 @project = Project.find(project_id)
264 269 end
@@ -266,12 +271,15 private
266 271 @issue = Issue.find(issue_id)
267 272 @project ||= @issue.project
268 273 end
274 rescue ActiveRecord::RecordNotFound
275 render_404
276 end
277
278 def find_project_for_new_time_entry
279 find_optional_project_for_new_time_entry
269 280 if @project.nil?
270 281 render_404
271 return false
272 282 end
273 rescue ActiveRecord::RecordNotFound
274 render_404
275 283 end
276 284
277 285 def find_optional_project
@@ -1,6 +1,7
1 1 <h2><%= l(:label_spent_time) %></h2>
2 2
3 3 <%= labelled_form_for @time_entry, :url => time_entries_path do |f| %>
4 <%= hidden_field_tag 'project_id', params[:project_id] if params[:project_id] %>
4 5 <%= render :partial => 'form', :locals => {:f => f} %>
5 6 <%= submit_tag l(:button_create) %>
6 7 <%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
@@ -44,6 +44,7 class TimelogControllerTest < ActionController::TestCase
44 44 # Default activity selected
45 45 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
46 46 :content => 'Development'
47 assert_select 'input[name=project_id][value=1]'
47 48 end
48 49
49 50 def test_get_new_should_only_show_active_time_entry_activities
@@ -61,6 +62,18 class TimelogControllerTest < ActionController::TestCase
61 62 assert_response :success
62 63 assert_template 'new'
63 64 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
65 assert_select 'input[name=project_id]', 0
66 end
67
68 def test_new_without_project_should_prefill_the_form
69 @request.session[:user_id] = 3
70 get :new, :time_entry => {:project_id => '1'}
71 assert_response :success
72 assert_template 'new'
73 assert_select 'select[name=?]', 'time_entry[project_id]' do
74 assert_select 'option[value=1][selected=selected]'
75 end
76 assert_select 'input[name=project_id]', 0
64 77 end
65 78
66 79 def test_new_without_project_should_deny_without_permission
@@ -144,7 +157,7 class TimelogControllerTest < ActionController::TestCase
144 157 :spent_on => '2008-03-14',
145 158 :hours => '7.3'},
146 159 :continue => '1'
147 assert_redirected_to '/projects/ecookbook/time_entries/new'
160 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
148 161 end
149 162
150 163 def test_create_and_continue_with_issue_id
@@ -155,7 +168,7 class TimelogControllerTest < ActionController::TestCase
155 168 :spent_on => '2008-03-14',
156 169 :hours => '7.3'},
157 170 :continue => '1'
158 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
171 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
159 172 end
160 173
161 174 def test_create_and_continue_without_project
@@ -167,7 +180,7 class TimelogControllerTest < ActionController::TestCase
167 180 :hours => '7.3'},
168 181 :continue => '1'
169 182
170 assert_redirected_to '/time_entries/new'
183 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
171 184 end
172 185
173 186 def test_create_without_log_time_permission_should_be_denied
General Comments 0
You need to be logged in to leave comments. Login now