annotate test/functional/repositories_subversion_controller_test.rb @ 8:0c83d98252d9 yuya

* Add custom repo prefix and proper auth realm, remove auth cache (seems like an unwise feature), pass DB handle around, various other bits of tidying
author Chris Cannam
date Thu, 12 Aug 2010 15:31:37 +0100
parents 513646585e45
children 94944d00e43c
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@0 18 require File.dirname(__FILE__) + '/../test_helper'
Chris@0 19 require 'repositories_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class RepositoriesSubversionControllerTest < ActionController::TestCase
Chris@0 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
Chris@0 26 :repositories, :issues, :issue_statuses, :changesets, :changes,
Chris@0 27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
Chris@0 28
Chris@0 29 def setup
Chris@0 30 @controller = RepositoriesController.new
Chris@0 31 @request = ActionController::TestRequest.new
Chris@0 32 @response = ActionController::TestResponse.new
Chris@0 33 Setting.default_language = 'en'
Chris@0 34 User.current = nil
Chris@0 35 end
Chris@0 36
Chris@0 37 if repository_configured?('subversion')
Chris@0 38 def test_show
Chris@0 39 get :show, :id => 1
Chris@0 40 assert_response :success
Chris@0 41 assert_template 'show'
Chris@0 42 assert_not_nil assigns(:entries)
Chris@0 43 assert_not_nil assigns(:changesets)
Chris@0 44 end
Chris@0 45
Chris@0 46 def test_browse_root
Chris@0 47 get :show, :id => 1
Chris@0 48 assert_response :success
Chris@0 49 assert_template 'show'
Chris@0 50 assert_not_nil assigns(:entries)
Chris@0 51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
Chris@0 52 assert_equal 'dir', entry.kind
Chris@0 53 end
Chris@0 54
Chris@0 55 def test_browse_directory
Chris@0 56 get :show, :id => 1, :path => ['subversion_test']
Chris@0 57 assert_response :success
Chris@0 58 assert_template 'show'
Chris@0 59 assert_not_nil assigns(:entries)
Chris@0 60 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
Chris@0 61 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
Chris@0 62 assert_equal 'file', entry.kind
Chris@0 63 assert_equal 'subversion_test/helloworld.c', entry.path
Chris@0 64 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
Chris@0 65 end
Chris@0 66
Chris@0 67 def test_browse_at_given_revision
Chris@0 68 get :show, :id => 1, :path => ['subversion_test'], :rev => 4
Chris@0 69 assert_response :success
Chris@0 70 assert_template 'show'
Chris@0 71 assert_not_nil assigns(:entries)
Chris@0 72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
Chris@0 73 end
Chris@0 74
Chris@0 75 def test_file_changes
Chris@0 76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
Chris@0 77 assert_response :success
Chris@0 78 assert_template 'changes'
Chris@0 79
Chris@0 80 changesets = assigns(:changesets)
Chris@0 81 assert_not_nil changesets
Chris@0 82 assert_equal %w(6 3 2), changesets.collect(&:revision)
Chris@0 83
Chris@0 84 # svn properties displayed with svn >= 1.5 only
Chris@0 85 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
Chris@0 86 assert_not_nil assigns(:properties)
Chris@0 87 assert_equal 'native', assigns(:properties)['svn:eol-style']
Chris@0 88 assert_tag :ul,
Chris@0 89 :child => { :tag => 'li',
Chris@0 90 :child => { :tag => 'b', :content => 'svn:eol-style' },
Chris@0 91 :child => { :tag => 'span', :content => 'native' } }
Chris@0 92 end
Chris@0 93 end
Chris@0 94
Chris@0 95 def test_directory_changes
Chris@0 96 get :changes, :id => 1, :path => ['subversion_test', 'folder' ]
Chris@0 97 assert_response :success
Chris@0 98 assert_template 'changes'
Chris@0 99
Chris@0 100 changesets = assigns(:changesets)
Chris@0 101 assert_not_nil changesets
Chris@0 102 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
Chris@0 103 end
Chris@0 104
Chris@0 105 def test_entry
Chris@0 106 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
Chris@0 107 assert_response :success
Chris@0 108 assert_template 'entry'
Chris@0 109 end
Chris@0 110
Chris@0 111 def test_entry_should_send_if_too_big
Chris@0 112 # no files in the test repo is larger than 1KB...
Chris@0 113 with_settings :file_max_size_displayed => 0 do
Chris@0 114 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c']
Chris@0 115 assert_response :success
Chris@0 116 assert_template ''
Chris@0 117 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
Chris@0 118 end
Chris@0 119 end
Chris@0 120
Chris@0 121 def test_entry_at_given_revision
Chris@0 122 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
Chris@0 123 assert_response :success
Chris@0 124 assert_template 'entry'
Chris@0 125 # this line was removed in r3 and file was moved in r6
Chris@0 126 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
Chris@0 127 :content => /Here's the code/
Chris@0 128 end
Chris@0 129
Chris@0 130 def test_entry_not_found
Chris@0 131 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c']
Chris@0 132 assert_tag :tag => 'div', :attributes => { :class => /error/ },
Chris@0 133 :content => /The entry or revision was not found in the repository/
Chris@0 134 end
Chris@0 135
Chris@0 136 def test_entry_download
Chris@0 137 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
Chris@0 138 assert_response :success
Chris@0 139 assert_template ''
Chris@0 140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
Chris@0 141 end
Chris@0 142
Chris@0 143 def test_directory_entry
Chris@0 144 get :entry, :id => 1, :path => ['subversion_test', 'folder']
Chris@0 145 assert_response :success
Chris@0 146 assert_template 'show'
Chris@0 147 assert_not_nil assigns(:entry)
Chris@0 148 assert_equal 'folder', assigns(:entry).name
Chris@0 149 end
Chris@0 150
Chris@0 151 def test_revision
Chris@0 152 get :revision, :id => 1, :rev => 2
Chris@0 153 assert_response :success
Chris@0 154 assert_template 'revision'
Chris@0 155 assert_tag :tag => 'ul',
Chris@0 156 :child => { :tag => 'li',
Chris@0 157 # link to the entry at rev 2
Chris@0 158 :child => { :tag => 'a',
Chris@0 159 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
Chris@0 160 :content => 'repo',
Chris@0 161 # link to partial diff
Chris@0 162 :sibling => { :tag => 'a',
Chris@0 163 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
Chris@0 164 }
Chris@0 165 }
Chris@0 166 }
Chris@0 167 end
Chris@0 168
Chris@0 169 def test_revision_with_repository_pointing_to_a_subdirectory
Chris@0 170 r = Project.find(1).repository
Chris@0 171 # Changes repository url to a subdirectory
Chris@0 172 r.update_attribute :url, (r.url + '/test/some')
Chris@0 173
Chris@0 174 get :revision, :id => 1, :rev => 2
Chris@0 175 assert_response :success
Chris@0 176 assert_template 'revision'
Chris@0 177 assert_tag :tag => 'ul',
Chris@0 178 :child => { :tag => 'li',
Chris@0 179 # link to the entry at rev 2
Chris@0 180 :child => { :tag => 'a',
Chris@0 181 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
Chris@0 182 :content => 'repo',
Chris@0 183 # link to partial diff
Chris@0 184 :sibling => { :tag => 'a',
Chris@0 185 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
Chris@0 186 }
Chris@0 187 }
Chris@0 188 }
Chris@0 189 end
Chris@0 190
Chris@0 191 def test_revision_diff
Chris@0 192 get :diff, :id => 1, :rev => 3
Chris@0 193 assert_response :success
Chris@0 194 assert_template 'diff'
Chris@0 195 end
Chris@0 196
Chris@0 197 def test_directory_diff
Chris@0 198 get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
Chris@0 199 assert_response :success
Chris@0 200 assert_template 'diff'
Chris@0 201
Chris@0 202 diff = assigns(:diff)
Chris@0 203 assert_not_nil diff
Chris@0 204 # 2 files modified
Chris@0 205 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
Chris@0 206 end
Chris@0 207
Chris@0 208 def test_annotate
Chris@0 209 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c']
Chris@0 210 assert_response :success
Chris@0 211 assert_template 'annotate'
Chris@0 212 end
Chris@0 213 else
Chris@0 214 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 215 def test_fake; assert true end
Chris@0 216 end
Chris@0 217 end