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

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