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_bazaar_controller_test.rb 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 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 RepositoriesBazaarControllerTest < 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/bazaar_repository/trunk').to_s
  23. PRJ_ID = 3
  24. def setup
  25. User.current = nil
  26. @project = Project.find(PRJ_ID)
  27. @repository = Repository::Bazaar.create(
  28. :project => @project,
  29. :url => REPOSITORY_PATH,
  30. :log_encoding => 'UTF-8')
  31. assert @repository
  32. end
  33. if File.directory?(REPOSITORY_PATH)
  34. def test_get_new
  35. @request.session[:user_id] = 1
  36. @project.repository.destroy
  37. get :new, :project_id => 'subproject1', :repository_scm => 'Bazaar'
  38. assert_response :success
  39. assert_template 'new'
  40. assert_kind_of Repository::Bazaar, assigns(:repository)
  41. assert assigns(:repository).new_record?
  42. end
  43. def test_browse_root
  44. get :show, :id => PRJ_ID
  45. assert_response :success
  46. assert_template 'show'
  47. assert_not_nil assigns(:entries)
  48. assert_equal 2, assigns(:entries).size
  49. assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
  50. assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'}
  51. end
  52. def test_browse_directory
  53. get :show, :id => PRJ_ID, :path => repository_path_hash(['directory'])[:param]
  54. assert_response :success
  55. assert_template 'show'
  56. assert_not_nil assigns(:entries)
  57. assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
  58. entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
  59. assert_not_nil entry
  60. assert_equal 'file', entry.kind
  61. assert_equal 'directory/edit.png', entry.path
  62. end
  63. def test_browse_at_given_revision
  64. get :show, :id => PRJ_ID, :path => repository_path_hash([])[:param],
  65. :rev => 3
  66. assert_response :success
  67. assert_template 'show'
  68. assert_not_nil assigns(:entries)
  69. assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'],
  70. assigns(:entries).collect(&:name)
  71. end
  72. def test_changes
  73. get :changes, :id => PRJ_ID,
  74. :path => repository_path_hash(['doc-mkdir.txt'])[:param]
  75. assert_response :success
  76. assert_template 'changes'
  77. assert_tag :tag => 'h2', :content => 'doc-mkdir.txt'
  78. end
  79. def test_entry_show
  80. get :entry, :id => PRJ_ID,
  81. :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param]
  82. assert_response :success
  83. assert_template 'entry'
  84. # Line 19
  85. assert_tag :tag => 'th',
  86. :content => /29/,
  87. :attributes => { :class => /line-num/ },
  88. :sibling => { :tag => 'td', :content => /Show help message/ }
  89. end
  90. def test_entry_download
  91. get :entry, :id => PRJ_ID,
  92. :path => repository_path_hash(['directory', 'doc-ls.txt'])[:param],
  93. :format => 'raw'
  94. assert_response :success
  95. # File content
  96. assert @response.body.include?('Show help message')
  97. end
  98. def test_directory_entry
  99. get :entry, :id => PRJ_ID,
  100. :path => repository_path_hash(['directory'])[:param]
  101. assert_response :success
  102. assert_template 'show'
  103. assert_not_nil assigns(:entry)
  104. assert_equal 'directory', assigns(:entry).name
  105. end
  106. def test_diff
  107. # Full diff of changeset 3
  108. ['inline', 'sbs'].each do |dt|
  109. get :diff, :id => PRJ_ID, :rev => 3, :type => dt
  110. assert_response :success
  111. assert_template 'diff'
  112. # Line 11 removed
  113. assert_tag :tag => 'th',
  114. :content => '11',
  115. :sibling => { :tag => 'td',
  116. :attributes => { :class => /diff_out/ },
  117. :content => /Display more information/ }
  118. end
  119. end
  120. def test_annotate
  121. get :annotate, :id => PRJ_ID,
  122. :path => repository_path_hash(['doc-mkdir.txt'])[:param]
  123. assert_response :success
  124. assert_template 'annotate'
  125. assert_tag :tag => 'th', :content => '2',
  126. :sibling => {
  127. :tag => 'td',
  128. :child => {
  129. :tag => 'a',
  130. :content => '3'
  131. }
  132. }
  133. assert_tag :tag => 'th', :content => '2',
  134. :sibling => { :tag => 'td', :content => /jsmith/ }
  135. assert_tag :tag => 'th', :content => '2',
  136. :sibling => {
  137. :tag => 'td',
  138. :child => {
  139. :tag => 'a',
  140. :content => '3'
  141. }
  142. }
  143. assert_tag :tag => 'th', :content => '2',
  144. :sibling => { :tag => 'td', :content => /Main purpose/ }
  145. end
  146. def test_destroy_valid_repository
  147. @request.session[:user_id] = 1 # admin
  148. assert_equal 0, @repository.changesets.count
  149. @repository.fetch_changesets
  150. assert @repository.changesets.count > 0
  151. assert_difference 'Repository.count', -1 do
  152. delete :destroy, :id => @repository.id
  153. end
  154. assert_response 302
  155. @project.reload
  156. assert_nil @project.repository
  157. end
  158. def test_destroy_invalid_repository
  159. @request.session[:user_id] = 1 # admin
  160. @project.repository.destroy
  161. @repository = Repository::Bazaar.create!(
  162. :project => @project,
  163. :url => "/invalid",
  164. :log_encoding => 'UTF-8')
  165. @repository.fetch_changesets
  166. @repository.reload
  167. assert_equal 0, @repository.changesets.count
  168. assert_difference 'Repository.count', -1 do
  169. delete :destroy, :id => @repository.id
  170. end
  171. assert_response 302
  172. @project.reload
  173. assert_nil @project.repository
  174. end
  175. else
  176. puts "Bazaar test repository NOT FOUND. Skipping functional tests !!!"
  177. def test_fake; assert true end
  178. end
  179. end