repositories_git_controller_test.rb 23.8 KB
Newer Older
1
# frozen_string_literal: true
2

3
# Redmine - project management software
jplang's avatar
jplang committed
4
# Copyright (C) 2006-2017  Jean-Philippe Lang
5 6 7 8 9
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
10
#
11 12 13 14
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
15
#
16 17 18 19
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

20
require File.expand_path('../../test_helper', __FILE__)
21

22
class RepositoriesGitControllerTest < Redmine::RepositoryControllerTest
23 24
  tests RepositoriesController

25
  fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
26
           :repositories, :enabled_modules
27

28
  REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
29
  REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30
  PRJ_ID     = 3
31
  NUM_REV = 28
32

33 34 35 36 37 38 39 40
  ## Git, Mercurial and CVS path encodings are binary.
  ## Subversion supports URL encoding for path.
  ## Redmine Mercurial adapter and extension use URL encoding.
  ## Git accepts only binary path in command line parameter.
  ## So, there is no way to use binary command line parameter in JRuby.
  JRUBY_SKIP     = (RUBY_PLATFORM == 'java')
  JRUBY_SKIP_STR = "TODO: This test fails in JRuby"

41
  def setup
42
    super
43
    @ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
44

45
    User.current = nil
46
    @project    = Project.find(PRJ_ID)
47
    @repository = Repository::Git.create(
48 49
                      :project       => @project,
                      :url           => REPOSITORY_PATH,
50 51
                      :path_encoding => 'ISO-8859-1'
                      )
52
    assert @repository
53
  end
54

55 56 57
  def test_create_and_update
    @request.session[:user_id] = 1
    assert_difference 'Repository.count' do
58 59 60 61 62 63 64 65 66 67 68
      post :create, :params => {
          :project_id => 'subproject1',
          :repository_scm => 'Git',
          :repository => {
            :url => '/test',
            :is_default => '0',
            :identifier => 'test-create',
            :report_last_commit => '1',
                                 
          }
        }
69 70
    end
    assert_response 302
71
    repository = Repository.order('id DESC').first
72 73
    assert_kind_of Repository::Git, repository
    assert_equal '/test', repository.url
74
    assert_equal true, repository.report_last_commit
75

76 77 78 79 80 81 82
    put :update, :params => {
        :id => repository.id,
        :repository => {
          :report_last_commit => '0'
          
        }
      }
83 84
    assert_response 302
    repo2 = Repository.find(repository.id)
85
    assert_equal false, repo2.report_last_commit
86 87
  end

88
  if File.directory?(REPOSITORY_PATH)
89 90 91 92 93 94 95 96 97 98
    ## Ruby uses ANSI api to fork a process on Windows.
    ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
    ## and these are incompatible with ASCII.
    ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
    ## http://code.google.com/p/msysgit/issues/detail?id=80
    ## So, Latin-1 path tests fail on Japanese Windows
    WINDOWS_PASS = (Redmine::Platform.mswin? &&
                         Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
    WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"

99
    def test_get_new
100 101
      @request.session[:user_id] = 1
      @project.repository.destroy
102 103 104 105
      get :new, :params => {
          :project_id => 'subproject1',
          :repository_scm => 'Git'
        }
106
      assert_response :success
107 108 109
      assert_select 'select[name=?]', 'repository_scm' do
        assert_select 'option[value=?][selected=selected]', 'Git'
      end
110 111
    end

112
    def test_browse_root
113
      assert_equal 0, @repository.changesets.count
114
      @repository.fetch_changesets
115 116 117
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count

118 119 120
      get :show, :params => {
          :id => PRJ_ID
        }
121
      assert_response :success
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

      assert_select 'table.entries tbody' do
        assert_select 'tr', 9
        assert_select 'tr.dir td.filename_no_report a', :text => 'images'
        assert_select 'tr.dir td.filename_no_report a', :text => 'this_is_a_really_long_and_verbose_directory_name'
        assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
        assert_select 'tr.file td.filename_no_report a', :text => 'README'
        assert_select 'tr.file td.filename_no_report a', :text => 'copied_README'
        assert_select 'tr.file td.filename_no_report a', :text => 'new_file.txt'
        assert_select 'tr.file td.filename_no_report a', :text => 'renamed_test.txt'
        assert_select 'tr.file td.filename_no_report a', :text => 'filemane with spaces.txt'
        assert_select 'tr.file td.filename_no_report a', :text => 'filename with a leading space.txt'
      end

      assert_select 'table.changesets tbody' do
        assert_select 'tr'
      end
139
    end
140 141

    def test_browse_branch
142
      assert_equal 0, @repository.changesets.count
143
      @repository.fetch_changesets
144 145
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
146 147
      get :show, :params => {
          :id => PRJ_ID,
148
          :repository_id => @repository.id,
149 150
          :rev => 'test_branch'
        }
151
      assert_response :success
152 153 154 155 156 157 158 159 160 161 162 163

      assert_select 'table.entries tbody' do
        assert_select 'tr', 4
        assert_select 'tr.dir td.filename_no_report a', :text => 'images'
        assert_select 'tr.dir td.filename_no_report a', :text => 'sources'
        assert_select 'tr.file td.filename_no_report a', :text => 'README'
        assert_select 'tr.file td.filename_no_report a', :text => 'test.txt'
      end

      assert_select 'table.changesets tbody' do
        assert_select 'tr'
      end
164 165
    end

166
    def test_browse_tag
167
      assert_equal 0, @repository.changesets.count
168
      @repository.fetch_changesets
169 170
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
171 172 173 174
       [
        "tag00.lightweight",
        "tag01.annotated",
       ].each do |t1|
175 176
        get :show, :params => {
            :id => PRJ_ID,
177
            :repository_id => @repository.id,
178 179
            :rev => t1
          }
180
        assert_response :success
181 182 183

        assert_select 'table.entries tbody tr'
        assert_select 'table.changesets tbody tr'
184 185 186
      end
    end

187
    def test_browse_directory
188
      assert_equal 0, @repository.changesets.count
189
      @repository.fetch_changesets
190 191
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
192 193
      get :show, :params => {
          :id => PRJ_ID,
194
          :repository_id => @repository.id,
195 196
          :path => repository_path_hash(['images'])[:param]
        }
197
      assert_response :success
198 199 200 201 202 203

      assert_select 'table.entries tbody' do
        assert_select 'tr', 1
        assert_select 'tr.file td.filename_no_report a', :text => 'edit.png'
      end
      assert_select 'table.changesets tbody tr'
204
    end
205

206
    def test_browse_at_given_revision
207
      assert_equal 0, @repository.changesets.count
208
      @repository.fetch_changesets
209 210
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
211 212
      get :show, :params => {
          :id => PRJ_ID,
213
          :repository_id => @repository.id,
214
          :path => repository_path_hash(['images'])[:param],
215
          :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
216
        }
217
      assert_response :success
218 219 220 221 222

      assert_select 'table.entries tbody' do
        assert_select 'tr', 1
        assert_select 'tr.file td.filename_no_report a', :text => 'delete.png'
      end
223 224
    end

225
    def test_changes
226 227
      get :changes, :params => {
          :id => PRJ_ID,
228
          :repository_id => @repository.id,
229
          :path => repository_path_hash(['images', 'edit.png'])[:param]
230
        }
231
      assert_response :success
232
      assert_select 'h2', :text => /edit.png/
233
    end
234

235
    def test_entry_show
236 237
      get :entry, :params => {
          :id => PRJ_ID,
238
          :repository_id => @repository.id,
239
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
240
        }
241
      assert_response :success
242 243
      # Line 11
      assert_select 'tr#L11 td.line-code', :text => /WITHOUT ANY WARRANTY/
244
    end
245

246 247 248 249 250 251 252 253 254 255 256
    def test_entry_show_should_render_pagination
      get :entry, :params => {
          :id => PRJ_ID,
          :repository_id => @repository.id,
          :path => repository_path_hash(['README'])[:param]
        }
      assert_response :success
      assert_select 'ul.pages li.next', :text => /next/i
      assert_select 'ul.pages li.previous', :text => /previous/i
    end

257 258 259
    def test_entry_show_latin_1
      if @ruby19_non_utf8_pass
        puts_ruby19_non_utf8_pass()
260 261
      elsif WINDOWS_PASS
        puts WINDOWS_SKIP_STR
262 263
      elsif JRUBY_SKIP
        puts JRUBY_SKIP_STR
264 265 266
      else
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
267 268
            get :entry, :params => {
                :id => PRJ_ID,
269
                :repository_id => @repository.id,
270
              :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
271 272
              :rev => r1
              }
273
            assert_response :success
274
            assert_select 'tr#L1 td.line-code', :text => /test-Ü.txt/
275 276 277 278 279
          end
        end
      end
    end

280
    def test_entry_download
281 282
      get :entry, :params => {
          :id => PRJ_ID,
283
          :repository_id => @repository.id,
284
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
285
          :format => 'raw'
286
        }
287 288 289 290
      assert_response :success
      # File content
      assert @response.body.include?('WITHOUT ANY WARRANTY')
    end
291

292
    def test_directory_entry
293 294
      get :entry, :params => {
          :id => PRJ_ID,
295
          :repository_id => @repository.id,
296
          :path => repository_path_hash(['sources'])[:param]
297
        }
298
      assert_response :success
299 300
      assert_select 'h2 a', :text => 'sources'
      assert_select 'table.entries tbody'
301 302
      assert_select 'div.contextual > a.icon-download', false

303
    end
304

305
    def test_diff
306
      assert_equal true, @repository.is_default
jplang's avatar
jplang committed
307
      assert @repository.identifier.blank?
308
      assert_equal 0, @repository.changesets.count
309
      @repository.fetch_changesets
310 311
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
312
      # Full diff of changeset 2f9c0091
313
      ['inline', 'sbs'].each do |dt|
314
        get :diff, :params => {
315
            :id   => PRJ_ID,
316
            :repository_id => @repository.id,
317 318
            :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
            :type => dt
319
          }
320 321
        assert_response :success
        # Line 22 removed
322
        assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
323
        assert_select 'h2', :text => /2f9c0091/
324
      end
325 326
    end

327 328 329 330 331
    def test_diff_with_rev_and_path
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
332 333 334
      with_settings :diff_max_lines_displayed => 1000 do
        # Full diff of changeset 2f9c0091
        ['inline', 'sbs'].each do |dt|
335
          get :diff, :params => {
336
              :id   => PRJ_ID,
337
              :repository_id => @repository.id,
338 339 340
              :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
              :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
              :type => dt
341
            }
342 343
          assert_response :success
          # Line 22 removed
344
          assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
345
          assert_select 'h2', :text => /2f9c0091/
346
        end
347 348 349
      end
    end

350
    def test_diff_truncated
351
      assert_equal 0, @repository.changesets.count
352
      @repository.fetch_changesets
353 354
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
355

356 357 358
      with_settings :diff_max_lines_displayed => 5 do
        # Truncated diff of changeset 2f9c0091
        with_cache do
359
          with_settings :default_language => 'en' do
360 361
            get :diff, :params => {
                :id   => PRJ_ID,
362
                :repository_id => @repository.id,
363
                :type => 'inline',
364
                :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
365
              }
366 367 368
            assert_response :success
            assert @response.body.include?("... This diff was truncated")
          end
369
          with_settings :default_language => 'fr' do
370 371
            get :diff, :params => {
                :id   => PRJ_ID,
372
                :repository_id => @repository.id,
373
                :type => 'inline',
374
                :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
375
              }
376 377 378 379
            assert_response :success
            assert ! @response.body.include?("... This diff was truncated")
            assert @response.body.include?("... Ce diff")
          end
380
        end
381 382 383
      end
    end

384
    def test_diff_two_revs
385
      assert_equal 0, @repository.changesets.count
386
      @repository.fetch_changesets
387 388
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
389
      ['inline', 'sbs'].each do |dt|
390
        get :diff, :params => {
391
            :id     => PRJ_ID,
392
            :repository_id => @repository.id,
393 394 395
            :rev    => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
            :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
            :type   => dt
396
          }
397
        assert_response :success
398
        assert_select 'h2', :text => /2f9c0091:61b685fb/
399
        assert_select 'form[action=?]', "/projects/subproject1/repository/#{@repository.id}/revisions/61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff"
400
        assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
401
      end
402 403
    end

404 405 406 407 408 409
    def test_diff_path_in_subrepo
      repo = Repository::Git.create(
                      :project       => @project,
                      :url           => REPOSITORY_PATH,
                      :identifier => 'test-diff-path',
                      :path_encoding => 'ISO-8859-1'
410
                      )
411 412 413
      assert repo
      assert_equal false, repo.is_default
      assert_equal 'test-diff-path', repo.identifier
414
      get :diff, :params => {
415 416 417 418 419
          :id     => PRJ_ID,
          :repository_id => 'test-diff-path',
          :rev    => '61b685fbe55ab05b',
          :rev_to => '2f9c0091c754a91a',
          :type   => 'inline'
420
        }
421
      assert_response :success
422 423
      assert_select 'form[action=?]', '/projects/subproject1/repository/test-diff-path/revisions/61b685fbe55ab05b/diff'
      assert_select 'input#rev_to[type=hidden][name=rev_to][value=?]', '2f9c0091c754a91a'
424 425
    end

426 427 428 429 430 431
    def test_diff_latin_1
      if @ruby19_non_utf8_pass
        puts_ruby19_non_utf8_pass()
      else
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
432
            ['inline', 'sbs'].each do |dt|
433 434
              get :diff, :params => {
                  :id => PRJ_ID,
435
                  :repository_id => @repository.id,
436 437 438
                  :rev => r1,
                  :type => dt
                }
439
              assert_response :success
440
              assert_select 'table' do
441 442
                assert_select 'thead th.filename', :text => /latin-1-dir\/test-Ü.txt/
                assert_select 'tbody td.diff_in', :text => /test-Ü.txt/
443
              end
444
            end
445 446 447 448 449
          end
        end
      end
    end

450
    def test_diff_should_show_filenames
451 452
      get :diff, :params => {
          :id => PRJ_ID,
453
          :repository_id => @repository.id,
454 455 456
          :rev => 'deff712f05a90d96edbd70facc47d944be5897e3',
          :type => 'inline'
        }
457 458 459 460 461 462 463
      assert_response :success
      # modified file
      assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
      # deleted file
      assert_select 'th.filename', :text => 'test.txt'
    end

464
    def test_save_diff_type
465 466 467
      user1 = User.find(1)
      user1.pref[:diff_type] = nil
      user1.preference.save
468
      user = User.find(1)
469 470 471
      assert_nil user.pref[:diff_type]

      @request.session[:user_id] = 1 # admin
472
      get :diff, :params => {
473
          :id   => PRJ_ID,
474
          :repository_id => @repository.id,
475
          :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
476
        }
477 478 479
      assert_response :success
      user.reload
      assert_equal "inline", user.pref[:diff_type]
480
      get :diff, :params => {
481
          :id   => PRJ_ID,
482
          :repository_id => @repository.id,
483 484
          :rev  => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
          :type => 'sbs'
485
        }
486 487 488 489 490
      assert_response :success
      user.reload
      assert_equal "sbs", user.pref[:diff_type]
    end

491
    def test_annotate
492 493
      get :annotate, :params => {
          :id => PRJ_ID,
494
          :repository_id => @repository.id,
495
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
496
        }
497
      assert_response :success
498

499
      # Line 23, changeset 2f9c0091
500 501 502 503 504 505
      assert_select 'tr' do
        assert_select 'th.line-num', :text => '23'
        assert_select 'td.revision', :text => /2f9c0091/
        assert_select 'td.author', :text => 'jsmith'
        assert_select 'td', :text => /remove_watcher/
      end
506
    end
507

508
    def test_annotate_at_given_revision
509
      assert_equal 0, @repository.changesets.count
510
      @repository.fetch_changesets
511 512
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
513 514
      get :annotate, :params => {
          :id => PRJ_ID,
515
          :repository_id => @repository.id,
516
          :rev => 'deff7',
517
          :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
518
        }
519
      assert_response :success
520
      assert_select 'h2', :text => /@ deff712f/
521 522
    end

523
    def test_annotate_binary_file
524
      with_settings :default_language => 'en' do
525 526
        get :annotate, :params => {
            :id => PRJ_ID,
527
            :repository_id => @repository.id,
528
            :path => repository_path_hash(['images', 'edit.png'])[:param]
529
          }
530
        assert_response :success
531
        assert_select 'p#errorExplanation', :text => /cannot be annotated/
532
      end
533
    end
534

535 536
    def test_annotate_error_when_too_big
      with_settings :file_max_size_displayed => 1 do
537 538
        get :annotate, :params => {
            :id => PRJ_ID,
539
            :repository_id => @repository.id,
540 541
            :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
            :rev => 'deff712f'
542
          }
543
        assert_response :success
544
        assert_select 'p#errorExplanation', :text => /exceeds the maximum text file size/
545

546 547
        get :annotate, :params => {
            :id => PRJ_ID,
548
            :repository_id => @repository.id,
549 550
            :path => repository_path_hash(['README'])[:param],
            :rev => '7234cb2'
551
          }
552 553 554 555
        assert_response :success
      end
    end

556 557 558
    def test_annotate_latin_1
      if @ruby19_non_utf8_pass
        puts_ruby19_non_utf8_pass()
559 560
      elsif WINDOWS_PASS
        puts WINDOWS_SKIP_STR
561 562
      elsif JRUBY_SKIP
        puts JRUBY_SKIP_STR
563 564 565
      else
        with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
          ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
566 567
            get :annotate, :params => {
                :id => PRJ_ID,
568
              :repository_id => @repository.id,
569
              :path => repository_path_hash(['latin-1-dir', "test-Ü.txt"])[:param],
570 571
              :rev => r1
              }
572 573 574
            assert_select "th.line-num", :text => '1' do
              assert_select "+ td.revision" do
                assert_select "a", :text => '57ca437c'
575 576
                assert_select "+ td.author", :text => "jsmith" do
                  assert_select "+ td",
577
                                :text => "test-Ü.txt"
578
                end
579
              end
580
            end
581 582 583 584 585
          end
        end
      end
    end

586 587
    def test_annotate_latin_1_author
      ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
588 589
        get :annotate, :params => {
            :id => PRJ_ID,
590
            :repository_id => @repository.id,
591 592
            :path => repository_path_hash([" filename with a leading space.txt "])[:param],
            :rev => r1
593
          }
594 595 596
        assert_select "th.line-num", :text => '1' do
          assert_select "+ td.revision" do
            assert_select "a", :text => '83ca5fd5'
597
            assert_select "+ td.author", :text => "Felix Schäfer" do
598 599 600 601 602 603 604 605
              assert_select "+ td",
                            :text => "And this is a file with a leading and trailing space..."
            end
          end
        end
      end
    end

606 607 608 609 610
    def test_revisions
      assert_equal 0, @repository.changesets.count
      @repository.fetch_changesets
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
611
      get :revisions, :params => {
612 613
          :id => PRJ_ID,
          :repository_id => @repository.id
614
        }
615
      assert_select 'form[method=get][action=?]', "/projects/subproject1/repository/#{@repository.id}/revision"
616 617
    end

618
    def test_revision
619
      assert_equal 0, @repository.changesets.count
620
      @repository.fetch_changesets
621 622
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
623
      ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
624 625
        get :revision, :params => {
            :id => PRJ_ID,
626
            :repository_id => @repository.id,
627 628
            :rev => r
          }
629 630 631 632 633
        assert_response :success
      end
    end

    def test_empty_revision
634
      assert_equal 0, @repository.changesets.count
635
      @repository.fetch_changesets
636 637
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
638
      ['', ' ', nil].each do |r|
639 640
        get :revision, :params => {
            :id => PRJ_ID,
641
            :repository_id => @repository.id,
642 643
            :rev => r
          }
644
        assert_response 404
645
        assert_select_error /was not found/
646 647
      end
    end
648

649 650
    def test_destroy_valid_repository
      @request.session[:user_id] = 1 # admin
651
      assert_equal 0, @repository.changesets.count
652
      @repository.fetch_changesets
653 654
      @project.reload
      assert_equal NUM_REV, @repository.changesets.count
655

656
      assert_difference 'Repository.count', -1 do
657 658 659
        delete :destroy, :params => {
            :id => @repository.id
          }
660
      end
661 662 663 664 665
      assert_response 302
      @project.reload
      assert_nil @project.repository
    end

666 667
    def test_destroy_invalid_repository
      @request.session[:user_id] = 1 # admin
668 669
      @project.repository.destroy
      @repository = Repository::Git.create!(
670 671 672 673 674 675 676 677
                      :project       => @project,
                      :url           => "/invalid",
                      :path_encoding => 'ISO-8859-1'
                      )
      @repository.fetch_changesets
      @repository.reload
      assert_equal 0, @repository.changesets.count

678
      assert_difference 'Repository.count', -1 do
679 680 681
        delete :destroy, :params => {
            :id => @repository.id
          }
682
      end
683 684 685 686 687
      assert_response 302
      @project.reload
      assert_nil @project.repository
    end

688 689 690
    private

    def puts_ruby19_non_utf8_pass
691 692
      puts "TODO: This test fails " +
           "when Encoding.default_external is not UTF-8. " +
693 694
           "Current value is '#{Encoding.default_external.to_s}'"
    end
695 696 697 698
  else
    puts "Git test repository NOT FOUND. Skipping functional tests !!!"
    def test_fake; assert true end
  end
699 700 701 702 703 704 705 706

  private
  def with_cache(&block)
    before = ActionController::Base.perform_caching
    ActionController::Base.perform_caching = true
    block.call
    ActionController::Base.perform_caching = before
  end
707
end