You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repositories_cvs_controller_test.rb 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2014 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. require File.expand_path('../../test_helper', __FILE__)
  18. class RepositoriesCvsControllerTest < ActionController::TestCase
  19. tests RepositoriesController
  20. fixtures :projects, :users, :roles, :members, :member_roles,
  21. :repositories, :enabled_modules
  22. REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s
  23. REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
  24. # CVS module
  25. MODULE_NAME = 'test'
  26. PRJ_ID = 3
  27. NUM_REV = 7
  28. def setup
  29. Setting.default_language = 'en'
  30. User.current = nil
  31. @project = Project.find(PRJ_ID)
  32. @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
  33. :root_url => REPOSITORY_PATH,
  34. :url => MODULE_NAME,
  35. :log_encoding => 'UTF-8')
  36. assert @repository
  37. end
  38. if File.directory?(REPOSITORY_PATH)
  39. def test_get_new
  40. @request.session[:user_id] = 1
  41. @project.repository.destroy
  42. get :new, :project_id => 'subproject1', :repository_scm => 'Cvs'
  43. assert_response :success
  44. assert_template 'new'
  45. assert_kind_of Repository::Cvs, assigns(:repository)
  46. assert assigns(:repository).new_record?
  47. end
  48. def test_browse_root
  49. assert_equal 0, @repository.changesets.count
  50. @repository.fetch_changesets
  51. @project.reload
  52. assert_equal NUM_REV, @repository.changesets.count
  53. get :show, :id => PRJ_ID
  54. assert_response :success
  55. assert_template 'show'
  56. assert_not_nil assigns(:entries)
  57. assert_equal 3, assigns(:entries).size
  58. entry = assigns(:entries).detect {|e| e.name == 'images'}
  59. assert_equal 'dir', entry.kind
  60. entry = assigns(:entries).detect {|e| e.name == 'README'}
  61. assert_equal 'file', entry.kind
  62. assert_not_nil assigns(:changesets)
  63. assert assigns(:changesets).size > 0
  64. end
  65. def test_browse_directory
  66. assert_equal 0, @repository.changesets.count
  67. @repository.fetch_changesets
  68. @project.reload
  69. assert_equal NUM_REV, @repository.changesets.count
  70. get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
  71. assert_response :success
  72. assert_template 'show'
  73. assert_not_nil assigns(:entries)
  74. assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
  75. entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
  76. assert_not_nil entry
  77. assert_equal 'file', entry.kind
  78. assert_equal 'images/edit.png', entry.path
  79. end
  80. def test_browse_at_given_revision
  81. assert_equal 0, @repository.changesets.count
  82. @repository.fetch_changesets
  83. @project.reload
  84. assert_equal NUM_REV, @repository.changesets.count
  85. get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
  86. :rev => 1
  87. assert_response :success
  88. assert_template 'show'
  89. assert_not_nil assigns(:entries)
  90. assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
  91. end
  92. def test_entry
  93. assert_equal 0, @repository.changesets.count
  94. @repository.fetch_changesets
  95. @project.reload
  96. assert_equal NUM_REV, @repository.changesets.count
  97. get :entry, :id => PRJ_ID,
  98. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  99. assert_response :success
  100. assert_template 'entry'
  101. assert_no_tag :tag => 'td',
  102. :attributes => { :class => /line-code/},
  103. :content => /before_filter/
  104. end
  105. def test_entry_at_given_revision
  106. # changesets must be loaded
  107. assert_equal 0, @repository.changesets.count
  108. @repository.fetch_changesets
  109. @project.reload
  110. assert_equal NUM_REV, @repository.changesets.count
  111. get :entry, :id => PRJ_ID,
  112. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  113. :rev => 2
  114. assert_response :success
  115. assert_template 'entry'
  116. # this line was removed in r3
  117. assert_tag :tag => 'td',
  118. :attributes => { :class => /line-code/},
  119. :content => /before_filter/
  120. end
  121. def test_entry_not_found
  122. assert_equal 0, @repository.changesets.count
  123. @repository.fetch_changesets
  124. @project.reload
  125. assert_equal NUM_REV, @repository.changesets.count
  126. get :entry, :id => PRJ_ID,
  127. :path => repository_path_hash(['sources', 'zzz.c'])[:param]
  128. assert_tag :tag => 'p',
  129. :attributes => { :id => /errorExplanation/ },
  130. :content => /The entry or revision was not found in the repository/
  131. end
  132. def test_entry_download
  133. assert_equal 0, @repository.changesets.count
  134. @repository.fetch_changesets
  135. @project.reload
  136. assert_equal NUM_REV, @repository.changesets.count
  137. get :entry, :id => PRJ_ID,
  138. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  139. :format => 'raw'
  140. assert_response :success
  141. end
  142. def test_directory_entry
  143. assert_equal 0, @repository.changesets.count
  144. @repository.fetch_changesets
  145. @project.reload
  146. assert_equal NUM_REV, @repository.changesets.count
  147. get :entry, :id => PRJ_ID,
  148. :path => repository_path_hash(['sources'])[:param]
  149. assert_response :success
  150. assert_template 'show'
  151. assert_not_nil assigns(:entry)
  152. assert_equal 'sources', assigns(:entry).name
  153. end
  154. def test_diff
  155. assert_equal 0, @repository.changesets.count
  156. @repository.fetch_changesets
  157. @project.reload
  158. assert_equal NUM_REV, @repository.changesets.count
  159. ['inline', 'sbs'].each do |dt|
  160. get :diff, :id => PRJ_ID, :rev => 3, :type => dt
  161. assert_response :success
  162. assert_template 'diff'
  163. assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_out' },
  164. :content => /before_filter :require_login/
  165. assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
  166. :content => /with one change/
  167. end
  168. end
  169. def test_diff_new_files
  170. assert_equal 0, @repository.changesets.count
  171. @repository.fetch_changesets
  172. @project.reload
  173. assert_equal NUM_REV, @repository.changesets.count
  174. ['inline', 'sbs'].each do |dt|
  175. get :diff, :id => PRJ_ID, :rev => 1, :type => dt
  176. assert_response :success
  177. assert_template 'diff'
  178. assert_tag :tag => 'td', :attributes => { :class => 'line-code diff_in' },
  179. :content => /watched.remove_watcher/
  180. assert_tag :tag => 'th', :attributes => { :class => 'filename' },
  181. :content => /test\/README/
  182. assert_tag :tag => 'th', :attributes => { :class => 'filename' },
  183. :content => /test\/images\/delete.png /
  184. assert_tag :tag => 'th', :attributes => { :class => 'filename' },
  185. :content => /test\/images\/edit.png/
  186. assert_tag :tag => 'th', :attributes => { :class => 'filename' },
  187. :content => /test\/sources\/watchers_controller.rb/
  188. end
  189. end
  190. def test_annotate
  191. assert_equal 0, @repository.changesets.count
  192. @repository.fetch_changesets
  193. @project.reload
  194. assert_equal NUM_REV, @repository.changesets.count
  195. get :annotate, :id => PRJ_ID,
  196. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  197. assert_response :success
  198. assert_template 'annotate'
  199. # 1.1 line
  200. assert_select 'tr' do
  201. assert_select 'th.line-num', :text => '21'
  202. assert_select 'td.revision', :text => /1.1/
  203. assert_select 'td.author', :text => /LANG/
  204. end
  205. # 1.2 line
  206. assert_select 'tr' do
  207. assert_select 'th.line-num', :text => '32'
  208. assert_select 'td.revision', :text => /1.2/
  209. assert_select 'td.author', :text => /LANG/
  210. end
  211. end
  212. def test_destroy_valid_repository
  213. @request.session[:user_id] = 1 # admin
  214. assert_equal 0, @repository.changesets.count
  215. @repository.fetch_changesets
  216. @project.reload
  217. assert_equal NUM_REV, @repository.changesets.count
  218. assert_difference 'Repository.count', -1 do
  219. delete :destroy, :id => @repository.id
  220. end
  221. assert_response 302
  222. @project.reload
  223. assert_nil @project.repository
  224. end
  225. def test_destroy_invalid_repository
  226. @request.session[:user_id] = 1 # admin
  227. @project.repository.destroy
  228. @repository = Repository::Cvs.create!(
  229. :project => Project.find(PRJ_ID),
  230. :root_url => "/invalid",
  231. :url => MODULE_NAME,
  232. :log_encoding => 'UTF-8'
  233. )
  234. @repository.fetch_changesets
  235. @project.reload
  236. assert_equal 0, @repository.changesets.count
  237. assert_difference 'Repository.count', -1 do
  238. delete :destroy, :id => @repository.id
  239. end
  240. assert_response 302
  241. @project.reload
  242. assert_nil @project.repository
  243. end
  244. else
  245. puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
  246. def test_fake; assert true end
  247. end
  248. end