]> source.dussan.org Git - redmine.git/commitdiff
Tests/cleanup VersionsController.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Dec 2011 09:12:51 +0000 (09:12 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 3 Dec 2011 09:12:51 +0000 (09:12 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8038 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/versions_controller.rb
test/functional/versions_controller_test.rb

index ed61fbb068c6eb441c6396048ecf0aed3bf9e6c7..3aac979431c7e9e04d439cb86a9972d10359e88d 100644 (file)
@@ -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
index c9d39366f5ae6c1604220d3da3662255afd3e198..df1d9a8af3d0668849f0e85ed9459a46d4c40ef3 100644 (file)
@@ -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