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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 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 < Redmine::RepositoryControllerTest
  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. super
  37. @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
  38. User.current = nil
  39. @project = Project.find(PRJ_ID)
  40. @repository = Repository::Git.create(
  41. :project => @project,
  42. :url => REPOSITORY_PATH,
  43. :path_encoding => 'ISO-8859-1'
  44. )
  45. assert @repository
  46. end
  47. def test_create_and_update
  48. @request.session[:user_id] = 1
  49. assert_difference 'Repository.count' do
  50. post :create, :params => {
  51. :project_id => 'subproject1',
  52. :repository_scm => 'Git',
  53. :repository => {
  54. :url => '/test',
  55. :is_default => '0',
  56. :identifier => 'test-create',
  57. :report_last_commit => '1',
  58. }
  59. }
  60. end
  61. assert_response 302
  62. repository = Repository.order('id DESC').first
  63. assert_kind_of Repository::Git, repository
  64. assert_equal '/test', repository.url
  65. assert_equal true, repository.report_last_commit
  66. put :update, :params => {
  67. :id => repository.id,
  68. :repository => {
  69. :report_last_commit => '0'
  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 :new, :params => {
  90. :project_id => 'subproject1',
  91. :repository_scm => 'Git'
  92. }
  93. assert_response :success
  94. assert_select 'select[name=?]', 'repository_scm' do
  95. assert_select 'option[value=?][selected=selected]', 'Git'
  96. end
  97. end
  98. def test_browse_root
  99. assert_equal 0, @repository.changesets.count
  100. @repository.fetch_changesets
  101. @project.reload
  102. assert_equal NUM_REV, @repository.changesets.count
  103. get :show, :params => {
  104. :id => PRJ_ID
  105. }
  106. assert_response :success
  107. assert_select 'table.entries tbody' do
  108. assert_select 'tr', 9
  109. assert_select 'tr.dir td.filename_no_report a', :text => 'images'
  110. assert_select 'tr.dir td.filename_no_report a', :text => 'this_is_a_really_long_and_verbose_directory_name'
  111. assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
  112. assert_select 'tr.file td.filename_no_report a', :text => 'README'
  113. assert_select 'tr.file td.filename_no_report a', :text => 'copied_README'
  114. assert_select 'tr.file td.filename_no_report a', :text => 'new_file.txt'
  115. assert_select 'tr.file td.filename_no_report a', :text => 'renamed_test.txt'
  116. assert_select 'tr.file td.filename_no_report a', :text => 'filemane with spaces.txt'
  117. assert_select 'tr.file td.filename_no_report a', :text => 'filename with a leading space.txt'
  118. end
  119. assert_select 'table.changesets tbody' do
  120. assert_select 'tr'
  121. end
  122. end
  123. def test_browse_branch
  124. assert_equal 0, @repository.changesets.count
  125. @repository.fetch_changesets
  126. @project.reload
  127. assert_equal NUM_REV, @repository.changesets.count
  128. get :show, :params => {
  129. :id => PRJ_ID,
  130. :repository_id => @repository.id,
  131. :rev => 'test_branch'
  132. }
  133. assert_response :success
  134. assert_select 'table.entries tbody' do
  135. assert_select 'tr', 4
  136. assert_select 'tr.dir td.filename_no_report a', :text => 'images'
  137. assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
  138. assert_select 'tr.file td.filename_no_report a', :text => 'README'
  139. assert_select 'tr.file td.filename_no_report a', :text => 'test.txt'
  140. end
  141. assert_select 'table.changesets tbody' do
  142. assert_select 'tr'
  143. end
  144. end
  145. def test_browse_tag
  146. assert_equal 0, @repository.changesets.count
  147. @repository.fetch_changesets
  148. @project.reload
  149. assert_equal NUM_REV, @repository.changesets.count
  150. [
  151. "tag00.lightweight",
  152. "tag01.annotated",
  153. ].each do |t1|
  154. get :show, :params => {
  155. :id => PRJ_ID,
  156. :repository_id => @repository.id,
  157. :rev => t1
  158. }
  159. assert_response :success
  160. assert_select 'table.entries tbody tr'
  161. assert_select 'table.changesets tbody tr'
  162. end
  163. end
  164. def test_browse_directory
  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, :params => {
  170. :id => PRJ_ID,
  171. :repository_id => @repository.id,
  172. :path => repository_path_hash(['images'])[:param]
  173. }
  174. assert_response :success
  175. assert_select 'table.entries tbody' do
  176. assert_select 'tr', 1
  177. assert_select 'tr.file td.filename_no_report a', :text => 'edit.png'
  178. end
  179. assert_select 'table.changesets tbody tr'
  180. end
  181. def test_browse_at_given_revision
  182. assert_equal 0, @repository.changesets.count
  183. @repository.fetch_changesets
  184. @project.reload
  185. assert_equal NUM_REV, @repository.changesets.count
  186. get :show, :params => {
  187. :id => PRJ_ID,
  188. :repository_id => @repository.id,
  189. :path => repository_path_hash(['images'])[:param],
  190. :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
  191. }
  192. assert_response :success
  193. assert_select 'table.entries tbody' do
  194. assert_select 'tr', 1
  195. assert_select 'tr.file td.filename_no_report a', :text => 'delete.png'
  196. end
  197. end
  198. def test_changes
  199. get :changes, :params => {
  200. :id => PRJ_ID,
  201. :repository_id => @repository.id,
  202. :path => repository_path_hash(['images', 'edit.png'])[:param]
  203. }
  204. assert_response :success
  205. assert_select 'h2', :text => /edit.png/
  206. end
  207. def test_entry_show
  208. get :entry, :params => {
  209. :id => PRJ_ID,
  210. :repository_id => @repository.id,
  211. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  212. }
  213. assert_response :success
  214. # Line 11
  215. assert_select 'tr#L11 td.line-code', :text => /WITHOUT ANY WARRANTY/
  216. end
  217. def test_entry_show_should_render_pagination
  218. get :entry, :params => {
  219. :id => PRJ_ID,
  220. :repository_id => @repository.id,
  221. :path => repository_path_hash(['README'])[:param]
  222. }
  223. assert_response :success
  224. assert_select 'ul.pages li.next', :text => /next/i
  225. assert_select 'ul.pages li.previous', :text => /previous/i
  226. end
  227. def test_entry_show_latin_1
  228. if @ruby19_non_utf8_pass
  229. puts_ruby19_non_utf8_pass()
  230. elsif WINDOWS_PASS
  231. puts WINDOWS_SKIP_STR
  232. elsif JRUBY_SKIP
  233. puts JRUBY_SKIP_STR
  234. else
  235. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  236. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  237. get :entry, :params => {
  238. :id => PRJ_ID,
  239. :repository_id => @repository.id,
  240. :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
  241. :rev => r1
  242. }
  243. assert_response :success
  244. assert_select 'tr#L1 td.line-code', :text => /test-#{CHAR_1_HEX}.txt/
  245. end
  246. end
  247. end
  248. end
  249. def test_entry_download
  250. get :entry, :params => {
  251. :id => PRJ_ID,
  252. :repository_id => @repository.id,
  253. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  254. :format => 'raw'
  255. }
  256. assert_response :success
  257. # File content
  258. assert @response.body.include?('WITHOUT ANY WARRANTY')
  259. end
  260. def test_directory_entry
  261. get :entry, :params => {
  262. :id => PRJ_ID,
  263. :repository_id => @repository.id,
  264. :path => repository_path_hash(['sources'])[:param]
  265. }
  266. assert_response :success
  267. assert_select 'h2 a', :text => 'sources'
  268. assert_select 'table.entries tbody'
  269. assert_select 'div.contextual > a.icon-download', false
  270. end
  271. def test_diff
  272. assert_equal true, @repository.is_default
  273. assert @repository.identifier.blank?
  274. assert_equal 0, @repository.changesets.count
  275. @repository.fetch_changesets
  276. @project.reload
  277. assert_equal NUM_REV, @repository.changesets.count
  278. # Full diff of changeset 2f9c0091
  279. ['inline', 'sbs'].each do |dt|
  280. get :diff, :params => {
  281. :id => PRJ_ID,
  282. :repository_id => @repository.id,
  283. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  284. :type => dt
  285. }
  286. assert_response :success
  287. # Line 22 removed
  288. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  289. assert_select 'h2', :text => /2f9c0091/
  290. end
  291. end
  292. def test_diff_with_rev_and_path
  293. assert_equal 0, @repository.changesets.count
  294. @repository.fetch_changesets
  295. @project.reload
  296. assert_equal NUM_REV, @repository.changesets.count
  297. with_settings :diff_max_lines_displayed => 1000 do
  298. # Full diff of changeset 2f9c0091
  299. ['inline', 'sbs'].each do |dt|
  300. get :diff, :params => {
  301. :id => PRJ_ID,
  302. :repository_id => @repository.id,
  303. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  304. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  305. :type => dt
  306. }
  307. assert_response :success
  308. # Line 22 removed
  309. assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
  310. assert_select 'h2', :text => /2f9c0091/
  311. end
  312. end
  313. end
  314. def test_diff_truncated
  315. assert_equal 0, @repository.changesets.count
  316. @repository.fetch_changesets
  317. @project.reload
  318. assert_equal NUM_REV, @repository.changesets.count
  319. with_settings :diff_max_lines_displayed => 5 do
  320. # Truncated diff of changeset 2f9c0091
  321. with_cache do
  322. with_settings :default_language => 'en' do
  323. get :diff, :params => {
  324. :id => PRJ_ID,
  325. :repository_id => @repository.id,
  326. :type => 'inline',
  327. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  328. }
  329. assert_response :success
  330. assert @response.body.include?("... This diff was truncated")
  331. end
  332. with_settings :default_language => 'fr' do
  333. get :diff, :params => {
  334. :id => PRJ_ID,
  335. :repository_id => @repository.id,
  336. :type => 'inline',
  337. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  338. }
  339. assert_response :success
  340. assert ! @response.body.include?("... This diff was truncated")
  341. assert @response.body.include?("... Ce diff")
  342. end
  343. end
  344. end
  345. end
  346. def test_diff_two_revs
  347. assert_equal 0, @repository.changesets.count
  348. @repository.fetch_changesets
  349. @project.reload
  350. assert_equal NUM_REV, @repository.changesets.count
  351. ['inline', 'sbs'].each do |dt|
  352. get :diff, :params => {
  353. :id => PRJ_ID,
  354. :repository_id => @repository.id,
  355. :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
  356. :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  357. :type => dt
  358. }
  359. assert_response :success
  360. assert_select 'h2', :text => /2f9c0091:61b685fb/
  361. assert_select 'form[action=?]', "/projects/subproject1/repository/#{@repository.id}/revisions/61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff"
  362. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  363. end
  364. end
  365. def test_diff_path_in_subrepo
  366. repo = Repository::Git.create(
  367. :project => @project,
  368. :url => REPOSITORY_PATH,
  369. :identifier => 'test-diff-path',
  370. :path_encoding => 'ISO-8859-1'
  371. )
  372. assert repo
  373. assert_equal false, repo.is_default
  374. assert_equal 'test-diff-path', repo.identifier
  375. get :diff, :params => {
  376. :id => PRJ_ID,
  377. :repository_id => 'test-diff-path',
  378. :rev => '61b685fbe55ab05b',
  379. :rev_to => '2f9c0091c754a91a',
  380. :type => 'inline'
  381. }
  382. assert_response :success
  383. assert_select 'form[action=?]', '/projects/subproject1/repository/test-diff-path/revisions/61b685fbe55ab05b/diff'
  384. assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91a'
  385. end
  386. def test_diff_latin_1
  387. if @ruby19_non_utf8_pass
  388. puts_ruby19_non_utf8_pass()
  389. else
  390. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  391. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  392. ['inline', 'sbs'].each do |dt|
  393. get :diff, :params => {
  394. :id => PRJ_ID,
  395. :repository_id => @repository.id,
  396. :rev => r1,
  397. :type => dt
  398. }
  399. assert_response :success
  400. assert_select 'table' do
  401. assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{CHAR_1_HEX}.txt/
  402. assert_select 'tbody td.diff_in', :text => /test-#{CHAR_1_HEX}.txt/
  403. end
  404. end
  405. end
  406. end
  407. end
  408. end
  409. def test_diff_should_show_filenames
  410. get :diff, :params => {
  411. :id => PRJ_ID,
  412. :repository_id => @repository.id,
  413. :rev => 'deff712f05a90d96edbd70facc47d944be5897e3',
  414. :type => 'inline'
  415. }
  416. assert_response :success
  417. # modified file
  418. assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
  419. # deleted file
  420. assert_select 'th.filename', :text => 'test.txt'
  421. end
  422. def test_save_diff_type
  423. user1 = User.find(1)
  424. user1.pref[:diff_type] = nil
  425. user1.preference.save
  426. user = User.find(1)
  427. assert_nil user.pref[:diff_type]
  428. @request.session[:user_id] = 1 # admin
  429. get :diff, :params => {
  430. :id => PRJ_ID,
  431. :repository_id => @repository.id,
  432. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
  433. }
  434. assert_response :success
  435. user.reload
  436. assert_equal "inline", user.pref[:diff_type]
  437. get :diff, :params => {
  438. :id => PRJ_ID,
  439. :repository_id => @repository.id,
  440. :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
  441. :type => 'sbs'
  442. }
  443. assert_response :success
  444. user.reload
  445. assert_equal "sbs", user.pref[:diff_type]
  446. end
  447. def test_annotate
  448. get :annotate, :params => {
  449. :id => PRJ_ID,
  450. :repository_id => @repository.id,
  451. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  452. }
  453. assert_response :success
  454. # Line 23, changeset 2f9c0091
  455. assert_select 'tr' do
  456. assert_select 'th.line-num', :text => '23'
  457. assert_select 'td.revision', :text => /2f9c0091/
  458. assert_select 'td.author', :text => 'jsmith'
  459. assert_select 'td', :text => /remove_watcher/
  460. end
  461. end
  462. def test_annotate_at_given_revision
  463. assert_equal 0, @repository.changesets.count
  464. @repository.fetch_changesets
  465. @project.reload
  466. assert_equal NUM_REV, @repository.changesets.count
  467. get :annotate, :params => {
  468. :id => PRJ_ID,
  469. :repository_id => @repository.id,
  470. :rev => 'deff7',
  471. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  472. }
  473. assert_response :success
  474. assert_select 'h2', :text => /@ deff712f/
  475. end
  476. def test_annotate_binary_file
  477. with_settings :default_language => 'en' do
  478. get :annotate, :params => {
  479. :id => PRJ_ID,
  480. :repository_id => @repository.id,
  481. :path => repository_path_hash(['images', 'edit.png'])[:param]
  482. }
  483. assert_response :success
  484. assert_select 'p#errorExplanation', :text => /cannot be annotated/
  485. end
  486. end
  487. def test_annotate_error_when_too_big
  488. with_settings :file_max_size_displayed => 1 do
  489. get :annotate, :params => {
  490. :id => PRJ_ID,
  491. :repository_id => @repository.id,
  492. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  493. :rev => 'deff712f'
  494. }
  495. assert_response :success
  496. assert_select 'p#errorExplanation', :text => /exceeds the maximum text file size/
  497. get :annotate, :params => {
  498. :id => PRJ_ID,
  499. :repository_id => @repository.id,
  500. :path => repository_path_hash(['README'])[:param],
  501. :rev => '7234cb2'
  502. }
  503. assert_response :success
  504. end
  505. end
  506. def test_annotate_latin_1
  507. if @ruby19_non_utf8_pass
  508. puts_ruby19_non_utf8_pass()
  509. elsif WINDOWS_PASS
  510. puts WINDOWS_SKIP_STR
  511. elsif JRUBY_SKIP
  512. puts JRUBY_SKIP_STR
  513. else
  514. with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
  515. ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
  516. get :annotate, :params => {
  517. :id => PRJ_ID,
  518. :repository_id => @repository.id,
  519. :path => repository_path_hash(['latin-1-dir', "test-#{CHAR_1_HEX}.txt"])[:param],
  520. :rev => r1
  521. }
  522. assert_select "th.line-num", :text => '1' do
  523. assert_select "+ td.revision" do
  524. assert_select "a", :text => '57ca437c'
  525. assert_select "+ td.author", :text => "jsmith" do
  526. assert_select "+ td",
  527. :text => "test-#{CHAR_1_HEX}.txt"
  528. end
  529. end
  530. end
  531. end
  532. end
  533. end
  534. end
  535. def test_annotate_latin_1_author
  536. ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
  537. get :annotate, :params => {
  538. :id => PRJ_ID,
  539. :repository_id => @repository.id,
  540. :path => repository_path_hash([" filename with a leading space.txt "])[:param],
  541. :rev => r1
  542. }
  543. assert_select "th.line-num", :text => '1' do
  544. assert_select "+ td.revision" do
  545. assert_select "a", :text => '83ca5fd5'
  546. assert_select "+ td.author", :text => FELIX_HEX do
  547. assert_select "+ td",
  548. :text => "And this is a file with a leading and trailing space..."
  549. end
  550. end
  551. end
  552. end
  553. end
  554. def test_revisions
  555. assert_equal 0, @repository.changesets.count
  556. @repository.fetch_changesets
  557. @project.reload
  558. assert_equal NUM_REV, @repository.changesets.count
  559. get :revisions, :params => {
  560. :id => PRJ_ID,
  561. :repository_id => @repository.id
  562. }
  563. assert_select 'form[method=get][action=?]', "/projects/subproject1/repository/#{@repository.id}/revision"
  564. end
  565. def test_revision
  566. assert_equal 0, @repository.changesets.count
  567. @repository.fetch_changesets
  568. @project.reload
  569. assert_equal NUM_REV, @repository.changesets.count
  570. ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
  571. get :revision, :params => {
  572. :id => PRJ_ID,
  573. :repository_id => @repository.id,
  574. :rev => r
  575. }
  576. assert_response :success
  577. end
  578. end
  579. def test_empty_revision
  580. assert_equal 0, @repository.changesets.count
  581. @repository.fetch_changesets
  582. @project.reload
  583. assert_equal NUM_REV, @repository.changesets.count
  584. ['', ' ', nil].each do |r|
  585. get :revision, :params => {
  586. :id => PRJ_ID,
  587. :repository_id => @repository.id,
  588. :rev => r
  589. }
  590. assert_response 404
  591. assert_select_error /was not found/
  592. end
  593. end
  594. def test_destroy_valid_repository
  595. @request.session[:user_id] = 1 # admin
  596. assert_equal 0, @repository.changesets.count
  597. @repository.fetch_changesets
  598. @project.reload
  599. assert_equal NUM_REV, @repository.changesets.count
  600. assert_difference 'Repository.count', -1 do
  601. delete :destroy, :params => {
  602. :id => @repository.id
  603. }
  604. end
  605. assert_response 302
  606. @project.reload
  607. assert_nil @project.repository
  608. end
  609. def test_destroy_invalid_repository
  610. @request.session[:user_id] = 1 # admin
  611. @project.repository.destroy
  612. @repository = Repository::Git.create!(
  613. :project => @project,
  614. :url => "/invalid",
  615. :path_encoding => 'ISO-8859-1'
  616. )
  617. @repository.fetch_changesets
  618. @repository.reload
  619. assert_equal 0, @repository.changesets.count
  620. assert_difference 'Repository.count', -1 do
  621. delete :destroy, :params => {
  622. :id => @repository.id
  623. }
  624. end
  625. assert_response 302
  626. @project.reload
  627. assert_nil @project.repository
  628. end
  629. private
  630. def puts_ruby19_non_utf8_pass
  631. puts "TODO: This test fails " +
  632. "when Encoding.default_external is not UTF-8. " +
  633. "Current value is '#{Encoding.default_external.to_s}'"
  634. end
  635. else
  636. puts "Git test repository NOT FOUND. Skipping functional tests !!!"
  637. def test_fake; assert true end
  638. end
  639. private
  640. def with_cache(&block)
  641. before = ActionController::Base.perform_caching
  642. ActionController::Base.perform_caching = true
  643. block.call
  644. ActionController::Base.perform_caching = before
  645. end
  646. end