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
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|
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
<%= 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>
<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 %>
\ No newline at end of file
+<% end %>
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
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|
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_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'
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'