##// END OF EJS Templates
scm: darcs: define NUM_REV as the number of test repository revisions at functional test...
Toshi MARUYAMA -
r7027:9114df75de35
parent child
Show More
@@ -1,151 +1,152
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller'
19 require 'repositories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
22 class RepositoriesController; def rescue_action(e) raise e end; end
23
23
24 class RepositoriesDarcsControllerTest < ActionController::TestCase
24 class RepositoriesDarcsControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles,
25 fixtures :projects, :users, :roles, :members, :member_roles,
26 :repositories, :enabled_modules
26 :repositories, :enabled_modules
27
27
28 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
28 REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s
29 PRJ_ID = 3
29 PRJ_ID = 3
30 NUM_REV = 6
30
31
31 def setup
32 def setup
32 @controller = RepositoriesController.new
33 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new
34 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new
35 @response = ActionController::TestResponse.new
35 User.current = nil
36 User.current = nil
36 @project = Project.find(PRJ_ID)
37 @project = Project.find(PRJ_ID)
37 @repository = Repository::Darcs.create(
38 @repository = Repository::Darcs.create(
38 :project => @project,
39 :project => @project,
39 :url => REPOSITORY_PATH,
40 :url => REPOSITORY_PATH,
40 :log_encoding => 'UTF-8'
41 :log_encoding => 'UTF-8'
41 )
42 )
42 assert @repository
43 assert @repository
43 end
44 end
44
45
45 if File.directory?(REPOSITORY_PATH)
46 if File.directory?(REPOSITORY_PATH)
46 def test_browse_root
47 def test_browse_root
47 @repository.fetch_changesets
48 @repository.fetch_changesets
48 @repository.reload
49 @repository.reload
49 get :show, :id => PRJ_ID
50 get :show, :id => PRJ_ID
50 assert_response :success
51 assert_response :success
51 assert_template 'show'
52 assert_template 'show'
52 assert_not_nil assigns(:entries)
53 assert_not_nil assigns(:entries)
53 assert_equal 3, assigns(:entries).size
54 assert_equal 3, assigns(:entries).size
54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
57 end
58 end
58
59
59 def test_browse_directory
60 def test_browse_directory
60 @repository.fetch_changesets
61 @repository.fetch_changesets
61 @repository.reload
62 @repository.reload
62 get :show, :id => PRJ_ID, :path => ['images']
63 get :show, :id => PRJ_ID, :path => ['images']
63 assert_response :success
64 assert_response :success
64 assert_template 'show'
65 assert_template 'show'
65 assert_not_nil assigns(:entries)
66 assert_not_nil assigns(:entries)
66 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
67 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
67 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
68 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
68 assert_not_nil entry
69 assert_not_nil entry
69 assert_equal 'file', entry.kind
70 assert_equal 'file', entry.kind
70 assert_equal 'images/edit.png', entry.path
71 assert_equal 'images/edit.png', entry.path
71 end
72 end
72
73
73 def test_browse_at_given_revision
74 def test_browse_at_given_revision
74 @repository.fetch_changesets
75 @repository.fetch_changesets
75 @repository.reload
76 @repository.reload
76 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
77 get :show, :id => PRJ_ID, :path => ['images'], :rev => 1
77 assert_response :success
78 assert_response :success
78 assert_template 'show'
79 assert_template 'show'
79 assert_not_nil assigns(:entries)
80 assert_not_nil assigns(:entries)
80 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
81 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
81 end
82 end
82
83
83 def test_changes
84 def test_changes
84 @repository.fetch_changesets
85 @repository.fetch_changesets
85 @repository.reload
86 @repository.reload
86 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
87 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
87 assert_response :success
88 assert_response :success
88 assert_template 'changes'
89 assert_template 'changes'
89 assert_tag :tag => 'h2', :content => 'edit.png'
90 assert_tag :tag => 'h2', :content => 'edit.png'
90 end
91 end
91
92
92 def test_diff
93 def test_diff
93 @repository.fetch_changesets
94 @repository.fetch_changesets
94 @repository.reload
95 @repository.reload
95 # Full diff of changeset 5
96 # Full diff of changeset 5
96 ['inline', 'sbs'].each do |dt|
97 ['inline', 'sbs'].each do |dt|
97 get :diff, :id => PRJ_ID, :rev => 5, :type => dt
98 get :diff, :id => PRJ_ID, :rev => 5, :type => dt
98 assert_response :success
99 assert_response :success
99 assert_template 'diff'
100 assert_template 'diff'
100 # Line 22 removed
101 # Line 22 removed
101 assert_tag :tag => 'th',
102 assert_tag :tag => 'th',
102 :content => '22',
103 :content => '22',
103 :sibling => { :tag => 'td',
104 :sibling => { :tag => 'td',
104 :attributes => { :class => /diff_out/ },
105 :attributes => { :class => /diff_out/ },
105 :content => /def remove/ }
106 :content => /def remove/ }
106 end
107 end
107 end
108 end
108
109
109 def test_destroy_valid_repository
110 def test_destroy_valid_repository
110 @request.session[:user_id] = 1 # admin
111 @request.session[:user_id] = 1 # admin
111 @repository.fetch_changesets
112 @repository.fetch_changesets
112 @repository.reload
113 @repository.reload
113 assert @repository.changesets.count > 0
114 assert @repository.changesets.count > 0
114
115
115 get :destroy, :id => PRJ_ID
116 get :destroy, :id => PRJ_ID
116 assert_response 302
117 assert_response 302
117 @project.reload
118 @project.reload
118 assert_nil @project.repository
119 assert_nil @project.repository
119 end
120 end
120
121
121 def test_destroy_invalid_repository
122 def test_destroy_invalid_repository
122 @request.session[:user_id] = 1 # admin
123 @request.session[:user_id] = 1 # admin
123 @repository.fetch_changesets
124 @repository.fetch_changesets
124 @repository.reload
125 @repository.reload
125 assert @repository.changesets.count > 0
126 assert @repository.changesets.count > 0
126
127
127 get :destroy, :id => PRJ_ID
128 get :destroy, :id => PRJ_ID
128 assert_response 302
129 assert_response 302
129 @project.reload
130 @project.reload
130 assert_nil @project.repository
131 assert_nil @project.repository
131
132
132 @repository = Repository::Darcs.create(
133 @repository = Repository::Darcs.create(
133 :project => @project,
134 :project => @project,
134 :url => "/invalid",
135 :url => "/invalid",
135 :log_encoding => 'UTF-8'
136 :log_encoding => 'UTF-8'
136 )
137 )
137 assert @repository
138 assert @repository
138 @repository.fetch_changesets
139 @repository.fetch_changesets
139 @repository.reload
140 @repository.reload
140 assert_equal 0, @repository.changesets.count
141 assert_equal 0, @repository.changesets.count
141
142
142 get :destroy, :id => PRJ_ID
143 get :destroy, :id => PRJ_ID
143 assert_response 302
144 assert_response 302
144 @project.reload
145 @project.reload
145 assert_nil @project.repository
146 assert_nil @project.repository
146 end
147 end
147 else
148 else
148 puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
149 puts "Darcs test repository NOT FOUND. Skipping functional tests !!!"
149 def test_fake; assert true end
150 def test_fake; assert true end
150 end
151 end
151 end
152 end
General Comments 0
You need to be logged in to leave comments. Login now