]> source.dussan.org Git - redmine.git/commitdiff
Added some tests for projects controller and helper.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 14 Dec 2007 17:31:24 +0000 (17:31 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 14 Dec 2007 17:31:24 +0000 (17:31 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@989 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/projects_helper.rb
test/fixtures/issues.yml
test/functional/projects_controller_test.rb
test/unit/helpers/projects_helper_test.rb [new file with mode: 0644]

index 4b1b1a9541c699d577915ceeeecc1820e66a0b18..df4b9c3345dfe5d8eb11c3973425dbef1d4412de 100644 (file)
@@ -179,9 +179,9 @@ module ProjectsHelper
     end
     
     # today red line
-    if Date.today >= @date_from and Date.today <= @date_to
+    if Date.today >= date_from and Date.today <= date_to
       gc.stroke('red')
-      x = (Date.today-@date_from+1)*zoom + subject_width
+      x = (Date.today-date_from+1)*zoom + subject_width
       gc.line(x, headers_heigth, x, headers_heigth + g_height-1)      
     end    
     
index 6649849d8e28e04624a1af50477d0a5b74b84677..fc5b48dee0cf64433207eba5cbe9fbce31e12fd2 100644 (file)
@@ -41,6 +41,8 @@ issues_003:
   assigned_to_id: \r
   author_id: 2\r
   status_id: 1\r
+  start_date: <%= 1.day.from_now.to_date.to_s(:db) %>\r
+  due_date: <%= 40.day.ago.to_date.to_s(:db) %>\r
 issues_004: \r
   created_on: 2006-07-19 21:07:27 +02:00\r
   project_id: 2\r
index 52c33ddd7772c4588a86a87cc941fb436bd3b193..b6ac59141c42858c2af2b868de60b7982bdc1276 100644 (file)
@@ -52,7 +52,37 @@ class ProjectsControllerTest < Test::Unit::TestCase
     assert_response :success
     assert_template 'show'\r
     assert_not_nil assigns(:project)\r
+  end
+  
+  def test_settings
+    @request.session[:user_id] = 2 # manager
+    get :settings, :id => 1
+    assert_response :success
+    assert_template 'settings'
+  end
+  
+  def test_edit
+    @request.session[:user_id] = 2 # manager
+    post :edit, :id => 1, :project => {:name => 'Test changed name'}
+    assert_redirected_to 'projects/settings/1'
+    project = Project.find(1)
+    assert_equal 'Test changed name', project.name
+  end
+  
+  def test_get_destroy
+    @request.session[:user_id] = 1 # admin
+    get :destroy, :id => 1
+    assert_response :success
+    assert_template 'destroy'
+    assert_not_nil Project.find_by_id(1)
   end\r
+
+  def test_post_destroy
+    @request.session[:user_id] = 1 # admin
+    post :destroy, :id => 1, :confirm => 1
+    assert_redirected_to 'admin/projects'
+    assert_nil Project.find_by_id(1)
+  end
   \r
   def test_list_documents\r
     get :list_documents, :id => 1\r
@@ -70,7 +100,23 @@ class ProjectsControllerTest < Test::Unit::TestCase
     assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
     assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
   end\r
-\r
+
+  def test_move_issues_to_another_project
+    @request.session[:user_id] = 1
+    post :move_issues, :id => 1, :issue_ids => [1, 2], :new_project_id => 2
+    assert_redirected_to 'projects/1/issues'
+    assert_equal 2, Issue.find(1).project_id
+    assert_equal 2, Issue.find(2).project_id
+  end
+  
+  def test_move_issues_to_another_tracker
+    @request.session[:user_id] = 1
+    post :move_issues, :id => 1, :issue_ids => [1, 2], :new_tracker_id => 3
+    assert_redirected_to 'projects/1/issues'
+    assert_equal 3, Issue.find(1).tracker_id
+    assert_equal 3, Issue.find(2).tracker_id
+  end
+  \r
   def test_list_files\r
     get :list_files, :id => 1\r
     assert_response :success\r
diff --git a/test/unit/helpers/projects_helper_test.rb b/test/unit/helpers/projects_helper_test.rb
new file mode 100644 (file)
index 0000000..d76d92b
--- /dev/null
@@ -0,0 +1,41 @@
+# redMine - project management software
+# Copyright (C) 2006-2007  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class ProjectsHelperTest < HelperTestCase
+  include ProjectsHelper
+  include ActionView::Helpers::TextHelper
+  fixtures :projects, :trackers, :issue_statuses, :issues, :enumerations, :users, :issue_categories
+
+  def setup
+    super
+  end
+  
+  if Object.const_defined?(:Magick)
+    def test_gantt_image
+      assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 6, 2)
+    end
+
+    def test_gantt_image_with_days
+      assert gantt_image(Issue.find(:all, :conditions => "start_date IS NOT NULL AND due_date IS NOT NULL"), Date.today, 3, 4)
+    end
+  else
+    puts "RMagick not installed. Skipping tests !!!"
+    def test_fake; assert true end
+  end
+end