Refactor: convert ProjectEnumerations to a resource on a project.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4075 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
5e1c295230
commit
3a2efb4757
@ -169,6 +169,13 @@ class ApplicationController < ActionController::Base
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Find project of id params[:project_id]
|
||||||
|
def find_project_by_project_id
|
||||||
|
@project = Project.find(params[:project_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
render_404
|
||||||
|
end
|
||||||
|
|
||||||
# Find a project based on params[:project_id]
|
# Find a project based on params[:project_id]
|
||||||
# TODO: some subclasses override this, see about merging their logic
|
# TODO: some subclasses override this, see about merging their logic
|
||||||
def find_optional_project
|
def find_optional_project
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class ProjectEnumerationsController < ApplicationController
|
class ProjectEnumerationsController < ApplicationController
|
||||||
before_filter :find_project
|
before_filter :find_project_by_project_id
|
||||||
before_filter :authorize
|
before_filter :authorize
|
||||||
|
|
||||||
def save
|
def update
|
||||||
if request.post? && params[:enumerations]
|
if request.put? && params[:enumerations]
|
||||||
Project.transaction do
|
Project.transaction do
|
||||||
params[:enumerations].each do |id, activity|
|
params[:enumerations].each do |id, activity|
|
||||||
@project.update_or_create_time_entry_activity(id, activity)
|
@project.update_or_create_time_entry_activity(id, activity)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<% form_tag({:controller => 'project_enumerations', :action => 'save', :id => @project}, :class => "tabular") do %>
|
<% form_tag(project_project_enumerations_path(@project), :method => :put, :class => "tabular") do %>
|
||||||
|
|
||||||
<table class="list">
|
<table class="list">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
@ -32,7 +32,7 @@
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<%= link_to(l(:button_reset), {:controller => 'project_enumerations', :action => 'destroy', :id => @project},
|
<%= link_to(l(:button_reset), project_project_enumerations_path(@project),
|
||||||
:method => :delete,
|
:method => :delete,
|
||||||
:confirm => l(:text_are_you_sure),
|
:confirm => l(:text_are_you_sure),
|
||||||
:class => 'icon icon-del') %>
|
:class => 'icon icon-del') %>
|
||||||
|
@ -179,7 +179,9 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
:modules => :post,
|
:modules => :post,
|
||||||
:archive => :post,
|
:archive => :post,
|
||||||
:unarchive => :post
|
:unarchive => :post
|
||||||
}
|
} do |project|
|
||||||
|
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
|
||||||
|
end
|
||||||
|
|
||||||
# Destroy uses a get request to prompt the user before the actual DELETE request
|
# Destroy uses a get request to prompt the user before the actual DELETE request
|
||||||
map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
|
map.project_destroy_confirm 'projects/:id/destroy', :controller => 'projects', :action => 'destroy', :conditions => {:method => :get}
|
||||||
@ -195,13 +197,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||||||
|
|
||||||
project_mapper.with_options :conditions => {:method => :post} do |project_actions|
|
project_mapper.with_options :conditions => {:method => :post} do |project_actions|
|
||||||
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new'
|
project_actions.connect 'projects/:id/files/new', :controller => 'files', :action => 'new'
|
||||||
project_actions.connect 'projects/:id/activities/save', :controller => 'project_enumerations', :action => 'save'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
project_mapper.with_options :conditions => {:method => :delete} do |project_actions|
|
|
||||||
project_actions.conditions 'projects/:id/reset_activities', :controller => 'project_enumerations', :action => 'destroy'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity|
|
map.with_options :controller => 'activities', :action => 'index', :conditions => {:method => :get} do |activity|
|
||||||
|
@ -87,7 +87,7 @@ Redmine::AccessControl.map do |map|
|
|||||||
map.permission :view_time_entries, :timelog => [:details, :report]
|
map.permission :view_time_entries, :timelog => [:details, :report]
|
||||||
map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
|
map.permission :edit_time_entries, {:timelog => [:edit, :destroy]}, :require => :member
|
||||||
map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
|
map.permission :edit_own_time_entries, {:timelog => [:edit, :destroy]}, :require => :loggedin
|
||||||
map.permission :manage_project_activities, {:project_enumerations => [:save, :destroy]}, :require => :member
|
map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
|
||||||
end
|
end
|
||||||
|
|
||||||
map.project_module :news do |map|
|
map.project_module :news do |map|
|
||||||
|
@ -8,11 +8,11 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
Setting.default_language = 'en'
|
Setting.default_language = 'en'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_save_to_override_system_activities
|
def test_update_to_override_system_activities
|
||||||
@request.session[:user_id] = 2 # manager
|
@request.session[:user_id] = 2 # manager
|
||||||
billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
|
billable_field = TimeEntryActivityCustomField.find_by_name("Billable")
|
||||||
|
|
||||||
post :save, :id => 1, :enumerations => {
|
put :update, :project_id => 1, :enumerations => {
|
||||||
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
|
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design, De-activate
|
||||||
"10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
|
"10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"}, # Development, Change custom value
|
||||||
"14"=>{"parent_id"=>"14", "custom_field_values"=>{"7"=>"1"}, "active"=>"1"}, # Inactive Activity, Activate with custom value
|
"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
|
|||||||
assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
|
assert_equal nil, project.time_entry_activities.find_by_name("QA"), "Custom QA activity created when it wasn't modified"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_save_will_update_project_specific_activities
|
def test_update_will_update_project_specific_activities
|
||||||
@request.session[:user_id] = 2 # manager
|
@request.session[:user_id] = 2 # manager
|
||||||
|
|
||||||
project_activity = TimeEntryActivity.new({
|
project_activity = TimeEntryActivity.new({
|
||||||
@ -77,7 +77,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert project_activity_two.save
|
assert project_activity_two.save
|
||||||
|
|
||||||
|
|
||||||
post :save, :id => 1, :enumerations => {
|
put :update, :project_id => 1, :enumerations => {
|
||||||
project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
|
project_activity.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # De-activate
|
||||||
project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
|
project_activity_two.id => {"custom_field_values"=>{"7" => "1"}, "active"=>"0"} # De-activate
|
||||||
}
|
}
|
||||||
@ -100,11 +100,11 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert !activity_two.active?
|
assert !activity_two.active?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_save_when_creating_new_activities_will_convert_existing_data
|
def test_update_when_creating_new_activities_will_convert_existing_data
|
||||||
assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
|
assert_equal 3, TimeEntry.find_all_by_activity_id_and_project_id(9, 1).size
|
||||||
|
|
||||||
@request.session[:user_id] = 2 # manager
|
@request.session[:user_id] = 2 # manager
|
||||||
post :save, :id => 1, :enumerations => {
|
put :update, :project_id => 1, :enumerations => {
|
||||||
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
|
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"} # Design, De-activate
|
||||||
}
|
}
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
@ -116,7 +116,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
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"
|
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"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_save_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
|
def test_update_when_creating_new_activities_will_not_convert_existing_data_if_an_exception_is_raised
|
||||||
# TODO: Need to cause an exception on create but these tests
|
# TODO: Need to cause an exception on create but these tests
|
||||||
# aren't setup for mocking. Just create a record now so the
|
# aren't setup for mocking. Just create a record now so the
|
||||||
# second one is a dupicate
|
# second one is a dupicate
|
||||||
@ -128,7 +128,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
|
assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size
|
||||||
|
|
||||||
@request.session[:user_id] = 2 # manager
|
@request.session[:user_id] = 2 # manager
|
||||||
post :save, :id => 1, :enumerations => {
|
put :update, :project_id => 1, :enumerations => {
|
||||||
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
|
"9"=> {"parent_id"=>"9", "custom_field_values"=>{"7" => "1"}, "active"=>"0"}, # Design
|
||||||
"10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
|
"10"=> {"parent_id"=>"10", "custom_field_values"=>{"7"=>"0"}, "active"=>"1"} # Development, Change custom value
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
|
assert_equal 1, TimeEntry.find_all_by_activity_id_and_project_id(10, 1).size, "Time Entries are not assigned to system activities"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_destroy
|
def test_destroy
|
||||||
@request.session[:user_id] = 2 # manager
|
@request.session[:user_id] = 2 # manager
|
||||||
project_activity = TimeEntryActivity.new({
|
project_activity = TimeEntryActivity.new({
|
||||||
:name => 'Project Specific',
|
:name => 'Project Specific',
|
||||||
@ -157,7 +157,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
})
|
})
|
||||||
assert project_activity_two.save
|
assert project_activity_two.save
|
||||||
|
|
||||||
delete :destroy, :id => 1
|
delete :destroy, :project_id => 1
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to 'projects/ecookbook/settings/activities'
|
assert_redirected_to 'projects/ecookbook/settings/activities'
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ class ProjectEnumerationsControllerTest < ActionController::TestCase
|
|||||||
assert TimeEntry.update_all("activity_id = '#{project_activity.id}'", ["project_id = ? AND activity_id = ?", 1, 9])
|
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
|
assert 3, TimeEntry.find_all_by_activity_id_and_project_id(project_activity.id, 1).size
|
||||||
|
|
||||||
delete :destroy, :id => 1
|
delete :destroy, :project_id => 1
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to 'projects/ecookbook/settings/activities'
|
assert_redirected_to 'projects/ecookbook/settings/activities'
|
||||||
|
|
||||||
|
@ -182,14 +182,14 @@ class RoutingTest < ActionController::IntegrationTest
|
|||||||
should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33'
|
should_route :post, "/projects/33/files/new", :controller => 'files', :action => 'new', :id => '33'
|
||||||
should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
|
should_route :post, "/projects/64/archive", :controller => 'projects', :action => 'archive', :id => '64'
|
||||||
should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'
|
should_route :post, "/projects/64/unarchive", :controller => 'projects', :action => 'unarchive', :id => '64'
|
||||||
should_route :post, "/projects/64/activities/save", :controller => 'project_enumerations', :action => 'save', :id => '64'
|
|
||||||
|
|
||||||
|
should_route :put, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'update', :project_id => '64'
|
||||||
should_route :put, "/projects/4223", :controller => 'projects', :action => 'update', :id => '4223'
|
should_route :put, "/projects/4223", :controller => 'projects', :action => 'update', :id => '4223'
|
||||||
should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'update', :id => '1', :format => 'xml'
|
should_route :put, "/projects/1.xml", :controller => 'projects', :action => 'update', :id => '1', :format => 'xml'
|
||||||
|
|
||||||
should_route :delete, "/projects/64", :controller => 'projects', :action => 'destroy', :id => '64'
|
should_route :delete, "/projects/64", :controller => 'projects', :action => 'destroy', :id => '64'
|
||||||
should_route :delete, "/projects/1.xml", :controller => 'projects', :action => 'destroy', :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 => 'project_enumerations', :action => 'destroy', :id => '64'
|
should_route :delete, "/projects/64/enumerations", :controller => 'project_enumerations', :action => 'destroy', :project_id => '64'
|
||||||
end
|
end
|
||||||
|
|
||||||
context "repositories" do
|
context "repositories" do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user