@@ -18,12 +18,13 | |||||
18 | class TimelogController < ApplicationController |
|
18 | class TimelogController < ApplicationController | |
19 | menu_item :issues |
|
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 | before_filter :find_time_entry, :only => [:show, :edit, :update] |
|
22 | before_filter :find_time_entry, :only => [:show, :edit, :update] | |
23 | before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] |
|
23 | before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy] | |
24 | before_filter :authorize, :except => [:new, :index, :report] |
|
24 | before_filter :authorize, :except => [:new, :index, :report] | |
25 |
|
25 | |||
26 |
before_filter :find_optional_project, :only => [ |
|
26 | before_filter :find_optional_project, :only => [:index, :report] | |
|
27 | before_filter :find_optional_project_for_new_time_entry, :only => [:new] | |||
27 | before_filter :authorize_global, :only => [:new, :index, :report] |
|
28 | before_filter :authorize_global, :only => [:new, :index, :report] | |
28 |
|
29 | |||
29 | accept_rss_auth :index |
|
30 | accept_rss_auth :index | |
@@ -133,9 +134,13 class TimelogController < ApplicationController | |||||
133 | flash[:notice] = l(:notice_successful_create) |
|
134 | flash[:notice] = l(:notice_successful_create) | |
134 | if params[:continue] |
|
135 | if params[:continue] | |
135 | if params[:project_id] |
|
136 | if params[:project_id] | |
136 |
redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue, |
|
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 | else |
|
140 | else | |
138 |
redirect_to :action => 'new', |
|
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 | end |
|
144 | end | |
140 | else |
|
145 | else | |
141 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project |
|
146 | redirect_back_or_default :action => 'index', :project_id => @time_entry.project | |
@@ -258,7 +263,7 private | |||||
258 | end |
|
263 | end | |
259 | end |
|
264 | end | |
260 |
|
265 | |||
261 | def find_project |
|
266 | def find_optional_project_for_new_time_entry | |
262 | if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present? |
|
267 | if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present? | |
263 | @project = Project.find(project_id) |
|
268 | @project = Project.find(project_id) | |
264 | end |
|
269 | end | |
@@ -266,12 +271,15 private | |||||
266 | @issue = Issue.find(issue_id) |
|
271 | @issue = Issue.find(issue_id) | |
267 | @project ||= @issue.project |
|
272 | @project ||= @issue.project | |
268 | end |
|
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 | if @project.nil? |
|
280 | if @project.nil? | |
270 | render_404 |
|
281 | render_404 | |
271 | return false |
|
|||
272 | end |
|
282 | end | |
273 | rescue ActiveRecord::RecordNotFound |
|
|||
274 | render_404 |
|
|||
275 | end |
|
283 | end | |
276 |
|
284 | |||
277 | def find_optional_project |
|
285 | def find_optional_project |
@@ -1,6 +1,7 | |||||
1 | <h2><%= l(:label_spent_time) %></h2> |
|
1 | <h2><%= l(:label_spent_time) %></h2> | |
2 |
|
2 | |||
3 | <%= labelled_form_for @time_entry, :url => time_entries_path do |f| %> |
|
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 | <%= render :partial => 'form', :locals => {:f => f} %> |
|
5 | <%= render :partial => 'form', :locals => {:f => f} %> | |
5 | <%= submit_tag l(:button_create) %> |
|
6 | <%= submit_tag l(:button_create) %> | |
6 | <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> |
|
7 | <%= submit_tag l(:button_create_and_continue), :name => 'continue' %> |
@@ -44,6 +44,7 class TimelogControllerTest < ActionController::TestCase | |||||
44 | # Default activity selected |
|
44 | # Default activity selected | |
45 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
45 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, | |
46 | :content => 'Development' |
|
46 | :content => 'Development' | |
|
47 | assert_select 'input[name=project_id][value=1]' | |||
47 | end |
|
48 | end | |
48 |
|
49 | |||
49 | def test_get_new_should_only_show_active_time_entry_activities |
|
50 | def test_get_new_should_only_show_active_time_entry_activities | |
@@ -61,6 +62,18 class TimelogControllerTest < ActionController::TestCase | |||||
61 | assert_response :success |
|
62 | assert_response :success | |
62 | assert_template 'new' |
|
63 | assert_template 'new' | |
63 | assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'} |
|
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 | end |
|
77 | end | |
65 |
|
78 | |||
66 | def test_new_without_project_should_deny_without_permission |
|
79 | def test_new_without_project_should_deny_without_permission | |
@@ -144,7 +157,7 class TimelogControllerTest < ActionController::TestCase | |||||
144 | :spent_on => '2008-03-14', |
|
157 | :spent_on => '2008-03-14', | |
145 | :hours => '7.3'}, |
|
158 | :hours => '7.3'}, | |
146 | :continue => '1' |
|
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 | end |
|
161 | end | |
149 |
|
162 | |||
150 | def test_create_and_continue_with_issue_id |
|
163 | def test_create_and_continue_with_issue_id | |
@@ -155,7 +168,7 class TimelogControllerTest < ActionController::TestCase | |||||
155 | :spent_on => '2008-03-14', |
|
168 | :spent_on => '2008-03-14', | |
156 | :hours => '7.3'}, |
|
169 | :hours => '7.3'}, | |
157 | :continue => '1' |
|
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 | end |
|
172 | end | |
160 |
|
173 | |||
161 | def test_create_and_continue_without_project |
|
174 | def test_create_and_continue_without_project | |
@@ -167,7 +180,7 class TimelogControllerTest < ActionController::TestCase | |||||
167 | :hours => '7.3'}, |
|
180 | :hours => '7.3'}, | |
168 | :continue => '1' |
|
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 | end |
|
184 | end | |
172 |
|
185 | |||
173 | def test_create_without_log_time_permission_should_be_denied |
|
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