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