##// END OF EJS Templates
Added some functional tests (issues)....
Jean-Philippe Lang -
r971:63ef594033da
parent child
Show More
@@ -1,86 +1,153
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < Test::Unit::TestCase
25 25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
26 26
27 27 def setup
28 28 @controller = IssuesController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_index
35 35 get :index
36 36 assert_response :success
37 37 assert_template 'index.rhtml'
38 38 assert_not_nil assigns(:issues)
39 39 assert_nil assigns(:project)
40 40 end
41 41
42 42 def test_index_with_project
43 43 get :index, :project_id => 1
44 44 assert_response :success
45 45 assert_template 'index.rhtml'
46 46 assert_not_nil assigns(:issues)
47 47 end
48 48
49 49 def test_index_with_project_and_filter
50 50 get :index, :project_id => 1, :set_filter => 1
51 51 assert_response :success
52 52 assert_template 'index.rhtml'
53 53 assert_not_nil assigns(:issues)
54 54 end
55 55
56 56 def test_index_csv_with_project
57 57 get :index, :format => 'csv'
58 58 assert_response :success
59 59 assert_not_nil assigns(:issues)
60 60 assert_equal 'text/csv', @response.content_type
61 61
62 62 get :index, :project_id => 1, :format => 'csv'
63 63 assert_response :success
64 64 assert_not_nil assigns(:issues)
65 65 assert_equal 'text/csv', @response.content_type
66 66 end
67 67
68 68 def test_index_pdf
69 69 get :index, :format => 'pdf'
70 70 assert_response :success
71 71 assert_not_nil assigns(:issues)
72 72 assert_equal 'application/pdf', @response.content_type
73 73
74 74 get :index, :project_id => 1, :format => 'pdf'
75 75 assert_response :success
76 76 assert_not_nil assigns(:issues)
77 77 assert_equal 'application/pdf', @response.content_type
78 78 end
79 79
80 80 def test_changes
81 81 get :changes, :project_id => 1
82 82 assert_response :success
83 83 assert_not_nil assigns(:changes)
84 84 assert_equal 'application/atom+xml', @response.content_type
85 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 153 end
@@ -1,87 +1,87
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19
20 20 class RepositoryBazaarTest < Test::Unit::TestCase
21 21 fixtures :projects
22 22
23 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 26 def setup
27 27 @project = Project.find(1)
28 28 assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}")
29 29 end
30 30
31 31 if File.directory?(REPOSITORY_PATH)
32 32 def test_fetch_changesets_from_scratch
33 33 @repository.fetch_changesets
34 34 @repository.reload
35 35
36 36 assert_equal 4, @repository.changesets.count
37 37 assert_equal 9, @repository.changes.count
38 38 assert_equal 'Initial import', @repository.changesets.find_by_revision(1).comments
39 39 end
40 40
41 41 def test_fetch_changesets_incremental
42 42 @repository.fetch_changesets
43 43 # Remove changesets with revision > 5
44 44 @repository.changesets.find(:all, :conditions => 'revision > 2').each(&:destroy)
45 45 @repository.reload
46 46 assert_equal 2, @repository.changesets.count
47 47
48 48 @repository.fetch_changesets
49 49 assert_equal 4, @repository.changesets.count
50 50 end
51 51
52 52 def test_entries
53 53 entries = @repository.entries
54 54 assert_equal 2, entries.size
55 55
56 56 assert_equal 'dir', entries[0].kind
57 57 assert_equal 'directory', entries[0].name
58 58
59 59 assert_equal 'file', entries[1].kind
60 60 assert_equal 'doc-mkdir.txt', entries[1].name
61 61 end
62 62
63 63 def test_entries_in_subdirectory
64 64 entries = @repository.entries('directory')
65 65 assert_equal 3, entries.size
66 66
67 67 assert_equal 'file', entries.last.kind
68 68 assert_equal 'edit.png', entries.last.name
69 69 end
70 70
71 71 def test_cat
72 72 cat = @repository.scm.cat('directory/document.txt')
73 73 assert cat =~ /Write the contents of a file as of a given revision to standard output/
74 74 end
75 75
76 76 def test_annotate
77 77 annotate = @repository.scm.annotate('doc-mkdir.txt')
78 78 assert_equal 17, annotate.lines.size
79 79 assert_equal 1, annotate.revisions[0].identifier
80 80 assert_equal 'jsmith@', annotate.revisions[0].author
81 81 assert_equal 'mkdir', annotate.lines[0]
82 82 end
83 83 else
84 84 puts "Bazaar test repository NOT FOUND. Skipping unit tests !!!"
85 85 def test_fake; assert true end
86 86 end
87 87 end
General Comments 0
You need to be logged in to leave comments. Login now