You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repositories_git_controller_test.rb 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  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
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class RepositoriesGitControllerTest < ActionController::TestCase
  19. tests RepositoriesController
  20. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  21. :repositories, :enabled_modules
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
  23. REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
  24. PRJ_ID = 3
  25. CHAR_1_HEX = "\xc3\x9c".force_encoding('UTF-8')
  26. FELIX_HEX = "Felix Sch\xC3\xA4fer".force_encoding('UTF-8')
  27. NUM_REV = 28
  28. ## Git, Mercurial and CVS path encodings are binary.
  29. ## Subversion supports URL encoding for path.
  30. ## Redmine Mercurial adapter and extension use URL encoding.
  31. ## Git accepts only binary path in command line parameter.
  32. ## So, there is no way to use binary command line parameter in JRuby.
  33. JRUBY_SKIP = (RUBY_PLATFORM == 'java')
  34. JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
  35. def setup
  36. @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
  37. User.current = nil
  38. @project = Project.find(PRJ_ID)
  39. @repository = Repository::Git.create(
  40. :project => @project,
  41. :url => REPOSITORY_PATH,
  42. :path_encoding => 'ISO-8859-1'
  43. )
  44. assert @repository
  45. end
  46. def test_create_and_update
  47. @request.session[:user_id] = 1
  48. assert_difference 'Repository.count' do
  49. post :create, :project_id => 'subproject1',
  50. :repository_scm => 'Git',
  51. :repository => {
  52. :url => '/test',
  53. :is_default => '0',
  54. :identifier => 'test-create',
  55. :extra_report_last_commit => '1',
  56. }
  57. end
  58. assert_response 302
  59. repository = Repository.order('id DESC').first
  60. assert_kind_of Repository::Git, repository
  61. assert_equal '/test', repository.url
  62. assert_equal true, repository.extra_report_last_commit
  63. put :update, :id => repository.id,
  64. :repository => {
  65. :extra_report_last_commit => '0'
  66. }
  67. assert_response 302
  68. repo2 = Repository.find(repository.id)
  69. assert_equal false, repo2.extra_report_last_commit
  70. end
  71. if File.directory?(REPOSITORY_PATH)
  72. ## Ruby uses ANSI api to fork a process on Windows.
  73. ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
  74. ## and these are incompatible with ASCII.
  75. ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
  76. ## http://code.google.com/p/msysgit/issues/detail?id=80
  77. ## So, Latin-1 path tests fail on Japanese Windows
  78. WINDOWS_PASS = (Redmine::Platform.mswin? &&
  79. Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
  80. WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
  81. def test_get_new
  82. @request.session[:user_id] = 1
  83. @project.repository.destroy
  84. get :new, :project_id => 'subproject1', :repository_scm => 'Git'
  85. assert_response :success
  86. assert_template 'new'
  87. assert_kind_of Repository::Git, assigns(:repository)
  88. assert assigns(:repository).new_record?
  89. end
  90. def test_browse_root
  91. assert_equal 0, @repository.changesets.count
  92. @repository.fetch_changesets
  93. @project.reload
  94. assert_equal NUM_REV, @repository.changesets.count
  95. get :show, :id => PRJ_ID
  96. assert_response :success
  97. assert_template 'show'
  98. assert_not_nil assigns(:entries)
  99. assert_equal 9, assigns(:entries).size
  100. assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
  101. assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
  102. assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
  103. assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
  104. assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
  105. assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
  106. assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
  107. assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
  108. assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
  109. assert_not_nil assigns(:changesets)
  110. assert assigns(:changesets).size > 0
  111. end
  112. def test_browse_branch
  113. assert_equal 0, @repository.changesets.count
  114. @repository.fetch_changesets
  115. @project.reload
  116. assert_equal NUM_REV, @repository.changesets.count
  117. get :show, :id => PRJ_ID, :rev => 'test_branch'
  118. assert_response :success
  119. assert_template 'show'
  120. assert_not_nil assigns(:entries)
  121. assert_equal 4, assigns(:entries).size
  122. assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
  123. assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
  124. assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
  125. assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
  126. assert_not_nil assigns(:changesets)
  127. assert assigns(:changesets).size > 0
  128. end
  129. def test_browse_tag
  130. assert_equal 0, @repository.changesets.count
  131. @repository.fetch_changesets
  132. @project.reload
  133. assert_equal NUM_REV, @repository.changesets.count
  134. [
  135. "tag00.lightweight",
  136. "tag01.annotated",
  137. ].each do |t1|
  138. get :show, :id => PRJ_ID, :rev => t1
  139. assert_response :success
  140. assert_template 'show'
  141. assert_not_nil assigns(:entries)
  142. assert assigns(:entries).size > 0
  143. assert_not_nil assigns(:changesets)
  144. assert assigns(:changesets).size > 0
  145. end
  146. end
  147. def test_browse_directory
  148. assert_equal 0, @repository.changesets.count
  149. @repository.fetch_changesets
  150. @project.reload
  151. assert_equal NUM_REV, @repository.changesets.count
  152. get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
  153. assert_response :success
  154. assert_template 'show'
  155. assert_not_nil assigns(:entries)
  156. assert_equal ['edit.png'], assigns(:entries).collect(&:name)
  157. entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
  158. assert_not_nil entry
  159. assert_equal 'file', entry.kind
  160. assert_equal 'images/edit.png', entry.path
  161. assert_not_nil assigns(:changesets)
  162. assert assigns(:changesets).size > 0
  163. end
  164. def test_browse_at_given_revision
  165. assert_equal 0, @repository.changesets.count
  166. @repository.fetch_changesets
  167. @project.reload
  168. assert_equal NUM_REV, @repository.changesets.count
  169. get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
  170. :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
  171. assert_response :success
  172. assert_template 'show'
  173. assert_not_nil assigns(:entries)
  174. assert_equal ['delete.png'], assigns(:entries).collect(&:name)
  175. assert_not_nil assigns(:changesets)
  176. assert assigns(:changesets).size > 0
  177. end
  178. def test_changes
  179. get :changes, :id => PRJ_ID,
  180. :path => repository_path_hash(['images', 'edit.png'])[:param]
  181. assert_response :success
  182. assert_template 'changes'
  183. assert_select 'h2', :text => /edit.png/
  184. end
  185. def test_entry_show
  186. get :entry, :id => PRJ_ID,
  187. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  188. assert_response :success
  189. assert_template 'entry'
  190. # Line 11
  191. assert_select 'tr#L11 td.line-code', :text => /WITHOUT ANY WARRANTY/
  192. end
  193. def test_entry_show_latin_1
  194. if @ruby19_non_utf8_pass
  195. puts_ruby19_non_utf8_pass()
  196. elsif WINDOWS_PASS
  197. puts WINDOWS_SKIP_STR
  198. elsif JRUBY_SKIP
  199. puts JRUBY_SKIP_STR
  200. else
  201. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  202. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  203. get :entry, :id => PRJ_ID,
  204. :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
  205. :rev => r1
  206. assert_response :success
  207. assert_template 'entry'
  208. assert_select 'tr#L1 td.line-code', :text => /test-#{CHAR_1_HEX}.txt/
  209. end
  210. end
  211. end
  212. end
  213. def test_entry_download
  214. get :entry, :id => PRJ_ID,
  215. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  216. :format => 'raw'
  217. assert_response :success
  218. # File content
  219. assert @response.body.include?('WITHOUT ANY WARRANTY')
  220. end
  221. def test_directory_entry
  222. get :entry, :id => PRJ_ID,
  223. :path => repository_path_hash(['sources'])[:param]
  224. assert_response :success
  225. assert_template 'show'
  226. assert_not_nil assigns(:entry)
  227. assert_equal 'sources', assigns(:entry).name
  228. end
  229. def test_diff
  230. assert_equal true, @repository.is_default
  231. assert @repository.identifier.blank?
  232. assert_equal 0, @repository.changesets.count
  233. @repository.fetch_changesets
  234. @project.reload
  235. assert_equal NUM_REV, @repository.changesets.count
  236. # Full diff of changeset 2f9c0091
  237. ['inline', 'sbs'].each do |dt|
  238. get :diff,
  239. :id => PRJ_ID,
  240. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  241. :type => dt
  242. assert_response :success
  243. assert_template 'diff'
  244. # Line 22 removed
  245. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  246. assert_select 'h2', :text => /2f9c0091/
  247. end
  248. end
  249. def test_diff_with_rev_and_path
  250. assert_equal 0, @repository.changesets.count
  251. @repository.fetch_changesets
  252. @project.reload
  253. assert_equal NUM_REV, @repository.changesets.count
  254. with_settings :diff_max_lines_displayed => 1000 do
  255. # Full diff of changeset 2f9c0091
  256. ['inline', 'sbs'].each do |dt|
  257. get :diff,
  258. :id => PRJ_ID,
  259. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  260. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  261. :type => dt
  262. assert_response :success
  263. assert_template 'diff'
  264. # Line 22 removed
  265. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  266. assert_select 'h2', :text => /2f9c0091/
  267. end
  268. end
  269. end
  270. def test_diff_truncated
  271. assert_equal 0, @repository.changesets.count
  272. @repository.fetch_changesets
  273. @project.reload
  274. assert_equal NUM_REV, @repository.changesets.count
  275. with_settings :diff_max_lines_displayed => 5 do
  276. # Truncated diff of changeset 2f9c0091
  277. with_cache do
  278. with_settings :default_language => 'en' do
  279. get :diff, :id => PRJ_ID, :type => 'inline',
  280. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  281. assert_response :success
  282. assert @response.body.include?("... This diff was truncated")
  283. end
  284. with_settings :default_language => 'fr' do
  285. get :diff, :id => PRJ_ID, :type => 'inline',
  286. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  287. assert_response :success
  288. assert ! @response.body.include?("... This diff was truncated")
  289. assert @response.body.include?("... Ce diff")
  290. end
  291. end
  292. end
  293. end
  294. def test_diff_two_revs
  295. assert_equal 0, @repository.changesets.count
  296. @repository.fetch_changesets
  297. @project.reload
  298. assert_equal NUM_REV, @repository.changesets.count
  299. ['inline', 'sbs'].each do |dt|
  300. get :diff,
  301. :id => PRJ_ID,
  302. :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
  303. :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  304. :type => dt
  305. assert_response :success
  306. assert_template 'diff'
  307. diff = assigns(:diff)
  308. assert_not_nil diff
  309. assert_select 'h2', :text => /2f9c0091:61b685fb/
  310. assert_select 'form[action=?]', '/projects/subproject1/repository/revisions/61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff'
  311. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  312. end
  313. end
  314. def test_diff_path_in_subrepo
  315. repo = Repository::Git.create(
  316. :project => @project,
  317. :url => REPOSITORY_PATH,
  318. :identifier => 'test-diff-path',
  319. :path_encoding => 'ISO-8859-1'
  320. )
  321. assert repo
  322. assert_equal false, repo.is_default
  323. assert_equal 'test-diff-path', repo.identifier
  324. get :diff,
  325. :id => PRJ_ID,
  326. :repository_id => 'test-diff-path',
  327. :rev => '61b685fbe55ab05b',
  328. :rev_to => '2f9c0091c754a91a',
  329. :type => 'inline'
  330. assert_response :success
  331. assert_template 'diff'
  332. diff = assigns(:diff)
  333. assert_not_nil diff
  334. assert_select 'form[action=?]', '/projects/subproject1/repository/test-diff-path/revisions/61b685fbe55ab05b/diff'
  335. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91a'
  336. end
  337. def test_diff_latin_1
  338. if @ruby19_non_utf8_pass
  339. puts_ruby19_non_utf8_pass()
  340. else
  341. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  342. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  343. ['inline', 'sbs'].each do |dt|
  344. get :diff, :id => PRJ_ID, :rev => r1, :type => dt
  345. assert_response :success
  346. assert_template 'diff'
  347. assert_select 'table' do
  348. assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/
  349. assert_select 'tbody td.diff_in', :text => /test-#{CHAR_1_HEX}.txt/
  350. end
  351. end
  352. end
  353. end
  354. end
  355. end
  356. def test_diff_should_show_filenames
  357. get :diff, :id => PRJ_ID, :rev => 'deff712f05a90d96edbd70facc47d944be5897e3', :type => 'inline'
  358. assert_response :success
  359. assert_template 'diff'
  360. # modified file
  361. assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
  362. # deleted file
  363. assert_select 'th.filename', :text => 'test.txt'
  364. end
  365. def test_save_diff_type
  366. user1 = User.find(1)
  367. user1.pref[:diff_type] = nil
  368. user1.preference.save
  369. user = User.find(1)
  370. assert_nil user.pref[:diff_type]
  371. @request.session[:user_id] = 1 # admin
  372. get :diff,
  373. :id => PRJ_ID,
  374. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  375. assert_response :success
  376. assert_template 'diff'
  377. user.reload
  378. assert_equal "inline", user.pref[:diff_type]
  379. get :diff,
  380. :id => PRJ_ID,
  381. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  382. :type => 'sbs'
  383. assert_response :success
  384. assert_template 'diff'
  385. user.reload
  386. assert_equal "sbs", user.pref[:diff_type]
  387. end
  388. def test_annotate
  389. get :annotate, :id => PRJ_ID,
  390. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  391. assert_response :success
  392. assert_template 'annotate'
  393. # Line 23, changeset 2f9c0091
  394. assert_select 'tr' do
  395. assert_select 'th.line-num', :text => '23'
  396. assert_select 'td.revision', :text => /2f9c0091/
  397. assert_select 'td.author', :text => 'jsmith'
  398. assert_select 'td', :text => /remove_watcher/
  399. end
  400. end
  401. def test_annotate_at_given_revision
  402. assert_equal 0, @repository.changesets.count
  403. @repository.fetch_changesets
  404. @project.reload
  405. assert_equal NUM_REV, @repository.changesets.count
  406. get :annotate, :id => PRJ_ID, :rev => 'deff7',
  407. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  408. assert_response :success
  409. assert_template 'annotate'
  410. assert_select 'h2', :text => /@ deff712f/
  411. end
  412. def test_annotate_binary_file
  413. with_settings :default_language => 'en' do
  414. get :annotate, :id => PRJ_ID,
  415. :path => repository_path_hash(['images', 'edit.png'])[:param]
  416. assert_response 500
  417. assert_select 'p#errorExplanation', :text => /cannot be annotated/
  418. end
  419. end
  420. def test_annotate_error_when_too_big
  421. with_settings :file_max_size_displayed => 1 do
  422. get :annotate, :id => PRJ_ID,
  423. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  424. :rev => 'deff712f'
  425. assert_response 500
  426. assert_select 'p#errorExplanation', :text => /exceeds the maximum text file size/
  427. get :annotate, :id => PRJ_ID,
  428. :path => repository_path_hash(['README'])[:param],
  429. :rev => '7234cb2'
  430. assert_response :success
  431. assert_template 'annotate'
  432. end
  433. end
  434. def test_annotate_latin_1
  435. if @ruby19_non_utf8_pass
  436. puts_ruby19_non_utf8_pass()
  437. elsif WINDOWS_PASS
  438. puts WINDOWS_SKIP_STR
  439. elsif JRUBY_SKIP
  440. puts JRUBY_SKIP_STR
  441. else
  442. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  443. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  444. get :annotate, :id => PRJ_ID,
  445. :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
  446. :rev => r1
  447. assert_select "th.line-num", :text => '1' do
  448. assert_select "+ td.revision" do
  449. assert_select "a", :text => '57ca437c'
  450. assert_select "+ td.author", :text => "jsmith" do
  451. assert_select "+ td",
  452. :text => "test-#{CHAR_1_HEX}.txt"
  453. end
  454. end
  455. end
  456. end
  457. end
  458. end
  459. end
  460. def test_annotate_latin_1_author
  461. ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
  462. get :annotate, :id => PRJ_ID,
  463. :path => repository_path_hash([" filename with a leading space.txt "])[:param],
  464. :rev => r1
  465. assert_select "th.line-num", :text => '1' do
  466. assert_select "+ td.revision" do
  467. assert_select "a", :text => '83ca5fd5'
  468. assert_select "+ td.author", :text => FELIX_HEX do
  469. assert_select "+ td",
  470. :text => "And this is a file with a leading and trailing space..."
  471. end
  472. end
  473. end
  474. end
  475. end
  476. def test_revisions
  477. assert_equal 0, @repository.changesets.count
  478. @repository.fetch_changesets
  479. @project.reload
  480. assert_equal NUM_REV, @repository.changesets.count
  481. get :revisions, :id => PRJ_ID
  482. assert_response :success
  483. assert_template 'revisions'
  484. assert_select 'form[method=get][action=?]', '/projects/subproject1/repository/revision'
  485. end
  486. def test_revision
  487. assert_equal 0, @repository.changesets.count
  488. @repository.fetch_changesets
  489. @project.reload
  490. assert_equal NUM_REV, @repository.changesets.count
  491. ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
  492. get :revision, :id => PRJ_ID, :rev => r
  493. assert_response :success
  494. assert_template 'revision'
  495. end
  496. end
  497. def test_empty_revision
  498. assert_equal 0, @repository.changesets.count
  499. @repository.fetch_changesets
  500. @project.reload
  501. assert_equal NUM_REV, @repository.changesets.count
  502. ['', ' ', nil].each do |r|
  503. get :revision, :id => PRJ_ID, :rev => r
  504. assert_response 404
  505. assert_select_error /was not found/
  506. end
  507. end
  508. def test_destroy_valid_repository
  509. @request.session[:user_id] = 1 # admin
  510. assert_equal 0, @repository.changesets.count
  511. @repository.fetch_changesets
  512. @project.reload
  513. assert_equal NUM_REV, @repository.changesets.count
  514. assert_difference 'Repository.count', -1 do
  515. delete :destroy, :id => @repository.id
  516. end
  517. assert_response 302
  518. @project.reload
  519. assert_nil @project.repository
  520. end
  521. def test_destroy_invalid_repository
  522. @request.session[:user_id] = 1 # admin
  523. @project.repository.destroy
  524. @repository = Repository::Git.create!(
  525. :project => @project,
  526. :url => "/invalid",
  527. :path_encoding => 'ISO-8859-1'
  528. )
  529. @repository.fetch_changesets
  530. @repository.reload
  531. assert_equal 0, @repository.changesets.count
  532. assert_difference 'Repository.count', -1 do
  533. delete :destroy, :id => @repository.id
  534. end
  535. assert_response 302
  536. @project.reload
  537. assert_nil @project.repository
  538. end
  539. private
  540. def puts_ruby19_non_utf8_pass
  541. puts "TODO: This test fails " +
  542. "when Encoding.default_external is not UTF-8. " +
  543. "Current value is '#{Encoding.default_external.to_s}'"
  544. end
  545. else
  546. puts "Git test repository NOT FOUND. Skipping functional tests !!!"
  547. def test_fake; assert true end
  548. end
  549. private
  550. def with_cache(&block)
  551. before = ActionController::Base.perform_caching
  552. ActionController::Base.perform_caching = true
  553. block.call
  554. ActionController::Base.perform_caching = before
  555. end
  556. end