Commit bd193a02 authored by Eric Davis's avatar Eric Davis

Refactor: convert VersionsController to a REST resource.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4097 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent eb1f58f9
......@@ -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
......
......@@ -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>
......
<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 %>
......
<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 %>
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment