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