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