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