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

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