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