git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4097 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/1.1.0
end | end | ||||
def update | def update | ||||
if request.post? && params[:version] | |||||
if request.put? && params[:version] | |||||
attributes = params[:version].dup | attributes = params[:version].dup | ||||
attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | ||||
if @version.update_attributes(attributes) | if @version.update_attributes(attributes) | ||||
end | end | ||||
def close_completed | def close_completed | ||||
if request.post? | |||||
if request.put? | |||||
@project.close_completed_versions | @project.close_completed_versions | ||||
end | end | ||||
redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
<td class="buttons"> | <td class="buttons"> | ||||
<% if version.project == @project %> | <% 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_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 %> | <% end %> | ||||
</td> | </td> | ||||
</tr> | </tr> | ||||
<div class="contextual"> | <div class="contextual"> | ||||
<% if @project.versions.any? %> | <% 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 %> | <% end %> | ||||
</div> | </div> | ||||
<h2><%=l(:label_version)%></h2> | <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 } %> | <%= render :partial => 'form', :locals => { :f => f } %> | ||||
<%= submit_tag l(:button_save) %> | <%= submit_tag l(:button_save) %> | ||||
<% end %> | <% end %> |
<h2><%=l(:label_version_new)%></h2> | <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 } %> | <%= render :partial => 'versions/form', :locals => { :f => f } %> | ||||
<%= submit_tag l(:button_create) %> | <%= submit_tag l(:button_create) %> | ||||
<% end %> | <% end %> |
end | end | ||||
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 => { | map.resources :projects, :member => { | ||||
:copy => [:get, :post], | :copy => [:get, :post], | ||||
:settings => :get, | :settings => :get, | ||||
} do |project| | } do |project| | ||||
project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] | project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy] | ||||
project.resources :files, :only => [:index, :new, :create] | project.resources :files, :only => [:index, :new, :create] | ||||
project.resources :versions, :collection => {:close_completed => :put} | |||||
end | 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 | ||||
activity.connect 'activity', :id => nil | activity.connect 'activity', :id => nil | ||||
activity.connect 'activity.:format', :id => nil | activity.connect 'activity.:format', :id => nil | ||||
end | 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| | map.with_options :controller => 'issue_categories' do |categories| | ||||
categories.connect 'projects/:project_id/issue_categories/new', :action => 'new' | categories.connect 'projects/:project_id/issue_categories/new', :action => 'new' | ||||
end | end |
def test_close_completed | def test_close_completed | ||||
Version.update_all("status = 'open'") | Version.update_all("status = 'open'") | ||||
@request.session[:user_id] = 2 | @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_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | ||||
assert_not_nil Version.find_by_status('closed') | assert_not_nil Version.find_by_status('closed') | ||||
end | end | ||||
def test_post_update | def test_post_update | ||||
@request.session[:user_id] = 2 | @request.session[:user_id] = 2 | ||||
post :update, :id => 2, | |||||
put :update, :id => 2, | |||||
:version => { :name => 'New version name', | :version => { :name => 'New version name', | ||||
:effective_date => Date.today.strftime("%Y-%m-%d")} | :effective_date => Date.today.strftime("%Y-%m-%d")} | ||||
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | ||||
def test_destroy | def test_destroy | ||||
@request.session[:user_id] = 2 | @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_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | ||||
assert_nil Version.find_by_id(3) | assert_nil Version.find_by_id(3) | ||||
end | end |