##// END OF EJS Templates
Refactor: convert VersionsController to a REST resource....
Eric Davis -
r3983:bd193a026df0
parent child
Show More
@@ -103,7 +103,7 class VersionsController < ApplicationController
103 end
103 end
104
104
105 def update
105 def update
106 if request.post? && params[:version]
106 if request.put? && params[:version]
107 attributes = params[:version].dup
107 attributes = params[:version].dup
108 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
108 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
109 if @version.update_attributes(attributes)
109 if @version.update_attributes(attributes)
@@ -114,7 +114,7 class VersionsController < ApplicationController
114 end
114 end
115
115
116 def close_completed
116 def close_completed
117 if request.post?
117 if request.put?
118 @project.close_completed_versions
118 @project.close_completed_versions
119 end
119 end
120 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
120 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
@@ -21,7 +21,7
21 <td class="buttons">
21 <td class="buttons">
22 <% if version.project == @project %>
22 <% if version.project == @project %>
23 <%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %>
23 <%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %>
24 <%= 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' %>
24 <%= 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' %>
25 <% end %>
25 <% end %>
26 </td>
26 </td>
27 </tr>
27 </tr>
@@ -34,7 +34,7
34
34
35 <div class="contextual">
35 <div class="contextual">
36 <% if @project.versions.any? %>
36 <% if @project.versions.any? %>
37 <%= link_to l(:label_close_versions), {:controller => 'versions', :action => 'close_completed', :project_id => @project}, :method => :post %>
37 <%= link_to l(:label_close_versions), close_completed_project_versions_path(@project), :method => :put %>
38 <% end %>
38 <% end %>
39 </div>
39 </div>
40
40
@@ -1,6 +1,6
1 <h2><%=l(:label_version)%></h2>
1 <h2><%=l(:label_version)%></h2>
2
2
3 <% labelled_tabular_form_for :version, @version, :url => { :action => 'update', :id => @version } do |f| %>
3 <% labelled_tabular_form_for :version, @version, :url => project_version_path(@project, @version), :html => {:method => :put} do |f| %>
4 <%= render :partial => 'form', :locals => { :f => f } %>
4 <%= render :partial => 'form', :locals => { :f => f } %>
5 <%= submit_tag l(:button_save) %>
5 <%= submit_tag l(:button_save) %>
6 <% end %>
6 <% end %>
@@ -1,6 +1,6
1 <h2><%=l(:label_version_new)%></h2>
1 <h2><%=l(:label_version_new)%></h2>
2
2
3 <% labelled_tabular_form_for :version, @version, :url => { :action => 'create', :project_id => @project } do |f| %>
3 <% labelled_tabular_form_for :version, @version, :url => project_versions_path(@project) do |f| %>
4 <%= render :partial => 'versions/form', :locals => { :f => f } %>
4 <%= render :partial => 'versions/form', :locals => { :f => f } %>
5 <%= submit_tag l(:button_create) %>
5 <%= submit_tag l(:button_create) %>
6 <% end %>
6 <% end %>
@@ -173,6 +173,9 ActionController::Routing::Routes.draw do |map|
173 end
173 end
174 end
174 end
175
175
176 # For nice "roadmap" in the url for the index action
177 map.connect 'projects/:project_id/roadmap', :controller => 'versions', :action => 'index'
178
176 map.resources :projects, :member => {
179 map.resources :projects, :member => {
177 :copy => [:get, :post],
180 :copy => [:get, :post],
178 :settings => :get,
181 :settings => :get,
@@ -182,6 +185,7 ActionController::Routing::Routes.draw do |map|
182 } do |project|
185 } do |project|
183 project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
186 project.resource :project_enumerations, :as => 'enumerations', :only => [:update, :destroy]
184 project.resources :files, :only => [:index, :new, :create]
187 project.resources :files, :only => [:index, :new, :create]
188 project.resources :versions, :collection => {:close_completed => :put}
185 end
189 end
186
190
187 # Destroy uses a get request to prompt the user before the actual DELETE request
191 # Destroy uses a get request to prompt the user before the actual DELETE request
@@ -201,19 +205,8 ActionController::Routing::Routes.draw do |map|
201 activity.connect 'activity', :id => nil
205 activity.connect 'activity', :id => nil
202 activity.connect 'activity.:format', :id => nil
206 activity.connect 'activity.:format', :id => nil
203 end
207 end
208
204
209
205 map.with_options :controller => 'versions' do |versions|
206 versions.connect 'projects/:project_id/versions/new', :action => 'new'
207 versions.connect 'projects/:project_id/roadmap', :action => 'index'
208 versions.connect 'versions/:action/:id', :conditions => {:method => :get}
209
210 versions.with_options :conditions => {:method => :post} do |version_actions|
211 version_actions.connect 'projects/:project_id/versions', :action => 'create'
212 version_actions.connect 'versions/update/:id', :action => 'update'
213 version_actions.connect 'projects/:project_id/versions/close_completed', :action => 'close_completed'
214 end
215 end
216
217 map.with_options :controller => 'issue_categories' do |categories|
210 map.with_options :controller => 'issue_categories' do |categories|
218 categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
211 categories.connect 'projects/:project_id/issue_categories/new', :action => 'new'
219 end
212 end
@@ -108,14 +108,14 class VersionsControllerTest < ActionController::TestCase
108 def test_close_completed
108 def test_close_completed
109 Version.update_all("status = 'open'")
109 Version.update_all("status = 'open'")
110 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
111 post :close_completed, :project_id => 'ecookbook'
111 put :close_completed, :project_id => 'ecookbook'
112 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
112 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
113 assert_not_nil Version.find_by_status('closed')
113 assert_not_nil Version.find_by_status('closed')
114 end
114 end
115
115
116 def test_post_update
116 def test_post_update
117 @request.session[:user_id] = 2
117 @request.session[:user_id] = 2
118 post :update, :id => 2,
118 put :update, :id => 2,
119 :version => { :name => 'New version name',
119 :version => { :name => 'New version name',
120 :effective_date => Date.today.strftime("%Y-%m-%d")}
120 :effective_date => Date.today.strftime("%Y-%m-%d")}
121 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
121 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
@@ -126,7 +126,7 class VersionsControllerTest < ActionController::TestCase
126
126
127 def test_destroy
127 def test_destroy
128 @request.session[:user_id] = 2
128 @request.session[:user_id] = 2
129 post :destroy, :id => 3
129 delete :destroy, :id => 3
130 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
130 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
131 assert_nil Version.find_by_id(3)
131 assert_nil Version.find_by_id(3)
132 end
132 end
General Comments 0
You need to be logged in to leave comments. Login now