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 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2015 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, :email_addresses, :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_select 'td.line-code', :text => /before_filter/, :count => 0
  102. end
  103. def test_entry_at_given_revision
  104. # changesets must be loaded
  105. assert_equal 0, @repository.changesets.count
  106. @repository.fetch_changesets
  107. @project.reload
  108. assert_equal NUM_REV, @repository.changesets.count
  109. get :entry, :id => PRJ_ID,
  110. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  111. :rev => 2
  112. assert_response :success
  113. assert_template 'entry'
  114. # this line was removed in r3
  115. assert_select 'td.line-code', :text => /before_filter/
  116. end
  117. def test_entry_not_found
  118. assert_equal 0, @repository.changesets.count
  119. @repository.fetch_changesets
  120. @project.reload
  121. assert_equal NUM_REV, @repository.changesets.count
  122. get :entry, :id => PRJ_ID,
  123. :path => repository_path_hash(['sources', 'zzz.c'])[:param]
  124. assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
  125. end
  126. def test_entry_download
  127. assert_equal 0, @repository.changesets.count
  128. @repository.fetch_changesets
  129. @project.reload
  130. assert_equal NUM_REV, @repository.changesets.count
  131. get :entry, :id => PRJ_ID,
  132. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
  133. :format => 'raw'
  134. assert_response :success
  135. end
  136. def test_directory_entry
  137. assert_equal 0, @repository.changesets.count
  138. @repository.fetch_changesets
  139. @project.reload
  140. assert_equal NUM_REV, @repository.changesets.count
  141. get :entry, :id => PRJ_ID,
  142. :path => repository_path_hash(['sources'])[:param]
  143. assert_response :success
  144. assert_template 'show'
  145. assert_not_nil assigns(:entry)
  146. assert_equal 'sources', assigns(:entry).name
  147. end
  148. def test_diff
  149. assert_equal 0, @repository.changesets.count
  150. @repository.fetch_changesets
  151. @project.reload
  152. assert_equal NUM_REV, @repository.changesets.count
  153. ['inline', 'sbs'].each do |dt|
  154. get :diff, :id => PRJ_ID, :rev => 3, :type => dt
  155. assert_response :success
  156. assert_template 'diff'
  157. assert_select 'td.line-code.diff_out', :text => /before_filter :require_login/
  158. assert_select 'td.line-code.diff_in', :text => /with one change/
  159. end
  160. end
  161. def test_diff_new_files
  162. assert_equal 0, @repository.changesets.count
  163. @repository.fetch_changesets
  164. @project.reload
  165. assert_equal NUM_REV, @repository.changesets.count
  166. ['inline', 'sbs'].each do |dt|
  167. get :diff, :id => PRJ_ID, :rev => 1, :type => dt
  168. assert_response :success
  169. assert_template 'diff'
  170. assert_select 'td.line-code.diff_in', :text => /watched.remove_watcher/
  171. assert_select 'th.filename', :text => /test\/README/
  172. assert_select 'th.filename', :text => /test\/images\/delete.png/
  173. assert_select 'th.filename', :text => /test\/images\/edit.png/
  174. assert_select 'th.filename', :text => /test\/sources\/watchers_controller.rb/
  175. end
  176. end
  177. def test_annotate
  178. assert_equal 0, @repository.changesets.count
  179. @repository.fetch_changesets
  180. @project.reload
  181. assert_equal NUM_REV, @repository.changesets.count
  182. get :annotate, :id => PRJ_ID,
  183. :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
  184. assert_response :success
  185. assert_template 'annotate'
  186. # 1.1 line
  187. assert_select 'tr' do
  188. assert_select 'th.line-num', :text => '21'
  189. assert_select 'td.revision', :text => /1.1/
  190. assert_select 'td.author', :text => /LANG/
  191. end
  192. # 1.2 line
  193. assert_select 'tr' do
  194. assert_select 'th.line-num', :text => '32'
  195. assert_select 'td.revision', :text => /1.2/
  196. assert_select 'td.author', :text => /LANG/
  197. end
  198. end
  199. def test_destroy_valid_repository
  200. @request.session[:user_id] = 1 # admin
  201. assert_equal 0, @repository.changesets.count
  202. @repository.fetch_changesets
  203. @project.reload
  204. assert_equal NUM_REV, @repository.changesets.count
  205. assert_difference 'Repository.count', -1 do
  206. delete :destroy, :id => @repository.id
  207. end
  208. assert_response 302
  209. @project.reload
  210. assert_nil @project.repository
  211. end
  212. def test_destroy_invalid_repository
  213. @request.session[:user_id] = 1 # admin
  214. @project.repository.destroy
  215. @repository = Repository::Cvs.create!(
  216. :project => Project.find(PRJ_ID),
  217. :root_url => "/invalid",
  218. :url => MODULE_NAME,
  219. :log_encoding => 'UTF-8'
  220. )
  221. @repository.fetch_changesets
  222. @project.reload
  223. assert_equal 0, @repository.changesets.count
  224. assert_difference 'Repository.count', -1 do
  225. delete :destroy, :id => @repository.id
  226. end
  227. assert_response 302
  228. @project.reload
  229. assert_nil @project.repository
  230. end
  231. else
  232. puts "CVS test repository NOT FOUND. Skipping functional tests !!!"
  233. def test_fake; assert true end
  234. end
  235. end