Chris@1517: # Redmine - project management software Chris@1517: # Copyright (C) 2006-2014 Jean-Philippe Lang Chris@1517: # Chris@1517: # This program is free software; you can redistribute it and/or Chris@1517: # modify it under the terms of the GNU General Public License Chris@1517: # as published by the Free Software Foundation; either version 2 Chris@1517: # of the License, or (at your option) any later version. Chris@1517: # Chris@1517: # This program is distributed in the hope that it will be useful, Chris@1517: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1517: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1517: # GNU General Public License for more details. Chris@1517: # Chris@1517: # You should have received a copy of the GNU General Public License Chris@1517: # along with this program; if not, write to the Free Software Chris@1517: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1517: Chris@1517: require File.expand_path('../../test_helper', __FILE__) Chris@1517: Chris@1517: class RepositoriesGitControllerTest < ActionController::TestCase Chris@1517: tests RepositoriesController Chris@1517: Chris@1517: fixtures :projects, :users, :roles, :members, :member_roles, Chris@1517: :repositories, :enabled_modules Chris@1517: Chris@1517: REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s Chris@1517: REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? Chris@1517: PRJ_ID = 3 Chris@1517: CHAR_1_HEX = "\xc3\x9c" Chris@1517: FELIX_HEX = "Felix Sch\xC3\xA4fer" Chris@1517: NUM_REV = 28 Chris@1517: Chris@1517: ## Git, Mercurial and CVS path encodings are binary. Chris@1517: ## Subversion supports URL encoding for path. Chris@1517: ## Redmine Mercurial adapter and extension use URL encoding. Chris@1517: ## Git accepts only binary path in command line parameter. Chris@1517: ## So, there is no way to use binary command line parameter in JRuby. Chris@1517: JRUBY_SKIP = (RUBY_PLATFORM == 'java') Chris@1517: JRUBY_SKIP_STR = "TODO: This test fails in JRuby" Chris@1517: Chris@1517: def setup Chris@1517: @ruby19_non_utf8_pass = Chris@1517: (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') Chris@1517: Chris@1517: User.current = nil Chris@1517: @project = Project.find(PRJ_ID) Chris@1517: @repository = Repository::Git.create( Chris@1517: :project => @project, Chris@1517: :url => REPOSITORY_PATH, Chris@1517: :path_encoding => 'ISO-8859-1' Chris@1517: ) Chris@1517: assert @repository Chris@1517: @char_1 = CHAR_1_HEX.dup Chris@1517: @felix_utf8 = FELIX_HEX.dup Chris@1517: if @char_1.respond_to?(:force_encoding) Chris@1517: @char_1.force_encoding('UTF-8') Chris@1517: @felix_utf8.force_encoding('UTF-8') Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_create_and_update Chris@1517: @request.session[:user_id] = 1 Chris@1517: assert_difference 'Repository.count' do Chris@1517: post :create, :project_id => 'subproject1', Chris@1517: :repository_scm => 'Git', Chris@1517: :repository => { Chris@1517: :url => '/test', Chris@1517: :is_default => '0', Chris@1517: :identifier => 'test-create', Chris@1517: :extra_report_last_commit => '1', Chris@1517: } Chris@1517: end Chris@1517: assert_response 302 Chris@1517: repository = Repository.order('id DESC').first Chris@1517: assert_kind_of Repository::Git, repository Chris@1517: assert_equal '/test', repository.url Chris@1517: assert_equal true, repository.extra_report_last_commit Chris@1517: Chris@1517: put :update, :id => repository.id, Chris@1517: :repository => { Chris@1517: :extra_report_last_commit => '0' Chris@1517: } Chris@1517: assert_response 302 Chris@1517: repo2 = Repository.find(repository.id) Chris@1517: assert_equal false, repo2.extra_report_last_commit Chris@1517: end Chris@1517: Chris@1517: if File.directory?(REPOSITORY_PATH) Chris@1517: ## Ruby uses ANSI api to fork a process on Windows. Chris@1517: ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem Chris@1517: ## and these are incompatible with ASCII. Chris@1517: ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10 Chris@1517: ## http://code.google.com/p/msysgit/issues/detail?id=80 Chris@1517: ## So, Latin-1 path tests fail on Japanese Windows Chris@1517: WINDOWS_PASS = (Redmine::Platform.mswin? && Chris@1517: Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10])) Chris@1517: WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10" Chris@1517: Chris@1517: def test_get_new Chris@1517: @request.session[:user_id] = 1 Chris@1517: @project.repository.destroy Chris@1517: get :new, :project_id => 'subproject1', :repository_scm => 'Git' Chris@1517: assert_response :success Chris@1517: assert_template 'new' Chris@1517: assert_kind_of Repository::Git, assigns(:repository) Chris@1517: assert assigns(:repository).new_record? Chris@1517: end Chris@1517: Chris@1517: def test_browse_root Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: Chris@1517: get :show, :id => PRJ_ID Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entries) Chris@1517: assert_equal 9, assigns(:entries).size Chris@1517: assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} Chris@1517: assert_not_nil assigns(:changesets) Chris@1517: assert assigns(:changesets).size > 0 Chris@1517: end Chris@1517: Chris@1517: def test_browse_branch Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: get :show, :id => PRJ_ID, :rev => 'test_branch' Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entries) Chris@1517: assert_equal 4, assigns(:entries).size Chris@1517: assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} Chris@1517: assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} Chris@1517: assert_not_nil assigns(:changesets) Chris@1517: assert assigns(:changesets).size > 0 Chris@1517: end Chris@1517: Chris@1517: def test_browse_tag Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: [ Chris@1517: "tag00.lightweight", Chris@1517: "tag01.annotated", Chris@1517: ].each do |t1| Chris@1517: get :show, :id => PRJ_ID, :rev => t1 Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entries) Chris@1517: assert assigns(:entries).size > 0 Chris@1517: assert_not_nil assigns(:changesets) Chris@1517: assert assigns(:changesets).size > 0 Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_browse_directory Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entries) Chris@1517: assert_equal ['edit.png'], assigns(:entries).collect(&:name) Chris@1517: entry = assigns(:entries).detect {|e| e.name == 'edit.png'} Chris@1517: assert_not_nil entry Chris@1517: assert_equal 'file', entry.kind Chris@1517: assert_equal 'images/edit.png', entry.path Chris@1517: assert_not_nil assigns(:changesets) Chris@1517: assert assigns(:changesets).size > 0 Chris@1517: end Chris@1517: Chris@1517: def test_browse_at_given_revision Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], Chris@1517: :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entries) Chris@1517: assert_equal ['delete.png'], assigns(:entries).collect(&:name) Chris@1517: assert_not_nil assigns(:changesets) Chris@1517: assert assigns(:changesets).size > 0 Chris@1517: end Chris@1517: Chris@1517: def test_changes Chris@1517: get :changes, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['images', 'edit.png'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'changes' Chris@1517: assert_tag :tag => 'h2', :content => 'edit.png' Chris@1517: end Chris@1517: Chris@1517: def test_entry_show Chris@1517: get :entry, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'entry' Chris@1517: # Line 19 Chris@1517: assert_tag :tag => 'th', Chris@1517: :content => '11', Chris@1517: :attributes => { :class => 'line-num' }, Chris@1517: :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } Chris@1517: end Chris@1517: Chris@1517: def test_entry_show_latin_1 Chris@1517: if @ruby19_non_utf8_pass Chris@1517: puts_ruby19_non_utf8_pass() Chris@1517: elsif WINDOWS_PASS Chris@1517: puts WINDOWS_SKIP_STR Chris@1517: elsif JRUBY_SKIP Chris@1517: puts JRUBY_SKIP_STR Chris@1517: else Chris@1517: with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do Chris@1517: ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| Chris@1517: get :entry, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], Chris@1517: :rev => r1 Chris@1517: assert_response :success Chris@1517: assert_template 'entry' Chris@1517: assert_tag :tag => 'th', Chris@1517: :content => '1', Chris@1517: :attributes => { :class => 'line-num' }, Chris@1517: :sibling => { :tag => 'td', Chris@1517: :content => /test-#{@char_1}.txt/ } Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_entry_download Chris@1517: get :entry, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], Chris@1517: :format => 'raw' Chris@1517: assert_response :success Chris@1517: # File content Chris@1517: assert @response.body.include?('WITHOUT ANY WARRANTY') Chris@1517: end Chris@1517: Chris@1517: def test_directory_entry Chris@1517: get :entry, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['sources'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'show' Chris@1517: assert_not_nil assigns(:entry) Chris@1517: assert_equal 'sources', assigns(:entry).name Chris@1517: end Chris@1517: Chris@1517: def test_diff Chris@1517: assert_equal true, @repository.is_default Chris@1517: assert_nil @repository.identifier Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: # Full diff of changeset 2f9c0091 Chris@1517: ['inline', 'sbs'].each do |dt| Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', Chris@1517: :type => dt Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: # Line 22 removed Chris@1517: assert_tag :tag => 'th', Chris@1517: :content => /22/, Chris@1517: :sibling => { :tag => 'td', Chris@1517: :attributes => { :class => /diff_out/ }, Chris@1517: :content => /def remove/ } Chris@1517: assert_tag :tag => 'h2', :content => /2f9c0091/ Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_diff_with_rev_and_path Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: with_settings :diff_max_lines_displayed => 1000 do Chris@1517: # Full diff of changeset 2f9c0091 Chris@1517: ['inline', 'sbs'].each do |dt| Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], Chris@1517: :type => dt Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: # Line 22 removed Chris@1517: assert_tag :tag => 'th', Chris@1517: :content => '22', Chris@1517: :sibling => { :tag => 'td', Chris@1517: :attributes => { :class => /diff_out/ }, Chris@1517: :content => /def remove/ } Chris@1517: assert_tag :tag => 'h2', :content => /2f9c0091/ Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_diff_truncated Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: Chris@1517: with_settings :diff_max_lines_displayed => 5 do Chris@1517: # Truncated diff of changeset 2f9c0091 Chris@1517: with_cache do Chris@1517: with_settings :default_language => 'en' do Chris@1517: get :diff, :id => PRJ_ID, :type => 'inline', Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' Chris@1517: assert_response :success Chris@1517: assert @response.body.include?("... This diff was truncated") Chris@1517: end Chris@1517: with_settings :default_language => 'fr' do Chris@1517: get :diff, :id => PRJ_ID, :type => 'inline', Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' Chris@1517: assert_response :success Chris@1517: assert ! @response.body.include?("... This diff was truncated") Chris@1517: assert @response.body.include?("... Ce diff") Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_diff_two_revs Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: ['inline', 'sbs'].each do |dt| Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', Chris@1517: :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', Chris@1517: :type => dt Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: diff = assigns(:diff) Chris@1517: assert_not_nil diff Chris@1517: assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ Chris@1517: assert_tag :tag => "form", Chris@1517: :attributes => { Chris@1517: :action => "/projects/subproject1/repository/revisions/" + Chris@1517: "61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff" Chris@1517: } Chris@1517: assert_tag :tag => 'input', Chris@1517: :attributes => { Chris@1517: :id => "rev_to", Chris@1517: :name => "rev_to", Chris@1517: :type => "hidden", Chris@1517: :value => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' Chris@1517: } Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_diff_path_in_subrepo Chris@1517: repo = Repository::Git.create( Chris@1517: :project => @project, Chris@1517: :url => REPOSITORY_PATH, Chris@1517: :identifier => 'test-diff-path', Chris@1517: :path_encoding => 'ISO-8859-1' Chris@1517: ); Chris@1517: assert repo Chris@1517: assert_equal false, repo.is_default Chris@1517: assert_equal 'test-diff-path', repo.identifier Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :repository_id => 'test-diff-path', Chris@1517: :rev => '61b685fbe55ab05b', Chris@1517: :rev_to => '2f9c0091c754a91a', Chris@1517: :type => 'inline' Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: diff = assigns(:diff) Chris@1517: assert_not_nil diff Chris@1517: assert_tag :tag => "form", Chris@1517: :attributes => { Chris@1517: :action => "/projects/subproject1/repository/test-diff-path/" + Chris@1517: "revisions/61b685fbe55ab05b/diff" Chris@1517: } Chris@1517: assert_tag :tag => 'input', Chris@1517: :attributes => { Chris@1517: :id => "rev_to", Chris@1517: :name => "rev_to", Chris@1517: :type => "hidden", Chris@1517: :value => '2f9c0091c754a91a' Chris@1517: } Chris@1517: end Chris@1517: Chris@1517: def test_diff_latin_1 Chris@1517: if @ruby19_non_utf8_pass Chris@1517: puts_ruby19_non_utf8_pass() Chris@1517: else Chris@1517: with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do Chris@1517: ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| Chris@1517: ['inline', 'sbs'].each do |dt| Chris@1517: get :diff, :id => PRJ_ID, :rev => r1, :type => dt Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: assert_tag :tag => 'thead', Chris@1517: :descendant => { Chris@1517: :tag => 'th', Chris@1517: :attributes => { :class => 'filename' } , Chris@1517: :content => /latin-1-dir\/test-#{@char_1}.txt/ , Chris@1517: }, Chris@1517: :sibling => { Chris@1517: :tag => 'tbody', Chris@1517: :descendant => { Chris@1517: :tag => 'td', Chris@1517: :attributes => { :class => /diff_in/ }, Chris@1517: :content => /test-#{@char_1}.txt/ Chris@1517: } Chris@1517: } Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_diff_should_show_filenames Chris@1517: get :diff, :id => PRJ_ID, :rev => 'deff712f05a90d96edbd70facc47d944be5897e3', :type => 'inline' Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: # modified file Chris@1517: assert_select 'th.filename', :text => 'sources/watchers_controller.rb' Chris@1517: # deleted file Chris@1517: assert_select 'th.filename', :text => 'test.txt' Chris@1517: end Chris@1517: Chris@1517: def test_save_diff_type Chris@1517: user1 = User.find(1) Chris@1517: user1.pref[:diff_type] = nil Chris@1517: user1.preference.save Chris@1517: user = User.find(1) Chris@1517: assert_nil user.pref[:diff_type] Chris@1517: Chris@1517: @request.session[:user_id] = 1 # admin Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: user.reload Chris@1517: assert_equal "inline", user.pref[:diff_type] Chris@1517: get :diff, Chris@1517: :id => PRJ_ID, Chris@1517: :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7', Chris@1517: :type => 'sbs' Chris@1517: assert_response :success Chris@1517: assert_template 'diff' Chris@1517: user.reload Chris@1517: assert_equal "sbs", user.pref[:diff_type] Chris@1517: end Chris@1517: Chris@1517: def test_annotate Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'annotate' Chris@1517: Chris@1517: # Line 23, changeset 2f9c0091 Chris@1517: assert_select 'tr' do Chris@1517: assert_select 'th.line-num', :text => '23' Chris@1517: assert_select 'td.revision', :text => /2f9c0091/ Chris@1517: assert_select 'td.author', :text => 'jsmith' Chris@1517: assert_select 'td', :text => /remove_watcher/ Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_annotate_at_given_revision Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: get :annotate, :id => PRJ_ID, :rev => 'deff7', Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] Chris@1517: assert_response :success Chris@1517: assert_template 'annotate' Chris@1517: assert_tag :tag => 'h2', :content => /@ deff712f/ Chris@1517: end Chris@1517: Chris@1517: def test_annotate_binary_file Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['images', 'edit.png'])[:param] Chris@1517: assert_response 500 Chris@1517: assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, Chris@1517: :content => /cannot be annotated/ Chris@1517: end Chris@1517: Chris@1517: def test_annotate_error_when_too_big Chris@1517: with_settings :file_max_size_displayed => 1 do Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], Chris@1517: :rev => 'deff712f' Chris@1517: assert_response 500 Chris@1517: assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, Chris@1517: :content => /exceeds the maximum text file size/ Chris@1517: Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['README'])[:param], Chris@1517: :rev => '7234cb2' Chris@1517: assert_response :success Chris@1517: assert_template 'annotate' Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_annotate_latin_1 Chris@1517: if @ruby19_non_utf8_pass Chris@1517: puts_ruby19_non_utf8_pass() Chris@1517: elsif WINDOWS_PASS Chris@1517: puts WINDOWS_SKIP_STR Chris@1517: elsif JRUBY_SKIP Chris@1517: puts JRUBY_SKIP_STR Chris@1517: else Chris@1517: with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do Chris@1517: ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], Chris@1517: :rev => r1 Chris@1517: assert_select "th.line-num", :text => '1' do Chris@1517: assert_select "+ td.revision" do Chris@1517: assert_select "a", :text => '57ca437c' Chris@1517: assert_select "+ td.author", :text => "jsmith" do Chris@1517: assert_select "+ td", Chris@1517: :text => "test-#{@char_1}.txt" Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_annotate_latin_1_author Chris@1517: ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1| Chris@1517: get :annotate, :id => PRJ_ID, Chris@1517: :path => repository_path_hash([" filename with a leading space.txt "])[:param], Chris@1517: :rev => r1 Chris@1517: assert_select "th.line-num", :text => '1' do Chris@1517: assert_select "+ td.revision" do Chris@1517: assert_select "a", :text => '83ca5fd5' Chris@1517: assert_select "+ td.author", :text => @felix_utf8 do Chris@1517: assert_select "+ td", Chris@1517: :text => "And this is a file with a leading and trailing space..." Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_revisions Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: get :revisions, :id => PRJ_ID Chris@1517: assert_response :success Chris@1517: assert_template 'revisions' Chris@1517: assert_tag :tag => 'form', Chris@1517: :attributes => { Chris@1517: :method => 'get', Chris@1517: :action => '/projects/subproject1/repository/revision' Chris@1517: } Chris@1517: end Chris@1517: Chris@1517: def test_revision Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| Chris@1517: get :revision, :id => PRJ_ID, :rev => r Chris@1517: assert_response :success Chris@1517: assert_template 'revision' Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_empty_revision Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: ['', ' ', nil].each do |r| Chris@1517: get :revision, :id => PRJ_ID, :rev => r Chris@1517: assert_response 404 Chris@1517: assert_error_tag :content => /was not found/ Chris@1517: end Chris@1517: end Chris@1517: Chris@1517: def test_destroy_valid_repository Chris@1517: @request.session[:user_id] = 1 # admin Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: @repository.fetch_changesets Chris@1517: @project.reload Chris@1517: assert_equal NUM_REV, @repository.changesets.count Chris@1517: Chris@1517: assert_difference 'Repository.count', -1 do Chris@1517: delete :destroy, :id => @repository.id Chris@1517: end Chris@1517: assert_response 302 Chris@1517: @project.reload Chris@1517: assert_nil @project.repository Chris@1517: end Chris@1517: Chris@1517: def test_destroy_invalid_repository Chris@1517: @request.session[:user_id] = 1 # admin Chris@1517: @project.repository.destroy Chris@1517: @repository = Repository::Git.create!( Chris@1517: :project => @project, Chris@1517: :url => "/invalid", Chris@1517: :path_encoding => 'ISO-8859-1' Chris@1517: ) Chris@1517: @repository.fetch_changesets Chris@1517: @repository.reload Chris@1517: assert_equal 0, @repository.changesets.count Chris@1517: Chris@1517: assert_difference 'Repository.count', -1 do Chris@1517: delete :destroy, :id => @repository.id Chris@1517: end Chris@1517: assert_response 302 Chris@1517: @project.reload Chris@1517: assert_nil @project.repository Chris@1517: end Chris@1517: Chris@1517: private Chris@1517: Chris@1517: def puts_ruby19_non_utf8_pass Chris@1517: puts "TODO: This test fails in Ruby 1.9 " + Chris@1517: "and Encoding.default_external is not UTF-8. " + Chris@1517: "Current value is '#{Encoding.default_external.to_s}'" Chris@1517: end Chris@1517: else Chris@1517: puts "Git test repository NOT FOUND. Skipping functional tests !!!" Chris@1517: def test_fake; assert true end Chris@1517: end Chris@1517: Chris@1517: private Chris@1517: def with_cache(&block) Chris@1517: before = ActionController::Base.perform_caching Chris@1517: ActionController::Base.perform_caching = true Chris@1517: block.call Chris@1517: ActionController::Base.perform_caching = before Chris@1517: end Chris@1517: end