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