Permalink
Browse files

Refactor: split VersionsController#new into #new and #create

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4090 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information...
1 parent bde8ab8 commit 969bf2107b2ebcdb480cbb56f523ecb72643146d @edavis10 committed Sep 16, 2010
@@ -18,9 +18,9 @@
class VersionsController < ApplicationController
menu_item :roadmap
model_object Version
- before_filter :find_model_object, :except => [:index, :new, :close_completed]
- before_filter :find_project_from_association, :except => [:index, :new, :close_completed]
- before_filter :find_project, :only => [:index, :new, :close_completed]
+ before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
+ before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
+ before_filter :find_project, :only => [:index, :new, :create, :close_completed]
before_filter :authorize
helper :custom_fields
@@ -63,6 +63,17 @@ def new
attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
@version.attributes = attributes
end
+ end
+
+ def create
+ # TODO: refactor with code above in #new
+ @version = @project.versions.build
+ if params[:version]
+ attributes = params[:version].dup
+ attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
+ @version.attributes = attributes
+ end
+
if request.post?
if @version.save
respond_to do |format|
@@ -79,7 +90,7 @@ def new
end
else
respond_to do |format|
- format.html
+ format.html { render :action => 'new' }
format.js do
render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) }
end
@@ -23,7 +23,7 @@
<%= prompt_to_remote(image_tag('add.png', :style => 'vertical-align: middle;'),
l(:label_version_new),
'version[name]',
- {:controller => 'versions', :action => 'new', :project_id => @project},
+ {:controller => 'versions', :action => 'create', :project_id => @project},
:title => l(:label_version_new),
:tabindex => 200) if authorize_for('versions', 'new') %>
</p>
@@ -1,6 +1,6 @@
<h2><%=l(:label_version_new)%></h2>
-<% labelled_tabular_form_for :version, @version, :url => { :action => 'new' } do |f| %>
+<% labelled_tabular_form_for :version, @version, :url => { :action => 'create', :project_id => @project } do |f| %>
<%= render :partial => 'versions/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
-<% end %>
+<% end %>
View
@@ -208,6 +208,7 @@
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
View
@@ -50,7 +50,7 @@
map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
map.permission :select_project_modules, {:projects => :modules}, :require => :member
map.permission :manage_members, {:projects => :settings, :members => [:new, :edit, :destroy, :autocomplete_for_member]}, :require => :member
- map.permission :manage_versions, {:projects => :settings, :versions => [:new, :edit, :update, :close_completed, :destroy]}, :require => :member
+ map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
map.project_module :issue_tracking do |map|
@@ -75,21 +75,21 @@ def test_show
assert_tag :tag => 'h2', :content => /1.0/
end
- def test_new
+ def test_create
@request.session[:user_id] = 2 # manager
assert_difference 'Version.count' do
- post :new, :project_id => '1', :version => {:name => 'test_add_version'}
+ post :create, :project_id => '1', :version => {:name => 'test_add_version'}
end
assert_redirected_to '/projects/ecookbook/settings/versions'
version = Version.find_by_name('test_add_version')
assert_not_nil version
assert_equal 1, version.project_id
end
- def test_new_from_issue_form
+ def test_create_from_issue_form
@request.session[:user_id] = 2 # manager
assert_difference 'Version.count' do
- xhr :post, :new, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
+ xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
end
assert_response :success
assert_select_rjs :replace, 'issue_fixed_version_id'
@@ -257,7 +257,7 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/versions/show/1", :controller => 'versions', :action => 'show', :id => '1'
should_route :get, "/versions/edit/1", :controller => 'versions', :action => 'edit', :id => '1'
- should_route :post, "/projects/foo/versions/new", :controller => 'versions', :action => 'new', :project_id => 'foo'
+ should_route :post, "/projects/foo/versions", :controller => 'versions', :action => 'create', :project_id => 'foo'
should_route :post, "/versions/update/1", :controller => 'versions', :action => 'update', :id => '1'
should_route :delete, "/versions/destroy/1", :controller => 'versions', :action => 'destroy', :id => '1'

0 comments on commit 969bf21

Please sign in to comment.