summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/versions_controller.rb8
-rw-r--r--test/functional/versions_controller_test.rb29
2 files changed, 29 insertions, 8 deletions
diff --git a/app/controllers/versions_controller.rb b/app/controllers/versions_controller.rb
index ed61fbb06..3aac97943 100644
--- a/app/controllers/versions_controller.rb
+++ b/app/controllers/versions_controller.rb
@@ -71,16 +71,10 @@ class VersionsController < ApplicationController
end
def 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
+ @version = @project.versions.build(params[:version])
end
def create
- # TODO: refactor with code above in #new
@version = @project.versions.build
if params[:version]
attributes = params[:version].dup
diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb
index c9d39366f..df1d9a8af 100644
--- a/test/functional/versions_controller_test.rb
+++ b/test/functional/versions_controller_test.rb
@@ -55,6 +55,14 @@ class VersionsControllerTest < ActionController::TestCase
assert assigns(:versions).include?(Version.find(1))
end
+ def test_index_with_tracker_ids
+ get :index, :project_id => 1, :tracker_ids => [1, 3]
+ assert_response :success
+ assert_template 'index'
+ assert_not_nil assigns(:issues_by_version)
+ assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
+ end
+
def test_index_showing_subprojects_versions
@subproject_version = Version.generate!(:project => Project.find(3))
get :index, :project_id => 1, :with_subprojects => 1
@@ -75,6 +83,13 @@ class VersionsControllerTest < ActionController::TestCase
assert_tag :tag => 'h2', :content => /1.0/
end
+ def test_new
+ @request.session[:user_id] = 2
+ get :new, :project_id => '1'
+ assert_response :success
+ assert_template 'new'
+ end
+
def test_create
@request.session[:user_id] = 2 # manager
assert_difference 'Version.count' do
@@ -135,11 +150,23 @@ class VersionsControllerTest < ActionController::TestCase
def test_destroy
@request.session[:user_id] = 2
- delete :destroy, :id => 3
+ assert_difference 'Version.count', -1 do
+ delete :destroy, :id => 3
+ end
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
assert_nil Version.find_by_id(3)
end
+ def test_destroy_version_in_use_should_fail
+ @request.session[:user_id] = 2
+ assert_no_difference 'Version.count' do
+ delete :destroy, :id => 2
+ end
+ assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
+ assert flash[:error].match(/Unable to delete version/)
+ assert Version.find_by_id(2)
+ end
+
def test_issue_status_by
xhr :get, :status_by, :id => 2
assert_response :success