##// END OF EJS Templates
Added some functional tests (issues)....
Jean-Philippe Lang -
r971:63ef594033da
parent child
Show More
@@ -1,86 +1,153
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
22 class IssuesController; def rescue_action(e) raise e end; end
23
23
24 class IssuesControllerTest < Test::Unit::TestCase
24 class IssuesControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = IssuesController.new
28 @controller = IssuesController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_index
34 def test_index
35 get :index
35 get :index
36 assert_response :success
36 assert_response :success
37 assert_template 'index.rhtml'
37 assert_template 'index.rhtml'
38 assert_not_nil assigns(:issues)
38 assert_not_nil assigns(:issues)
39 assert_nil assigns(:project)
39 assert_nil assigns(:project)
40 end
40 end
41
41
42 def test_index_with_project
42 def test_index_with_project
43 get :index, :project_id => 1
43 get :index, :project_id => 1
44 assert_response :success
44 assert_response :success
45 assert_template 'index.rhtml'
45 assert_template 'index.rhtml'
46 assert_not_nil assigns(:issues)
46 assert_not_nil assigns(:issues)
47 end
47 end
48
48
49 def test_index_with_project_and_filter
49 def test_index_with_project_and_filter
50 get :index, :project_id => 1, :set_filter => 1
50 get :index, :project_id => 1, :set_filter => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'index.rhtml'
52 assert_template 'index.rhtml'
53 assert_not_nil assigns(:issues)
53 assert_not_nil assigns(:issues)
54 end
54 end
55
55
56 def test_index_csv_with_project
56 def test_index_csv_with_project
57 get :index, :format => 'csv'
57 get :index, :format => 'csv'
58 assert_response :success
58 assert_response :success
59 assert_not_nil assigns(:issues)
59 assert_not_nil assigns(:issues)
60 assert_equal 'text/csv', @response.content_type
60 assert_equal 'text/csv', @response.content_type
61
61
62 get :index, :project_id => 1, :format => 'csv'
62 get :index, :project_id => 1, :format => 'csv'
63 assert_response :success
63 assert_response :success
64 assert_not_nil assigns(:issues)
64 assert_not_nil assigns(:issues)
65 assert_equal 'text/csv', @response.content_type
65 assert_equal 'text/csv', @response.content_type
66 end
66 end
67
67
68 def test_index_pdf
68 def test_index_pdf
69 get :index, :format => 'pdf'
69 get :index, :format => 'pdf'
70 assert_response :success
70 assert_response :success
71 assert_not_nil assigns(:issues)
71 assert_not_nil assigns(:issues)
72 assert_equal 'application/pdf', @response.content_type
72 assert_equal 'application/pdf', @response.content_type
73
73
74 get :index, :project_id => 1, :format => 'pdf'
74 get :index, :project_id => 1, :format => 'pdf'
75 assert_response :success
75 assert_response :success
76 assert_not_nil assigns(:issues)
76 assert_not_nil assigns(:issues)
77 assert_equal 'application/pdf', @response.content_type
77 assert_equal 'application/pdf', @response.content_type
78 end
78 end
79
79
80 def test_changes
80 def test_changes
81 get :changes, :project_id => 1
81 get :changes, :project_id => 1
82 assert_response :success
82 assert_response :success
83 assert_not_nil assigns(:changes)
83 assert_not_nil assigns(:changes)
84 assert_equal 'application/atom+xml', @response.content_type
84 assert_equal 'application/atom+xml', @response.content_type
85 end
85 end
86
87 def test_show
88 get :show, :id => 1
89 assert_response :success
90 assert_template 'show.rhtml'
91 assert_not_nil assigns(:issue)
92 end
93
94 def test_get_edit
95 @request.session[:user_id] = 2
96 get :edit, :id => 1
97 assert_response :success
98 assert_template 'edit'
99 assert_not_nil assigns(:issue)
100 assert_equal Issue.find(1), assigns(:issue)
101 end
102
103 def test_post_edit
104 @request.session[:user_id] = 2
105 post :edit, :id => 1, :issue => {:subject => 'Modified subject'}
106 assert_redirected_to 'issues/show/1'
107 assert_equal 'Modified subject', Issue.find(1).subject
108 end
109
110 def test_post_change_status
111 issue = Issue.find(1)
112 assert_equal 1, issue.status_id
113 @request.session[:user_id] = 2
114 post :change_status, :id => 1,
115 :new_status_id => 2,
116 :issue => { :assigned_to_id => 3 },
117 :notes => 'Assigned to dlopper',
118 :confirm => 1
119 assert_redirected_to 'issues/show/1'
120 issue.reload
121 assert_equal 2, issue.status_id
122 j = issue.journals.find(:first, :order => 'created_on DESC')
123 assert_equal 'Assigned to dlopper', j.notes
124 assert_equal 2, j.details.size
125 end
126
127 def test_context_menu
128 @request.session[:user_id] = 2
129 get :context_menu, :id => 1
130 assert_response :success
131 assert_template 'context_menu'
132 end
133
134 def test_destroy
135 @request.session[:user_id] = 2
136 post :destroy, :id => 1
137 assert_redirected_to 'projects/1/issues'
138 assert_nil Issue.find_by_id(1)
139 end
140
141 def test_destroy_attachment
142 issue = Issue.find(3)
143 a = issue.attachments.size
144 @request.session[:user_id] = 2
145 post :destroy_attachment, :id => 3, :attachment_id => 1
146 assert_redirected_to 'issues/show/3'
147 assert_nil Attachment.find_by_id(1)
148 issue.reload
149 assert_equal((a-1), issue.attachments.size)
150 j = issue.journals.find(:first, :order => 'created_on DESC')
151 assert_equal 'attachment', j.details.first.property
152 end
86 end
153 end
@@ -1,87 +1,87
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class RepositoryBazaarTest < Test::Unit::TestCase
20 class RepositoryBazaarTest < Test::Unit::TestCase
21 fixtures :projects
21 fixtures :projects
22
22
23 # No '..' in the repository path
23 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + 'tmp/test/bazaar_repository'
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository'
25
25
26 def setup
26 def setup
27 @project = Project.find(1)
27 @project = Project.find(1)
28 assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
28 assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
29 end
29 end
30
30
31 if File.directory?(REPOSITORY_PATH)
31 if File.directory?(REPOSITORY_PATH)
32 def test_fetch_changesets_from_scratch
32 def test_fetch_changesets_from_scratch
33 @repository.fetch_changesets
33 @repository.fetch_changesets
34 @repository.reload
34 @repository.reload
35
35
36 assert_equal 4, @repository.changesets.count
36 assert_equal 4, @repository.changesets.count
37 assert_equal 9, @repository.changes.count
37 assert_equal 9, @repository.changes.count
38 assert_equal 'Initial import', @repository.changesets.find_by_revision(1).comments
38 assert_equal 'Initial import', @repository.changesets.find_by_revision(1).comments
39 end
39 end
40
40
41 def test_fetch_changesets_incremental
41 def test_fetch_changesets_incremental
42 @repository.fetch_changesets
42 @repository.fetch_changesets
43 # Remove changesets with revision > 5
43 # Remove changesets with revision > 5
44 @repository.changesets.find(:all, :conditions => 'revision > 2').each(&:destroy)
44 @repository.changesets.find(:all, :conditions => 'revision > 2').each(&:destroy)
45 @repository.reload
45 @repository.reload
46 assert_equal 2, @repository.changesets.count
46 assert_equal 2, @repository.changesets.count
47
47
48 @repository.fetch_changesets
48 @repository.fetch_changesets
49 assert_equal 4, @repository.changesets.count
49 assert_equal 4, @repository.changesets.count
50 end
50 end
51
51
52 def test_entries
52 def test_entries
53 entries = @repository.entries
53 entries = @repository.entries
54 assert_equal 2, entries.size
54 assert_equal 2, entries.size
55
55
56 assert_equal 'dir', entries[0].kind
56 assert_equal 'dir', entries[0].kind
57 assert_equal 'directory', entries[0].name
57 assert_equal 'directory', entries[0].name
58
58
59 assert_equal 'file', entries[1].kind
59 assert_equal 'file', entries[1].kind
60 assert_equal 'doc-mkdir.txt', entries[1].name
60 assert_equal 'doc-mkdir.txt', entries[1].name
61 end
61 end
62
62
63 def test_entries_in_subdirectory
63 def test_entries_in_subdirectory
64 entries = @repository.entries('directory')
64 entries = @repository.entries('directory')
65 assert_equal 3, entries.size
65 assert_equal 3, entries.size
66
66
67 assert_equal 'file', entries.last.kind
67 assert_equal 'file', entries.last.kind
68 assert_equal 'edit.png', entries.last.name
68 assert_equal 'edit.png', entries.last.name
69 end
69 end
70
70
71 def test_cat
71 def test_cat
72 cat = @repository.scm.cat('directory/document.txt')
72 cat = @repository.scm.cat('directory/document.txt')
73 assert cat =~ /Write the contents of a file as of a given revision to standard output/
73 assert cat =~ /Write the contents of a file as of a given revision to standard output/
74 end
74 end
75
75
76 def test_annotate
76 def test_annotate
77 annotate = @repository.scm.annotate('doc-mkdir.txt')
77 annotate = @repository.scm.annotate('doc-mkdir.txt')
78 assert_equal 17, annotate.lines.size
78 assert_equal 17, annotate.lines.size
79 assert_equal 1, annotate.revisions[0].identifier
79 assert_equal 1, annotate.revisions[0].identifier
80 assert_equal 'jsmith@', annotate.revisions[0].author
80 assert_equal 'jsmith@', annotate.revisions[0].author
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 unit 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
General Comments 0
You need to be logged in to leave comments. Login now