##// END OF EJS Templates
Added some functional tests (projects and repositories)....
Jean-Philippe Lang -
r968:76ed8cc200c5
parent child
Show More
@@ -0,0 +1,91
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
24 class RepositoriesControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26
27 # No '..' in the repository path for svn
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/subversion_repository'
29
30 def setup
31 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new
34 User.current = nil
35 end
36
37 if File.directory?(REPOSITORY_PATH)
38 def test_show
39 get :show, :id => 1
40 assert_response :success
41 assert_template 'show'
42 assert_not_nil assigns(:entries)
43 assert_not_nil assigns(:changesets)
44 end
45
46 def test_browse_root
47 get :browse, :id => 1
48 assert_response :success
49 assert_template 'browse'
50 assert_not_nil assigns(:entries)
51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
52 assert_equal 'dir', entry.kind
53 end
54
55 def test_browse_directory
56 get :browse, :id => 1, :path => ['subversion_test']
57 assert_response :success
58 assert_template 'browse'
59 assert_not_nil assigns(:entries)
60 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
61 assert_equal 'file', entry.kind
62 assert_equal 'subversion_test/helloworld.c', entry.path
63 end
64
65 def test_entry
66 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
67 assert_response :success
68 assert_template 'entry'
69 end
70
71 def test_entry_download
72 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
73 assert_response :success
74 end
75
76 def test_diff
77 get :diff, :id => 1, :rev => 3
78 assert_response :success
79 assert_template 'diff'
80 end
81
82 def test_annotate
83 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
84 assert_response :success
85 assert_template 'annotate'
86 end
87 else
88 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
89 def test_fake; assert true end
90 end
91 end
@@ -1,11 +1,12
1 ---
1 ---
2 repositories_001:
2 repositories_001:
3 project_id: 1
3 project_id: 1
4 url: svn://localhost/test
4 url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
5 id: 10
5 id: 10
6 root_url: svn://localhost
6 root_url: file:///<%= RAILS_ROOT.gsub(%r{config\/\.\.}, '') %>/tmp/test/subversion_repository
7 password: ""
7 password: ""
8 login: ""
8 login: ""
9 type: Subversion
9 repositories_002:
10 repositories_002:
10 project_id: 2
11 project_id: 2
11 url: svn://localhost/test
12 url: svn://localhost/test
@@ -13,3 +14,4 repositories_002:
13 root_url: svn://localhost
14 root_url: svn://localhost
14 password: ""
15 password: ""
15 login: ""
16 login: ""
17 type: Subversion
@@ -22,7 +22,7 require 'projects_controller'
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
25 fixtures :projects, :versions, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
@@ -41,6 +41,10 class ProjectsControllerTest < Test::Unit::TestCase
41 assert_response :success
41 assert_response :success
42 assert_template 'list'
42 assert_template 'list'
43 assert_not_nil assigns(:project_tree)
43 assert_not_nil assigns(:project_tree)
44 # Root project as hash key
45 assert assigns(:project_tree).has_key?(Project.find(1))
46 # Subproject in corresponding value
47 assert assigns(:project_tree)[Project.find(1)].include?(Project.find(3))
44 end
48 end
45
49
46 def test_show
50 def test_show
@@ -86,6 +90,21 class ProjectsControllerTest < Test::Unit::TestCase
86 assert_response :success
90 assert_response :success
87 assert_template 'roadmap'
91 assert_template 'roadmap'
88 assert_not_nil assigns(:versions)
92 assert_not_nil assigns(:versions)
93 # Version with no date set appears
94 assert assigns(:versions).include?(Version.find(3))
95 # Completed version doesn't appear
96 assert !assigns(:versions).include?(Version.find(1))
97 end
98
99 def test_roadmap_with_completed_versions
100 get :roadmap, :id => 1, :completed => 1
101 assert_response :success
102 assert_template 'roadmap'
103 assert_not_nil assigns(:versions)
104 # Version with no date set appears
105 assert assigns(:versions).include?(Version.find(3))
106 # Completed version appears
107 assert assigns(:versions).include?(Version.find(1))
89 end
108 end
90
109
91 def test_activity
110 def test_activity
@@ -120,6 +139,42 class ProjectsControllerTest < Test::Unit::TestCase
120 }
139 }
121 end
140 end
122
141
142 def test_calendar
143 get :calendar, :id => 1
144 assert_response :success
145 assert_template 'calendar'
146 assert_not_nil assigns(:calendar)
147 end
148
149 def test_calendar_with_subprojects
150 get :calendar, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
151 assert_response :success
152 assert_template 'calendar'
153 assert_not_nil assigns(:calendar)
154 end
155
156 def test_gantt
157 get :gantt, :id => 1
158 assert_response :success
159 assert_template 'gantt.rhtml'
160 assert_not_nil assigns(:events)
161 end
162
163 def test_gantt_with_subprojects
164 get :gantt, :id => 1, :with_subprojects => 1, :tracker_ids => [1, 2]
165 assert_response :success
166 assert_template 'gantt.rhtml'
167 assert_not_nil assigns(:events)
168 end
169
170 def test_gantt_export_to_pdf
171 get :gantt, :id => 1, :format => 'pdf'
172 assert_response :success
173 assert_template 'gantt.rfpdf'
174 assert_equal 'application/pdf', @response.content_type
175 assert_not_nil assigns(:events)
176 end
177
123 def test_archive
178 def test_archive
124 @request.session[:user_id] = 1 # admin
179 @request.session[:user_id] = 1 # admin
125 post :archive, :id => 1
180 post :archive, :id => 1
@@ -31,6 +31,13 class RepositoriesControllerTest < Test::Unit::TestCase
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_revisions
35 get :revisions, :id => 1
36 assert_response :success
37 assert_template 'revisions'
38 assert_not_nil assigns(:changesets)
39 end
40
34 def test_revision_with_before_nil_and_afer_normal
41 def test_revision_with_before_nil_and_afer_normal
35 get :revision, {:id => 1, :rev => 1}
42 get :revision, {:id => 1, :rev => 1}
36 assert_response :success
43 assert_response :success
@@ -43,4 +50,15 class RepositoriesControllerTest < Test::Unit::TestCase
43 }
50 }
44 end
51 end
45
52
53 def test_graph_commits_per_month
54 get :graph, :id => 1, :graph => 'commits_per_month'
55 assert_response :success
56 assert_equal 'image/svg+xml', @response.content_type
57 end
58
59 def test_graph_commits_per_author
60 get :graph, :id => 1, :graph => 'commits_per_author'
61 assert_response :success
62 assert_equal 'image/svg+xml', @response.content_type
63 end
46 end
64 end
@@ -81,7 +81,7 class RepositoryBazaarTest < Test::Unit::TestCase
81 assert_equal 'mkdir', annotate.lines[0]
81 assert_equal 'mkdir', annotate.lines[0]
82 end
82 end
83 else
83 else
84 puts "Bazaar test repository NOT FOUND. Skipping tests !!!"
84 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
85 def test_fake; assert true end
85 def test_fake; assert true end
86 end
86 end
87 end
87 end
@@ -49,7 +49,7 class RepositorySubversionTest < Test::Unit::TestCase
49 assert_equal 8, @repository.changesets.count
49 assert_equal 8, @repository.changesets.count
50 end
50 end
51 else
51 else
52 puts "Subversion test repository NOT FOUND. Skipping tests !!!"
52 puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
53 def test_fake; assert true end
53 def test_fake; assert true end
54 end
54 end
55 end
55 end
General Comments 0
You need to be logged in to leave comments. Login now