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 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2020 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. require File.expand_path('../../test_helper', __FILE__)
  19. class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
  20. tests RepositoriesController
  21. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
  22. :repositories, :enabled_modules
  23. REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
  24. REPOSITORY_PATH.tr!('/', "\\") if Redmine::Platform.mswin?
  25. PRJ_ID = 3
  26. NUM_REV = 28
  27. def setup
  28. super
  29. @not_utf8_external = Encoding.default_external.to_s != 'UTF-8'
  30. User.current = nil
  31. @project = Project.find(PRJ_ID)
  32. @repository =
  33. Repository::Git.
  34. create(
  35. :project => @project,
  36. :url => REPOSITORY_PATH,
  37. :path_encoding => 'ISO-8859-1'
  38. )
  39. assert @repository
  40. end
  41. def test_create_and_update
  42. @request.session[:user_id] = 1
  43. assert_difference 'Repository.count' do
  44. post(
  45. :create,
  46. :params => {
  47. :project_id => 'subproject1',
  48. :repository_scm => 'Git',
  49. :repository => {
  50. :url => '/test',
  51. :is_default => '0',
  52. :identifier => 'test-create',
  53. :report_last_commit => '1',
  54. }
  55. }
  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.report_last_commit
  63. put(
  64. :update,
  65. :params => {
  66. :id => repository.id,
  67. :repository => {
  68. :report_last_commit => '0'
  69. }
  70. }
  71. )
  72. assert_response 302
  73. repo2 = Repository.find(repository.id)
  74. assert_equal false, repo2.report_last_commit
  75. end
  76. if File.directory?(REPOSITORY_PATH)
  77. ## Ruby uses ANSI api to fork a process on Windows.
  78. ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
  79. ## and these are incompatible with ASCII.
  80. ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
  81. ## http://code.google.com/p/msysgit/issues/detail?id=80
  82. ## So, Latin-1 path tests fail on Japanese Windows
  83. WINDOWS_PASS = (Redmine::Platform.mswin? &&
  84. Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
  85. WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
  86. def test_get_new
  87. @request.session[:user_id] = 1
  88. @project.repository.destroy
  89. get(
  90. :new,
  91. :params => {
  92. :project_id => 'subproject1',
  93. :repository_scm => 'Git'
  94. }
  95. )
  96. assert_response :success
  97. assert_select 'select[name=?]', 'repository_scm' do
  98. assert_select 'option[value=?][selected=selected]', 'Git'
  99. end
  100. end
  101. def test_browse_root
  102. assert_equal 0, @repository.changesets.count
  103. @repository.fetch_changesets
  104. @project.reload
  105. assert_equal NUM_REV, @repository.changesets.count
  106. get(:show, :params => {:id => PRJ_ID})
  107. assert_response :success
  108. assert_select 'table.entries tbody' do
  109. assert_select 'tr', 9
  110. assert_select 'tr.dir td.filename_no_report a', :text => 'images'
  111. assert_select 'tr.dir td.filename_no_report a', :text => 'this_is_a_really_long_and_verbose_directory_name'
  112. assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
  113. assert_select 'tr.file td.filename_no_report a', :text => 'README'
  114. assert_select 'tr.file td.filename_no_report a', :text => 'copied_README'
  115. assert_select 'tr.file td.filename_no_report a', :text => 'new_file.txt'
  116. assert_select 'tr.file td.filename_no_report a', :text => 'renamed_test.txt'
  117. assert_select 'tr.file td.filename_no_report a', :text => 'filemane with spaces.txt'
  118. assert_select 'tr.file td.filename_no_report a', :text => 'filename with a leading space.txt'
  119. end
  120. assert_select 'table.changesets tbody' do
  121. assert_select 'tr'
  122. end
  123. end
  124. def test_browse_branch
  125. assert_equal 0, @repository.changesets.count
  126. @repository.fetch_changesets
  127. @project.reload
  128. assert_equal NUM_REV, @repository.changesets.count
  129. get(
  130. :show,
  131. :params => {
  132. :id => PRJ_ID,
  133. :repository_id => @repository.id,
  134. :rev => 'test_branch'
  135. }
  136. )
  137. assert_response :success
  138. assert_select 'table.entries tbody' do
  139. assert_select 'tr', 4
  140. assert_select 'tr.dir td.filename_no_report a', :text => 'images'
  141. assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
  142. assert_select 'tr.file td.filename_no_report a', :text => 'README'
  143. assert_select 'tr.file td.filename_no_report a', :text => 'test.txt'
  144. end
  145. assert_select 'table.changesets tbody' do
  146. assert_select 'tr'
  147. end
  148. end
  149. def test_browse_tag
  150. assert_equal 0, @repository.changesets.count
  151. @repository.fetch_changesets
  152. @project.reload
  153. assert_equal NUM_REV, @repository.changesets.count
  154. [
  155. "tag00.lightweight",
  156. "tag01.annotated",
  157. ].each do |t1|
  158. get(
  159. :show,
  160. :params => {
  161. :id => PRJ_ID,
  162. :repository_id => @repository.id,
  163. :rev => t1
  164. }
  165. )
  166. assert_response :success
  167. assert_select 'table.entries tbody tr'
  168. assert_select 'table.changesets tbody tr'
  169. end
  170. end
  171. def test_browse_directory
  172. assert_equal 0, @repository.changesets.count
  173. @repository.fetch_changesets
  174. @project.reload
  175. assert_equal NUM_REV, @repository.changesets.count
  176. get(
  177. :show,
  178. :params => {
  179. :id => PRJ_ID,
  180. :repository_id => @repository.id,
  181. :path => repository_path_hash(['images'])[:param]
  182. }
  183. )
  184. assert_response :success
  185. assert_select 'table.entries tbody' do
  186. assert_select 'tr', 1
  187. assert_select 'tr.file td.filename_no_report a', :text => 'edit.png'
  188. end
  189. assert_select 'table.changesets tbody tr'
  190. end
  191. def test_browse_at_given_revision
  192. assert_equal 0, @repository.changesets.count
  193. @repository.fetch_changesets
  194. @project.reload
  195. assert_equal NUM_REV, @repository.changesets.count
  196. get(
  197. :show,
  198. :params => {
  199. :id => PRJ_ID,
  200. :repository_id => @repository.id,
  201. :path => repository_path_hash(['images'])[:param],
  202. :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
  203. }
  204. )
  205. assert_response :success
  206. assert_select 'table.entries tbody' do
  207. assert_select 'tr', 1
  208. assert_select 'tr.file td.filename_no_report a', :text => 'delete.png'
  209. end
  210. end
  211. def test_browse_latin_1_dir
  212. if @not_utf8_external
  213. puts_pass_on_not_utf8
  214. elsif WINDOWS_PASS
  215. puts WINDOWS_SKIP_STR
  216. else
  217. assert_equal 0, @repository.changesets.count
  218. @repository.fetch_changesets
  219. @project.reload
  220. assert_equal NUM_REV, @repository.changesets.count
  221. get(
  222. :show,
  223. :params => {
  224. :id => PRJ_ID,
  225. :repository_id => @repository.id,
  226. :path => repository_path_hash(['latin-1-dir', 'test-Ü-subdir'])[:param],
  227. :rev => '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'
  228. }
  229. )
  230. assert_response :success
  231. assert_select 'table.entries tbody' do
  232. assert_select 'tr', 3
  233. assert_select 'tr.file td.filename_no_report a', :text => 'test-Ü-1.txt'
  234. assert_select 'tr.file td.filename_no_report a', :text => 'test-Ü-2.txt'
  235. assert_select 'tr.file td.filename_no_report a', :text => 'test-Ü.txt'
  236. end
  237. end
  238. end
  239. def test_changes
  240. get(
  241. :changes,
  242. :params => {
  243. :id => PRJ_ID,
  244. :repository_id => @repository.id,
  245. :path => repository_path_hash(['images', 'edit.png'])[:param]
  246. }
  247. )
  248. assert_response :success
  249. assert_select 'h2', :text => /edit.png/
  250. end
  251. def test_entry_show
  252. get(
  253. :entry,
  254. :params => {
  255. :id => PRJ_ID,
  256. :repository_id => @repository.id,
  257. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  258. }
  259. )
  260. assert_response :success
  261. # Line 11
  262. assert_select 'tr#L11 td.line-code', :text => /WITHOUT ANY WARRANTY/
  263. end
  264. def test_entry_show_should_render_pagination
  265. get(
  266. :entry,
  267. :params => {
  268. :id => PRJ_ID,
  269. :repository_id => @repository.id,
  270. :path => repository_path_hash(['README'])[:param]
  271. }
  272. )
  273. assert_response :success
  274. assert_select 'ul.pages li.next', :text => /next/i
  275. assert_select 'ul.pages li.previous', :text => /previous/i
  276. end
  277. def test_entry_show_latin_1
  278. if @not_utf8_external
  279. puts_pass_on_not_utf8
  280. elsif WINDOWS_PASS
  281. puts WINDOWS_SKIP_STR
  282. else
  283. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  284. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  285. get(
  286. :entry,
  287. :params => {
  288. :id => PRJ_ID,
  289. :repository_id => @repository.id,
  290. :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
  291. :rev => r1
  292. }
  293. )
  294. assert_response :success
  295. assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
  296. end
  297. end
  298. end
  299. end
  300. def test_entry_download
  301. get(
  302. :entry,
  303. :params => {
  304. :id => PRJ_ID,
  305. :repository_id => @repository.id,
  306. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  307. :format => 'raw'
  308. }
  309. )
  310. assert_response :success
  311. # File content
  312. assert @response.body.include?('WITHOUT ANY WARRANTY')
  313. end
  314. def test_directory_entry
  315. get(
  316. :entry,
  317. :params => {
  318. :id => PRJ_ID,
  319. :repository_id => @repository.id,
  320. :path => repository_path_hash(['sources'])[:param]
  321. }
  322. )
  323. assert_response :success
  324. assert_select 'h2 a', :text => 'sources'
  325. assert_select 'table.entries tbody'
  326. assert_select 'div.contextual > a.icon-download', false
  327. end
  328. def test_diff
  329. assert_equal true, @repository.is_default
  330. assert @repository.identifier.blank?
  331. assert_equal 0, @repository.changesets.count
  332. @repository.fetch_changesets
  333. @project.reload
  334. assert_equal NUM_REV, @repository.changesets.count
  335. # Full diff of changeset 2f9c0091
  336. ['inline', 'sbs'].each do |dt|
  337. get(
  338. :diff,
  339. :params => {
  340. :id => PRJ_ID,
  341. :repository_id => @repository.id,
  342. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  343. :type => dt
  344. }
  345. )
  346. assert_response :success
  347. # Line 22 removed
  348. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  349. assert_select 'h2', :text => /2f9c0091/
  350. end
  351. end
  352. def test_diff_with_rev_and_path
  353. assert_equal 0, @repository.changesets.count
  354. @repository.fetch_changesets
  355. @project.reload
  356. assert_equal NUM_REV, @repository.changesets.count
  357. with_settings :diff_max_lines_displayed => 1000 do
  358. # Full diff of changeset 2f9c0091
  359. ['inline', 'sbs'].each do |dt|
  360. get(
  361. :diff,
  362. :params => {
  363. :id => PRJ_ID,
  364. :repository_id => @repository.id,
  365. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  366. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  367. :type => dt
  368. }
  369. )
  370. assert_response :success
  371. # Line 22 removed
  372. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  373. assert_select 'h2', :text => /2f9c0091/
  374. end
  375. end
  376. end
  377. def test_diff_truncated
  378. assert_equal 0, @repository.changesets.count
  379. @repository.fetch_changesets
  380. @project.reload
  381. assert_equal NUM_REV, @repository.changesets.count
  382. with_settings :diff_max_lines_displayed => 5 do
  383. # Truncated diff of changeset 2f9c0091
  384. with_cache do
  385. with_settings :default_language => 'en' do
  386. get(
  387. :diff,
  388. :params => {
  389. :id => PRJ_ID,
  390. :repository_id => @repository.id,
  391. :type => 'inline',
  392. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  393. }
  394. )
  395. assert_response :success
  396. assert @response.body.include?("... This diff was truncated")
  397. end
  398. with_settings :default_language => 'fr' do
  399. get(
  400. :diff,
  401. :params => {
  402. :id => PRJ_ID,
  403. :repository_id => @repository.id,
  404. :type => 'inline',
  405. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  406. }
  407. )
  408. assert_response :success
  409. assert ! @response.body.include?("... This diff was truncated")
  410. assert @response.body.include?("... Ce diff")
  411. end
  412. end
  413. end
  414. end
  415. def test_diff_two_revs
  416. assert_equal 0, @repository.changesets.count
  417. @repository.fetch_changesets
  418. @project.reload
  419. assert_equal NUM_REV, @repository.changesets.count
  420. ['inline', 'sbs'].each do |dt|
  421. get(
  422. :diff,
  423. :params => {
  424. :id => PRJ_ID,
  425. :repository_id => @repository.id,
  426. :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
  427. :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  428. :type => dt
  429. }
  430. )
  431. assert_response :success
  432. assert_select 'h2', :text => /2f9c0091:61b685fb/
  433. assert_select 'form[action=?]', "/projects/subproject1/repository/#{@repository.id}/revisions/61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff"
  434. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  435. end
  436. end
  437. def test_diff_path_in_subrepo
  438. repo =
  439. Repository::Git.
  440. create(
  441. :project => @project,
  442. :url => REPOSITORY_PATH,
  443. :identifier => 'test-diff-path',
  444. :path_encoding => 'ISO-8859-1'
  445. )
  446. assert repo
  447. assert_equal false, repo.is_default
  448. assert_equal 'test-diff-path', repo.identifier
  449. get(
  450. :diff,
  451. :params => {
  452. :id => PRJ_ID,
  453. :repository_id => 'test-diff-path',
  454. :rev => '61b685fbe55ab05b',
  455. :rev_to => '2f9c0091c754a91a',
  456. :type => 'inline'
  457. }
  458. )
  459. assert_response :success
  460. assert_select 'form[action=?]', '/projects/subproject1/repository/test-diff-path/revisions/61b685fbe55ab05b/diff'
  461. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91a'
  462. end
  463. def test_diff_latin_1
  464. if @not_utf8_external
  465. puts_pass_on_not_utf8
  466. else
  467. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  468. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  469. ['inline', 'sbs'].each do |dt|
  470. get(
  471. :diff,
  472. :params => {
  473. :id => PRJ_ID,
  474. :repository_id => @repository.id,
  475. :rev => r1,
  476. :type => dt
  477. }
  478. )
  479. assert_response :success
  480. assert_select 'table' do
  481. assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü.txt/
  482. assert_select 'tbody td.diff_in', :text => /test-Ü.txt/
  483. end
  484. end
  485. end
  486. end
  487. end
  488. end
  489. def test_diff_should_show_filenames
  490. get(
  491. :diff,
  492. :params => {
  493. :id => PRJ_ID,
  494. :repository_id => @repository.id,
  495. :rev => 'deff712f05a90d96edbd70facc47d944be5897e3',
  496. :type => 'inline'
  497. }
  498. )
  499. assert_response :success
  500. # modified file
  501. assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
  502. # deleted file
  503. assert_select 'th.filename', :text => 'test.txt'
  504. end
  505. def test_save_diff_type
  506. user1 = User.find(1)
  507. user1.pref[:diff_type] = nil
  508. user1.preference.save
  509. user = User.find(1)
  510. assert_nil user.pref[:diff_type]
  511. @request.session[:user_id] = 1 # admin
  512. get(
  513. :diff,
  514. :params => {
  515. :id => PRJ_ID,
  516. :repository_id => @repository.id,
  517. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  518. }
  519. )
  520. assert_response :success
  521. user.reload
  522. assert_equal "inline", user.pref[:diff_type]
  523. get(
  524. :diff,
  525. :params => {
  526. :id => PRJ_ID,
  527. :repository_id => @repository.id,
  528. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  529. :type => 'sbs'
  530. }
  531. )
  532. assert_response :success
  533. user.reload
  534. assert_equal "sbs", user.pref[:diff_type]
  535. end
  536. def test_annotate
  537. get(
  538. :annotate,
  539. :params => {
  540. :id => PRJ_ID,
  541. :repository_id => @repository.id,
  542. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  543. }
  544. )
  545. assert_response :success
  546. # Line 23, changeset 2f9c0091
  547. assert_select 'tr' do
  548. assert_select 'th.line-num', :text => '23'
  549. assert_select 'td.revision', :text => /2f9c0091/
  550. assert_select 'td.author', :text => 'jsmith'
  551. assert_select 'td', :text => /remove_watcher/
  552. end
  553. end
  554. def test_annotate_at_given_revision
  555. assert_equal 0, @repository.changesets.count
  556. @repository.fetch_changesets
  557. @project.reload
  558. assert_equal NUM_REV, @repository.changesets.count
  559. get(
  560. :annotate,
  561. :params => {
  562. :id => PRJ_ID,
  563. :repository_id => @repository.id,
  564. :rev => 'deff7',
  565. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  566. }
  567. )
  568. assert_response :success
  569. assert_select 'h2', :text => /@ deff712f/
  570. end
  571. def test_annotate_binary_file
  572. with_settings :default_language => 'en' do
  573. get(
  574. :annotate,
  575. :params => {
  576. :id => PRJ_ID,
  577. :repository_id => @repository.id,
  578. :path => repository_path_hash(['images', 'edit.png'])[:param]
  579. }
  580. )
  581. assert_response :success
  582. assert_select 'p#errorExplanation', :text => /cannot be annotated/
  583. end
  584. end
  585. def test_annotate_error_when_too_big
  586. with_settings :file_max_size_displayed => 1 do
  587. get(
  588. :annotate,
  589. :params => {
  590. :id => PRJ_ID,
  591. :repository_id => @repository.id,
  592. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  593. :rev => 'deff712f'
  594. }
  595. )
  596. assert_response :success
  597. assert_select 'p#errorExplanation', :text => /exceeds the maximum text file size/
  598. get(
  599. :annotate,
  600. :params => {
  601. :id => PRJ_ID,
  602. :repository_id => @repository.id,
  603. :path => repository_path_hash(['README'])[:param],
  604. :rev => '7234cb2'
  605. }
  606. )
  607. assert_response :success
  608. end
  609. end
  610. def test_annotate_latin_1
  611. if @not_utf8_external
  612. puts_pass_on_not_utf8
  613. elsif WINDOWS_PASS
  614. puts WINDOWS_SKIP_STR
  615. else
  616. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  617. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  618. get(
  619. :annotate,
  620. :params => {
  621. :id => PRJ_ID,
  622. :repository_id => @repository.id,
  623. :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
  624. :rev => r1
  625. }
  626. )
  627. assert_select "th.line-num", :text => '1' do
  628. assert_select "+ td.revision" do
  629. assert_select "a", :text => '57ca437c'
  630. assert_select "+ td.author", :text => "jsmith" do
  631. assert_select "+ td",
  632. :text => "test-Ü.txt"
  633. end
  634. end
  635. end
  636. end
  637. end
  638. end
  639. end
  640. def test_annotate_latin_1_author
  641. ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
  642. get(
  643. :annotate,
  644. :params => {
  645. :id => PRJ_ID,
  646. :repository_id => @repository.id,
  647. :path => repository_path_hash([" filename with a leading space.txt "])[:param],
  648. :rev => r1
  649. }
  650. )
  651. assert_select "th.line-num", :text => '1' do
  652. assert_select "+ td.revision" do
  653. assert_select "a", :text => '83ca5fd5'
  654. assert_select "+ td.author", :text => "Felix Schäfer" do
  655. assert_select "+ td",
  656. :text => "And this is a file with a leading and trailing space..."
  657. end
  658. end
  659. end
  660. end
  661. end
  662. def test_revisions
  663. assert_equal 0, @repository.changesets.count
  664. @repository.fetch_changesets
  665. @project.reload
  666. assert_equal NUM_REV, @repository.changesets.count
  667. get(
  668. :revisions,
  669. :params => {
  670. :id => PRJ_ID,
  671. :repository_id => @repository.id
  672. }
  673. )
  674. assert_select 'form[method=get][action=?]', "/projects/subproject1/repository/#{@repository.id}/revision"
  675. end
  676. def test_revision
  677. assert_equal 0, @repository.changesets.count
  678. @repository.fetch_changesets
  679. @project.reload
  680. assert_equal NUM_REV, @repository.changesets.count
  681. ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
  682. get(
  683. :revision,
  684. :params => {
  685. :id => PRJ_ID,
  686. :repository_id => @repository.id,
  687. :rev => r
  688. }
  689. )
  690. assert_response :success
  691. end
  692. end
  693. def test_empty_revision
  694. assert_equal 0, @repository.changesets.count
  695. @repository.fetch_changesets
  696. @project.reload
  697. assert_equal NUM_REV, @repository.changesets.count
  698. ['', ' ', nil].each do |r|
  699. get(
  700. :revision,
  701. :params => {
  702. :id => PRJ_ID,
  703. :repository_id => @repository.id,
  704. :rev => r
  705. }
  706. )
  707. assert_response 404
  708. assert_select_error /was not found/
  709. end
  710. end
  711. def test_destroy_valid_repository
  712. @request.session[:user_id] = 1 # admin
  713. assert_equal 0, @repository.changesets.count
  714. @repository.fetch_changesets
  715. @project.reload
  716. assert_equal NUM_REV, @repository.changesets.count
  717. assert_difference 'Repository.count', -1 do
  718. delete(
  719. :destroy,
  720. :params => {
  721. :id => @repository.id
  722. }
  723. )
  724. end
  725. assert_response 302
  726. @project.reload
  727. assert_nil @project.repository
  728. end
  729. def test_destroy_invalid_repository
  730. @request.session[:user_id] = 1 # admin
  731. @project.repository.destroy
  732. @repository =
  733. Repository::Git.
  734. create!(
  735. :project => @project,
  736. :url => "/invalid",
  737. :path_encoding => 'ISO-8859-1'
  738. )
  739. @repository.fetch_changesets
  740. @repository.reload
  741. assert_equal 0, @repository.changesets.count
  742. assert_difference 'Repository.count', -1 do
  743. delete(
  744. :destroy,
  745. :params => {
  746. :id => @repository.id
  747. }
  748. )
  749. end
  750. assert_response 302
  751. @project.reload
  752. assert_nil @project.repository
  753. end
  754. private
  755. def puts_pass_on_not_utf8
  756. puts "TODO: This test fails " +
  757. "when Encoding.default_external is not UTF-8. " +
  758. "Current value is '#{Encoding.default_external.to_s}'"
  759. end
  760. else
  761. puts "Git test repository NOT FOUND. Skipping functional tests !!!"
  762. def test_fake; assert true end
  763. end
  764. private
  765. def with_cache(&block)
  766. before = ActionController::Base.perform_caching
  767. ActionController::Base.perform_caching = true
  768. yield
  769. ActionController::Base.perform_caching = before
  770. end
  771. end