mirror of
				https://github.com/redmine/redmine.git
				synced 2025-10-30 18:06:30 +01:00 
			
		
		
		
	Refactor: move method, ProjectsController#reset_activities to ProjectEnumerationsController#destroy.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4054 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
		| @@ -15,4 +15,12 @@ class ProjectEnumerationsController < ApplicationController | ||||
|     redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project | ||||
|   end | ||||
|  | ||||
|   def destroy | ||||
|     @project.time_entry_activities.each do |time_entry_activity| | ||||
|       time_entry_activity.destroy(time_entry_activity.parent) | ||||
|     end | ||||
|     flash[:notice] = l(:notice_successful_update) | ||||
|     redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project | ||||
|   end | ||||
|  | ||||
| end | ||||
|   | ||||
| @@ -238,14 +238,6 @@ class ProjectsController < ApplicationController | ||||
|     @project = nil | ||||
|   end | ||||
|  | ||||
|   def reset_activities | ||||
|     @project.time_entry_activities.each do |time_entry_activity| | ||||
|       time_entry_activity.destroy(time_entry_activity.parent) | ||||
|     end | ||||
|     flash[:notice] = l(:notice_successful_update) | ||||
|     redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project | ||||
|   end | ||||
|    | ||||
| private | ||||
|   def find_optional_project | ||||
|     return true unless params[:id] | ||||
|   | ||||
| @@ -32,7 +32,7 @@ | ||||
| </table> | ||||
|  | ||||
| <div class="contextual"> | ||||
| <%= link_to(l(:button_reset), {:controller => 'projects', :action => 'reset_activities', :id => @project}, | ||||
| <%= link_to(l(:button_reset), {:controller => 'project_enumerations', :action => 'destroy', :id => @project}, | ||||
| 						:method => :delete, | ||||
| 						:confirm => l(:text_are_you_sure), | ||||
|             :class => 'icon icon-del') %> | ||||
|   | ||||
| @@ -209,7 +209,7 @@ ActionController::Routing::Routes.draw do |map| | ||||
|  | ||||
|     projects.with_options :conditions => {:method => :delete} do |project_actions| | ||||
|       project_actions.conditions 'projects/:id.:format', :action => 'destroy', :format => /xml/ | ||||
|       project_actions.conditions 'projects/:id/reset_activities', :action => 'reset_activities' | ||||
|       project_actions.conditions 'projects/:id/reset_activities', :controller => 'project_enumerations', :action => 'destroy' | ||||
|     end | ||||
|   end | ||||
|    | ||||
|   | ||||
| @@ -87,7 +87,7 @@ Redmine::AccessControl.map do |map| | ||||
|     map.permission :view_time_entries, :timelog => [:details, :report] | ||||
|     map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member | ||||
|     map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin | ||||
|     map.permission :manage_project_activities, {:projects => [:reset_activities], :project_enumerations => [:save]}, :require => :member | ||||
|     map.permission :manage_project_activities, {:project_enumerations => [:save, :destroy]}, :require => :member | ||||
|   end | ||||
|    | ||||
|   map.project_module :news do |map| | ||||
|   | ||||
| @@ -139,4 +139,51 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase | ||||
|     # TimeEntries shouldn't have been reassigned on the saved record either | ||||
|     assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities" | ||||
|   end | ||||
|  | ||||
|     def test_destroy | ||||
|     @request.session[:user_id] = 2 # manager | ||||
|     project_activity = TimeEntryActivity.new({ | ||||
|                                                :name => 'Project Specific', | ||||
|                                                :parent => TimeEntryActivity.find(:first), | ||||
|                                                :project => Project.find(1), | ||||
|                                                :active => true | ||||
|                                              }) | ||||
|     assert project_activity.save | ||||
|     project_activity_two = TimeEntryActivity.new({ | ||||
|                                                    :name => 'Project Specific Two', | ||||
|                                                    :parent => TimeEntryActivity.find(:last), | ||||
|                                                    :project => Project.find(1), | ||||
|                                                    :active => true | ||||
|                                                  }) | ||||
|     assert project_activity_two.save | ||||
|  | ||||
|     delete :destroy, :id => 1 | ||||
|     assert_response :redirect | ||||
|     assert_redirected_to 'projects/ecookbook/settings/activities' | ||||
|  | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity.id) | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | ||||
|   end | ||||
|    | ||||
|   def test_destroy_should_reassign_time_entries_back_to_the_system_activity | ||||
|     @request.session[:user_id] = 2 # manager | ||||
|     project_activity = TimeEntryActivity.new({ | ||||
|                                                :name => 'Project Specific Design', | ||||
|                                                :parent => TimeEntryActivity.find(9), | ||||
|                                                :project => Project.find(1), | ||||
|                                                :active => true | ||||
|                                              }) | ||||
|     assert project_activity.save | ||||
|     assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | ||||
|     assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | ||||
|      | ||||
|     delete :destroy, :id => 1 | ||||
|     assert_response :redirect | ||||
|     assert_redirected_to 'projects/ecookbook/settings/activities' | ||||
|  | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity.id) | ||||
|     assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | ||||
|     assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | ||||
|   end | ||||
|  | ||||
| end | ||||
|   | ||||
| @@ -381,52 +381,6 @@ class ProjectsControllerTest < ActionController::TestCase | ||||
|     assert_template 'show' | ||||
|   end | ||||
|  | ||||
|   def test_reset_activities | ||||
|     @request.session[:user_id] = 2 # manager | ||||
|     project_activity = TimeEntryActivity.new({ | ||||
|                                                :name => 'Project Specific', | ||||
|                                                :parent => TimeEntryActivity.find(:first), | ||||
|                                                :project => Project.find(1), | ||||
|                                                :active => true | ||||
|                                              }) | ||||
|     assert project_activity.save | ||||
|     project_activity_two = TimeEntryActivity.new({ | ||||
|                                                    :name => 'Project Specific Two', | ||||
|                                                    :parent => TimeEntryActivity.find(:last), | ||||
|                                                    :project => Project.find(1), | ||||
|                                                    :active => true | ||||
|                                                  }) | ||||
|     assert project_activity_two.save | ||||
|  | ||||
|     delete :reset_activities, :id => 1 | ||||
|     assert_response :redirect | ||||
|     assert_redirected_to 'projects/ecookbook/settings/activities' | ||||
|  | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity.id) | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity_two.id) | ||||
|   end | ||||
|    | ||||
|   def test_reset_activities_should_reassign_time_entries_back_to_the_system_activity | ||||
|     @request.session[:user_id] = 2 # manager | ||||
|     project_activity = TimeEntryActivity.new({ | ||||
|                                                :name => 'Project Specific Design', | ||||
|                                                :parent => TimeEntryActivity.find(9), | ||||
|                                                :project => Project.find(1), | ||||
|                                                :active => true | ||||
|                                              }) | ||||
|     assert project_activity.save | ||||
|     assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9]) | ||||
|     assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size | ||||
|      | ||||
|     delete :reset_activities, :id => 1 | ||||
|     assert_response :redirect | ||||
|     assert_redirected_to 'projects/ecookbook/settings/activities' | ||||
|  | ||||
|     assert_nil TimeEntryActivity.find_by_id(project_activity.id) | ||||
|     assert_equal 0, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size, "TimeEntries still assigned to project specific activity" | ||||
|     assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size, "TimeEntries still assigned to project specific activity" | ||||
|   end | ||||
|    | ||||
|   # A hook that is manually registered later | ||||
|   class ProjectBasedTemplate < Redmine::Hook::ViewListener | ||||
|     def view_layouts_base_html_head(context) | ||||
|   | ||||
| @@ -190,7 +190,7 @@ class RoutingTest < ActionController::IntegrationTest | ||||
|     should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'edit', :id => '1', :format => 'xml' | ||||
|  | ||||
|     should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :id => '1', :format => 'xml' | ||||
|     should_route :delete, "/projects/64/reset_activities", :controller => 'projects', :action => 'reset_activities', :id => '64' | ||||
|     should_route :delete, "/projects/64/reset_activities", :controller => 'project_enumerations', :action => 'destroy', :id => '64' | ||||
|   end | ||||
|  | ||||
|   context "repositories" do | ||||
|   | ||||
		Reference in New Issue
	
	Block a user