summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-09-17 15:55:08 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-09-17 15:55:08 +0000
commitbd193a026df09ba231b241c24b43762810af7871 (patch)
tree9adc2db6ad84e9a4c6efefe0814ddf6edf0c54f7
parenteb1f58f9624a22d4b5a22f1510c858fa6d5cf7cb (diff)
downloadredmine-bd193a026df09ba231b241c24b43762810af7871.tar.gz
redmine-bd193a026df09ba231b241c24b43762810af7871.zip
Refactor: convert VersionsController to a REST resource.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4097 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/versions_controller.rb4
-rw-r--r--app/views/projects/settings/_versions.rhtml4
-rw-r--r--app/views/versions/edit.rhtml2
-rw-r--r--app/views/versions/new.html.erb2
-rw-r--r--config/routes.rb17
-rw-r--r--test/functional/versions_controller_test.rb6
6 files changed, 14 insertions, 21 deletions
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index 331935d9b..48612c7b8 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 dc81f6265..d41929c2d 100644
--- a/app/views/projects/settings/_versions.rhtml
+++ b/app/views/projects/settings/_versions.rhtml
@@ -21,7 +21,7 @@
<td class="buttons">
<% 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 %>
</td>
</tr>
@@ -34,7 +34,7 @@
<div class="contextual">
<% 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 %>
</div>
diff --git a/app/views/versions/edit.rhtml b/app/views/versions/edit.rhtml
index 8c437eb5e..8724fe62a 100644
--- a/app/views/versions/edit.rhtml
+++ b/app/views/versions/edit.rhtml
@@ -1,6 +1,6 @@
<h2><%=l(:label_version)%></h2>
-<% 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 9fbd94178..d60468159 100644
--- a/app/views/versions/new.html.erb
+++ b/app/views/versions/new.html.erb
@@ -1,6 +1,6 @@
<h2><%=l(:label_version_new)%></h2>
-<% 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 3197df01a..00a2c3608 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 1b33ba816..e4ac5c068 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