@@ -169,6 +169,13 class ApplicationController < ActionController::Base | |||
|
169 | 169 | render_404 |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | # Find project of id params[:project_id] | |
|
173 | def find_project_by_project_id | |
|
174 | @project = Project.find(params[:project_id]) | |
|
175 | rescue ActiveRecord::RecordNotFound | |
|
176 | render_404 | |
|
177 | end | |
|
178 | ||
|
172 | 179 | # Find a project based on params[:project_id] |
|
173 | 180 | # TODO: some subclasses override this, see about merging their logic |
|
174 | 181 | def find_optional_project |
@@ -1,9 +1,9 | |||
|
1 | 1 | class ProjectEnumerationsController < ApplicationController |
|
2 | before_filter :find_project | |
|
2 | before_filter :find_project_by_project_id | |
|
3 | 3 | before_filter :authorize |
|
4 | 4 | |
|
5 |
def |
|
|
6 |
if request.p |
|
|
5 | def update | |
|
6 | if request.put? && params[:enumerations] | |
|
7 | 7 | Project.transaction do |
|
8 | 8 | params[:enumerations].each do |id, activity| |
|
9 | 9 | @project.update_or_create_time_entry_activity(id, activity) |
@@ -1,4 +1,4 | |||
|
1 |
<% form_tag( |
|
|
1 | <% form_tag(project_project_enumerations_path(@project), :method => :put, :class => "tabular") do %> | |
|
2 | 2 | |
|
3 | 3 | <table class="list"> |
|
4 | 4 | <thead><tr> |
@@ -32,7 +32,7 | |||
|
32 | 32 | </table> |
|
33 | 33 | |
|
34 | 34 | <div class="contextual"> |
|
35 |
<%= link_to(l(:button_reset), |
|
|
35 | <%= link_to(l(:button_reset), project_project_enumerations_path(@project), | |
|
36 | 36 | :method => :delete, |
|
37 | 37 | :confirm => l(:text_are_you_sure), |
|
38 | 38 | :class => 'icon icon-del') %> |
@@ -179,7 +179,9 ActionController::Routing::Routes.draw do |map| | |||
|
179 | 179 | :modules => :post, |
|
180 | 180 | :archive => :post, |
|
181 | 181 | :unarchive => :post |
|
182 | } | |
|
182 | } do |project| | |
|
183 | project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] | |
|
184 | end | |
|
183 | 185 | |
|
184 | 186 | # Destroy uses a get request to prompt the user before the actual DELETE request |
|
185 | 187 | map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get} |
@@ -195,13 +197,7 ActionController::Routing::Routes.draw do |map| | |||
|
195 | 197 | |
|
196 | 198 | project_mapper.with_options :conditions => {:method => :post} do |project_actions| |
|
197 | 199 | project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new' |
|
198 | project_actions.connect 'projects/:id/activities/save', :controller => 'project_enumerations', :action => 'save' | |
|
199 | end | |
|
200 | ||
|
201 | project_mapper.with_options :conditions => {:method => :delete} do |project_actions| | |
|
202 | project_actions.conditions 'projects/:id/reset_activities', :controller => 'project_enumerations', :action => 'destroy' | |
|
203 | 200 | end |
|
204 | ||
|
205 | 201 | end |
|
206 | 202 | |
|
207 | 203 | map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity| |
@@ -87,7 +87,7 Redmine::AccessControl.map do |map| | |||
|
87 | 87 | map.permission :view_time_entries, :timelog => [:details, :report] |
|
88 | 88 | map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member |
|
89 | 89 | map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin |
|
90 |
map.permission :manage_project_activities, {:project_enumerations => [: |
|
|
90 | map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member | |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | map.project_module :news do |map| |
@@ -8,11 +8,11 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
8 | 8 | Setting.default_language = 'en' |
|
9 | 9 | end |
|
10 | 10 | |
|
11 |
def test_ |
|
|
11 | def test_update_to_override_system_activities | |
|
12 | 12 | @request.session[:user_id] = 2 # manager |
|
13 | 13 | billable_field = TimeEntryActivityCustomField.find_by_name("Billable") |
|
14 | 14 | |
|
15 |
p |
|
|
15 | put :update, :project_id => 1, :enumerations => { | |
|
16 | 16 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate |
|
17 | 17 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value |
|
18 | 18 | "14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value |
@@ -58,7 +58,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
58 | 58 | assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified" |
|
59 | 59 | end |
|
60 | 60 | |
|
61 |
def test_ |
|
|
61 | def test_update_will_update_project_specific_activities | |
|
62 | 62 | @request.session[:user_id] = 2 # manager |
|
63 | 63 | |
|
64 | 64 | project_activity = TimeEntryActivity.new({ |
@@ -77,7 +77,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
77 | 77 | assert project_activity_two.save |
|
78 | 78 | |
|
79 | 79 | |
|
80 |
p |
|
|
80 | put :update, :project_id => 1, :enumerations => { | |
|
81 | 81 | project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate |
|
82 | 82 | project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate |
|
83 | 83 | } |
@@ -100,11 +100,11 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
100 | 100 | assert !activity_two.active? |
|
101 | 101 | end |
|
102 | 102 | |
|
103 |
def test_ |
|
|
103 | def test_update_when_creating_new_activities_will_convert_existing_data | |
|
104 | 104 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size |
|
105 | 105 | |
|
106 | 106 | @request.session[:user_id] = 2 # manager |
|
107 |
p |
|
|
107 | put :update, :project_id => 1, :enumerations => { | |
|
108 | 108 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate |
|
109 | 109 | } |
|
110 | 110 | assert_response :redirect |
@@ -116,7 +116,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
116 | 116 | assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(project_specific_activity.id, 1).size, "No Time Entries assigned to the project activity" |
|
117 | 117 | end |
|
118 | 118 | |
|
119 |
def test_ |
|
|
119 | def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised | |
|
120 | 120 | # TODO: Need to cause an exception on create but these tests |
|
121 | 121 | # aren't setup for mocking. Just create a record now so the |
|
122 | 122 | # second one is a dupicate |
@@ -128,7 +128,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
128 | 128 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size |
|
129 | 129 | |
|
130 | 130 | @request.session[:user_id] = 2 # manager |
|
131 |
p |
|
|
131 | put :update, :project_id => 1, :enumerations => { | |
|
132 | 132 | "9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design |
|
133 | 133 | "10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value |
|
134 | 134 | } |
@@ -140,7 +140,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
140 | 140 | assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" |
|
141 | 141 | end |
|
142 | 142 | |
|
143 |
|
|
|
143 | def test_destroy | |
|
144 | 144 | @request.session[:user_id] = 2 # manager |
|
145 | 145 | project_activity = TimeEntryActivity.new({ |
|
146 | 146 | :name => 'Project Specific', |
@@ -157,7 +157,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
157 | 157 | }) |
|
158 | 158 | assert project_activity_two.save |
|
159 | 159 | |
|
160 | delete :destroy, :id => 1 | |
|
160 | delete :destroy, :project_id => 1 | |
|
161 | 161 | assert_response :redirect |
|
162 | 162 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
163 | 163 | |
@@ -177,7 +177,7 class ProjectEnumerationsControllerTest < ActionController::TestCase | |||
|
177 | 177 | assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) |
|
178 | 178 | assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size |
|
179 | 179 | |
|
180 | delete :destroy, :id => 1 | |
|
180 | delete :destroy, :project_id => 1 | |
|
181 | 181 | assert_response :redirect |
|
182 | 182 | assert_redirected_to 'projects/ecookbook/settings/activities' |
|
183 | 183 |
@@ -182,14 +182,14 class RoutingTest < ActionController::IntegrationTest | |||
|
182 | 182 | should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33' |
|
183 | 183 | should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64' |
|
184 | 184 | should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64' |
|
185 | should_route :post, "/projects/64/activities/save", :controller => 'project_enumerations', :action => 'save', :id => '64' | |
|
186 | 185 | |
|
186 | should_route :put, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'update', :project_id => '64' | |
|
187 | 187 | should_route :put, "/projects/4223", :controller => 'projects', :action => 'update', :id => '4223' |
|
188 | 188 | should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'update', :id => '1', :format => 'xml' |
|
189 | 189 | |
|
190 | 190 | should_route :delete, "/projects/64", :controller => 'projects', :action => 'destroy', :id => '64' |
|
191 | 191 | should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml' |
|
192 |
should_route :delete, "/projects/64/ |
|
|
192 | should_route :delete, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'destroy', :project_id => '64' | |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | context "repositories" do |
General Comments 0
You need to be logged in to leave comments.
Login now