Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

repositories_controller_test.rb 10KB

Converted routing and urls to follow the Rails REST convention. Patch supplied by commits from Gerrit Kaiser on Github. Existing routes will still work (backwards compatible) but any new urls will be generated using the new routing rules. Changes listed below: * made the URLs for some project tabs and project settings follow the new rails RESTful conventions of /collection/:id/subcollection/:sub_id * prettier URL for project roadmap * more nice project URLs * use GET for filtering form * prettified URLs used on issues tab * custom route for activity atom feeds * prettier repository urls * fixed broken route definition * fixed failing tests for issuecontroller that were hardcoding the url string * more RESTful routes for boards and messages * RESTful routes for wiki pages * RESTful routes for documents * moved old routes that are retained for compatibility to the bottom and grouped them together * added RESTful URIs for issues * RESTfulness for the news section * fixed route order * changed hardcoded URLs in tests * fixed badly written tests * fixed forgotten parameter in routes * changed hardcoded URLS to new scheme * changed project add url to the standard POST to collection * create new issue by POSTing to collection * changed hardcoded URLs in integrations tests * made project add form work again * restful routes for project deletion * prettier routes for project (un)archival * made routes table more readable * fixed note quoting * user routing * fixed bug * always sort by GET * Fixed: cross-project issue list should not show issues of projects for which the issue tracking module was disabled. * prettified URLs used on issues tab * urls for time log * fixed reply routing * eliminate revision query paremeter for diff and entry actions * fixed test failures with hard-coded urls * ensure ajax links always use get * refactored ajax link generation into separate method #1901 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2317 e93f8b46-1217-0410-a6f0-8f06a7374b81
15 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2016 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 RepositoriesControllerTest < Redmine::ControllerTest
  19. fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules,
  20. :repositories, :issues, :issue_statuses, :changesets, :changes,
  21. :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
  22. def setup
  23. User.current = nil
  24. end
  25. def test_new
  26. @request.session[:user_id] = 1
  27. get :new, :project_id => 'subproject1'
  28. assert_response :success
  29. assert_select 'select[name=?]', 'repository_scm' do
  30. assert_select 'option[value=?][selected=selected]', 'Subversion'
  31. end
  32. assert_select 'input[name=?]:not([disabled])', 'repository[url]'
  33. end
  34. def test_new_should_propose_enabled_scm_only
  35. @request.session[:user_id] = 1
  36. with_settings :enabled_scm => ['Mercurial', 'Git'] do
  37. get :new, :project_id => 'subproject1'
  38. end
  39. assert_response :success
  40. assert_select 'select[name=repository_scm]' do
  41. assert_select 'option', 3
  42. assert_select 'option[value=Mercurial][selected=selected]'
  43. assert_select 'option[value=Git]:not([selected])'
  44. end
  45. end
  46. def test_get_new_with_type
  47. @request.session[:user_id] = 1
  48. get :new, :project_id => 'subproject1', :repository_scm => 'Git'
  49. assert_response :success
  50. assert_select 'select[name=?]', 'repository_scm' do
  51. assert_select 'option[value=?][selected=selected]', 'Git'
  52. end
  53. end
  54. def test_create
  55. @request.session[:user_id] = 1
  56. assert_difference 'Repository.count' do
  57. post :create, :project_id => 'subproject1',
  58. :repository_scm => 'Subversion',
  59. :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''}
  60. end
  61. assert_response 302
  62. repository = Repository.order('id DESC').first
  63. assert_kind_of Repository::Subversion, repository
  64. assert_equal 'file:///test', repository.url
  65. end
  66. def test_create_with_failure
  67. @request.session[:user_id] = 1
  68. assert_no_difference 'Repository.count' do
  69. post :create, :project_id => 'subproject1',
  70. :repository_scm => 'Subversion',
  71. :repository => {:url => 'invalid'}
  72. end
  73. assert_response :success
  74. assert_select_error /URL is invalid/
  75. assert_select 'select[name=?]', 'repository_scm' do
  76. assert_select 'option[value=?][selected=selected]', 'Subversion'
  77. end
  78. end
  79. def test_edit
  80. @request.session[:user_id] = 1
  81. get :edit, :id => 11
  82. assert_response :success
  83. assert_select 'input[name=?][value=?][disabled=disabled]', 'repository[url]', 'svn://localhost/test'
  84. end
  85. def test_update
  86. @request.session[:user_id] = 1
  87. put :update, :id => 11, :repository => {:password => 'test_update'}
  88. assert_response 302
  89. assert_equal 'test_update', Repository.find(11).password
  90. end
  91. def test_update_with_failure
  92. @request.session[:user_id] = 1
  93. put :update, :id => 11, :repository => {:password => 'x'*260}
  94. assert_response :success
  95. assert_select_error /Password is too long/
  96. end
  97. def test_destroy
  98. @request.session[:user_id] = 1
  99. assert_difference 'Repository.count', -1 do
  100. delete :destroy, :id => 11
  101. end
  102. assert_response 302
  103. assert_nil Repository.find_by_id(11)
  104. end
  105. def test_show_with_autofetch_changesets_enabled_should_fetch_changesets
  106. Repository::Subversion.any_instance.expects(:fetch_changesets).once
  107. with_settings :autofetch_changesets => '1' do
  108. get :show, :id => 1
  109. end
  110. end
  111. def test_show_with_autofetch_changesets_disabled_should_not_fetch_changesets
  112. Repository::Subversion.any_instance.expects(:fetch_changesets).never
  113. with_settings :autofetch_changesets => '0' do
  114. get :show, :id => 1
  115. end
  116. end
  117. def test_show_with_closed_project_should_not_fetch_changesets
  118. Repository::Subversion.any_instance.expects(:fetch_changesets).never
  119. Project.find(1).close
  120. with_settings :autofetch_changesets => '1' do
  121. get :show, :id => 1
  122. end
  123. end
  124. def test_revisions
  125. get :revisions, :id => 1
  126. assert_response :success
  127. assert_select 'table.changesets'
  128. end
  129. def test_revisions_for_other_repository
  130. repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo')
  131. get :revisions, :id => 1, :repository_id => 'foo'
  132. assert_response :success
  133. assert_select 'table.changesets'
  134. end
  135. def test_revisions_for_invalid_repository
  136. get :revisions, :id => 1, :repository_id => 'foo'
  137. assert_response 404
  138. end
  139. def test_revision
  140. get :revision, :id => 1, :rev => 1
  141. assert_response :success
  142. assert_select 'h2', :text => 'Revision 1'
  143. end
  144. def test_revision_should_not_format_comments_when_disabled
  145. Changeset.where(:id => 100).update_all(:comments => 'Simple *text*')
  146. with_settings :commit_logs_formatting => '0' do
  147. get :revision, :id => 1, :rev => 1
  148. assert_response :success
  149. assert_select '.changeset-comments', :text => 'Simple *text*'
  150. end
  151. end
  152. def test_revision_should_show_add_related_issue_form
  153. Role.find(1).add_permission! :manage_related_issues
  154. @request.session[:user_id] = 2
  155. get :revision, :id => 1, :rev => 1
  156. assert_response :success
  157. assert_select 'form[action=?]', '/projects/ecookbook/repository/revisions/1/issues' do
  158. assert_select 'input[name=?]', 'issue_id'
  159. end
  160. end
  161. def test_revision_should_not_change_the_project_menu_link
  162. get :revision, :id => 1, :rev => 1
  163. assert_response :success
  164. assert_select '#main-menu a.repository[href=?]', '/projects/ecookbook/repository'
  165. end
  166. def test_revision_with_before_nil_and_afer_normal
  167. get :revision, {:id => 1, :rev => 1}
  168. assert_response :success
  169. assert_select 'div.contextual' do
  170. assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/0', 0
  171. assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2'
  172. end
  173. end
  174. def test_add_related_issue
  175. @request.session[:user_id] = 2
  176. assert_difference 'Changeset.find(103).issues.size' do
  177. xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
  178. assert_response :success
  179. assert_equal 'text/javascript', response.content_type
  180. end
  181. assert_equal [2], Changeset.find(103).issue_ids
  182. assert_include 'related-issues', response.body
  183. assert_include 'Feature request #2', response.body
  184. end
  185. def test_add_related_issue_should_accept_issue_id_with_sharp
  186. @request.session[:user_id] = 2
  187. assert_difference 'Changeset.find(103).issues.size' do
  188. xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => "#2", :format => 'js'
  189. end
  190. assert_equal [2], Changeset.find(103).issue_ids
  191. end
  192. def test_add_related_issue_with_invalid_issue_id
  193. @request.session[:user_id] = 2
  194. assert_no_difference 'Changeset.find(103).issues.size' do
  195. xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js'
  196. assert_response :success
  197. assert_equal 'text/javascript', response.content_type
  198. end
  199. assert_include 'alert("Issue is invalid")', response.body
  200. end
  201. def test_remove_related_issue
  202. Changeset.find(103).issues << Issue.find(1)
  203. Changeset.find(103).issues << Issue.find(2)
  204. @request.session[:user_id] = 2
  205. assert_difference 'Changeset.find(103).issues.size', -1 do
  206. xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js'
  207. assert_response :success
  208. assert_equal 'text/javascript', response.content_type
  209. end
  210. assert_equal [1], Changeset.find(103).issue_ids
  211. assert_include 'related-issue-2', response.body
  212. end
  213. def test_graph_commits_per_month
  214. # Make sure there's some data to display
  215. latest = Project.find(1).repository.changesets.maximum(:commit_date)
  216. assert_not_nil latest
  217. Date.stubs(:today).returns(latest.to_date + 10)
  218. get :graph, :id => 1, :graph => 'commits_per_month'
  219. assert_response :success
  220. assert_equal 'image/svg+xml', @response.content_type
  221. end
  222. def test_graph_commits_per_author
  223. get :graph, :id => 1, :graph => 'commits_per_author'
  224. assert_response :success
  225. assert_equal 'image/svg+xml', @response.content_type
  226. end
  227. def test_get_committers
  228. @request.session[:user_id] = 2
  229. # add a commit with an unknown user
  230. Changeset.create!(
  231. :repository => Project.find(1).repository,
  232. :committer => 'foo',
  233. :committed_on => Time.now,
  234. :revision => 100,
  235. :comments => 'Committed by foo.'
  236. )
  237. get :committers, :id => 10
  238. assert_response :success
  239. assert_select 'input[value=dlopper] + select option[value="3"][selected=selected]', :text => 'Dave Lopper'
  240. assert_select 'input[value=foo] + select option[selected=selected]', 0 # no option selected
  241. end
  242. def test_get_committers_without_changesets
  243. Changeset.delete_all
  244. @request.session[:user_id] = 2
  245. get :committers, :id => 10
  246. assert_response :success
  247. end
  248. def test_post_committers
  249. @request.session[:user_id] = 2
  250. # add a commit with an unknown user
  251. c = Changeset.create!(
  252. :repository => Project.find(1).repository,
  253. :committer => 'foo',
  254. :committed_on => Time.now,
  255. :revision => 100,
  256. :comments => 'Committed by foo.'
  257. )
  258. assert_no_difference "Changeset.where(:user_id => 3).count" do
  259. post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']}
  260. assert_response 302
  261. assert_equal User.find(2), c.reload.user
  262. end
  263. end
  264. end