From bd193a026df09ba231b241c24b43762810af7871 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 17 Sep 2010 15:55:08 +0000 Subject: [PATCH] Refactor: convert VersionsController to a REST resource. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4097 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/versions_controller.rb | 4 ++-- app/views/projects/settings/_versions.rhtml | 4 ++-- app/views/versions/edit.rhtml | 2 +- app/views/versions/new.html.erb | 2 +- config/routes.rb | 17 +++++------------ test/functional/versions_controller_test.rb | 6 +++--- 6 files changed, 14 insertions(+), 21 deletions(-) diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb index 331935d9..48612c7b 100644 --- a/app/controllers/versions_controller.rb +++ b/app/controllers/versions_controller.rb @@ -103,7 +103,7 @@ class VersionsController < ApplicationController end def update - if request.post? && params[:version] + if request.put? && params[:version] attributes = params[:version].dup attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) if @version.update_attributes(attributes) @@ -114,7 +114,7 @@ class VersionsController < ApplicationController end def close_completed - if request.post? + if request.put? @project.close_completed_versions end redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project diff --git a/app/views/projects/settings/_versions.rhtml b/app/views/projects/settings/_versions.rhtml index dc81f626..d41929c2 100644 --- a/app/views/projects/settings/_versions.rhtml +++ b/app/views/projects/settings/_versions.rhtml @@ -21,7 +21,7 @@ <% if version.project == @project %> <%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %> - <%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %> + <%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :delete, :class => 'icon icon-del' %> <% end %> @@ -34,7 +34,7 @@
<% if @project.versions.any? %> - <%= link_to l(:label_close_versions), {:controller => 'versions', :action => 'close_completed', :project_id => @project}, :method => :post %> + <%= link_to l(:label_close_versions), close_completed_project_versions_path(@project), :method => :put %> <% end %>
diff --git a/app/views/versions/edit.rhtml b/app/views/versions/edit.rhtml index 8c437eb5..8724fe62 100644 --- a/app/views/versions/edit.rhtml +++ b/app/views/versions/edit.rhtml @@ -1,6 +1,6 @@

<%=l(:label_version)%>

-<% labelled_tabular_form_for :version, @version, :url => { :action => 'update', :id => @version } do |f| %> +<% labelled_tabular_form_for :version, @version, :url => project_version_path(@project, @version), :html => {:method => :put} do |f| %> <%= render :partial => 'form', :locals => { :f => f } %> <%= submit_tag l(:button_save) %> <% end %> diff --git a/app/views/versions/new.html.erb b/app/views/versions/new.html.erb index 9fbd9417..d6046815 100644 --- a/app/views/versions/new.html.erb +++ b/app/views/versions/new.html.erb @@ -1,6 +1,6 @@

<%=l(:label_version_new)%>

-<% labelled_tabular_form_for :version, @version, :url => { :action => 'create', :project_id => @project } do |f| %> +<% labelled_tabular_form_for :version, @version, :url => project_versions_path(@project) do |f| %> <%= render :partial => 'versions/form', :locals => { :f => f } %> <%= submit_tag l(:button_create) %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 3197df01..00a2c360 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -173,6 +173,9 @@ ActionController::Routing::Routes.draw do |map| end end + # For nice "roadmap" in the url for the index action + map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index' + map.resources :projects, :member => { :copy => [:get, :post], :settings => :get, @@ -182,6 +185,7 @@ ActionController::Routing::Routes.draw do |map| } do |project| project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] project.resources :files, :only => [:index, :new, :create] + project.resources :versions, :collection => {:close_completed => :put} end # Destroy uses a get request to prompt the user before the actual DELETE request @@ -201,19 +205,8 @@ ActionController::Routing::Routes.draw do |map| activity.connect 'activity', :id => nil activity.connect 'activity.:format', :id => nil end + - map.with_options :controller => 'versions' do |versions| - versions.connect 'projects/:project_id/versions/new', :action => 'new' - versions.connect 'projects/:project_id/roadmap', :action => 'index' - versions.connect 'versions/:action/:id', :conditions => {:method => :get} - - versions.with_options :conditions => {:method => :post} do |version_actions| - version_actions.connect 'projects/:project_id/versions', :action => 'create' - version_actions.connect 'versions/update/:id', :action => 'update' - version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed' - end - end - map.with_options :controller => 'issue_categories' do |categories| categories.connect 'projects/:project_id/issue_categories/new', :action => 'new' end diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb index 1b33ba81..e4ac5c06 100644 --- a/test/functional/versions_controller_test.rb +++ b/test/functional/versions_controller_test.rb @@ -108,14 +108,14 @@ class VersionsControllerTest < ActionController::TestCase def test_close_completed Version.update_all("status = 'open'") @request.session[:user_id] = 2 - post :close_completed, :project_id => 'ecookbook' + put :close_completed, :project_id => 'ecookbook' assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' assert_not_nil Version.find_by_status('closed') end def test_post_update @request.session[:user_id] = 2 - post :update, :id => 2, + put :update, :id => 2, :version => { :name => 'New version name', :effective_date => Date.today.strftime("%Y-%m-%d")} assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' @@ -126,7 +126,7 @@ class VersionsControllerTest < ActionController::TestCase def test_destroy @request.session[:user_id] = 2 - post :destroy, :id => 3 + delete :destroy, :id => 3 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' assert_nil Version.find_by_id(3) end -- 2.11.0