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