Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

projects_test.rb 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 Redmine::ApiTest::ProjectsTest < Redmine::ApiTest::Base
  19. fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details,
  20. :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages,
  21. :attachments, :custom_fields, :custom_values, :time_entries, :issue_categories
  22. def setup
  23. super
  24. set_tmp_attachments_directory
  25. end
  26. test "GET /projects.xml should return projects" do
  27. get '/projects.xml'
  28. assert_response :success
  29. assert_equal 'application/xml', @response.content_type
  30. assert_select 'projects>project>id', :text => '1'
  31. assert_select 'projects>project>status', :text => '1'
  32. assert_select 'projects>project>is_public', :text => 'true'
  33. end
  34. test "GET /projects.json should return projects" do
  35. get '/projects.json'
  36. assert_response :success
  37. assert_equal 'application/json', @response.content_type
  38. json = ActiveSupport::JSON.decode(response.body)
  39. assert_kind_of Hash, json
  40. assert_kind_of Array, json['projects']
  41. assert_kind_of Hash, json['projects'].first
  42. assert json['projects'].first.has_key?('id')
  43. end
  44. test "GET /projects.xml with include=issue_categories should return categories" do
  45. get '/projects.xml?include=issue_categories'
  46. assert_response :success
  47. assert_equal 'application/xml', @response.content_type
  48. assert_select 'issue_categories[type=array] issue_category[id="2"][name=Recipes]'
  49. end
  50. test "GET /projects.xml with include=trackers should return trackers" do
  51. get '/projects.xml?include=trackers'
  52. assert_response :success
  53. assert_equal 'application/xml', @response.content_type
  54. assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
  55. end
  56. test "GET /projects.xml with include=enabled_modules should return enabled modules" do
  57. get '/projects.xml?include=enabled_modules'
  58. assert_response :success
  59. assert_equal 'application/xml', @response.content_type
  60. assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
  61. end
  62. test "GET /projects/:id.xml should return the project" do
  63. get '/projects/1.xml'
  64. assert_response :success
  65. assert_equal 'application/xml', @response.content_type
  66. assert_select 'project>id', :text => '1'
  67. assert_select 'project>status', :text => '1'
  68. assert_select 'project>is_public', :text => 'true'
  69. assert_select 'custom_field[name="Development status"]', :text => 'Stable'
  70. assert_select 'trackers', 0
  71. assert_select 'issue_categories', 0
  72. end
  73. test "GET /projects/:id.json should return the project" do
  74. get '/projects/1.json'
  75. json = ActiveSupport::JSON.decode(response.body)
  76. assert_kind_of Hash, json
  77. assert_kind_of Hash, json['project']
  78. assert_equal 1, json['project']['id']
  79. end
  80. test "GET /projects/:id.xml with hidden custom fields should not display hidden custom fields" do
  81. ProjectCustomField.find_by_name('Development status').update_attribute :visible, false
  82. get '/projects/1.xml'
  83. assert_response :success
  84. assert_equal 'application/xml', @response.content_type
  85. assert_select 'custom_field[name=?]', 'Development status', 0
  86. end
  87. test "GET /projects/:id.xml with include=issue_categories should return categories" do
  88. get '/projects/1.xml?include=issue_categories'
  89. assert_response :success
  90. assert_equal 'application/xml', @response.content_type
  91. assert_select 'issue_categories[type=array] issue_category[id="2"][name=Recipes]'
  92. end
  93. test "GET /projects/:id.xml with include=trackers should return trackers" do
  94. get '/projects/1.xml?include=trackers'
  95. assert_response :success
  96. assert_equal 'application/xml', @response.content_type
  97. assert_select 'trackers[type=array] tracker[id="2"][name="Feature request"]'
  98. end
  99. test "GET /projects/:id.xml with include=enabled_modules should return enabled modules" do
  100. get '/projects/1.xml?include=enabled_modules'
  101. assert_response :success
  102. assert_equal 'application/xml', @response.content_type
  103. assert_select 'enabled_modules[type=array] enabled_module[name=issue_tracking]'
  104. end
  105. test "POST /projects.xml with valid parameters should create the project" do
  106. with_settings :default_projects_modules => ['issue_tracking', 'repository'] do
  107. assert_difference('Project.count') do
  108. post '/projects.xml',
  109. {:project => {:name => 'API test', :identifier => 'api-test'}},
  110. credentials('admin')
  111. end
  112. end
  113. project = Project.order('id DESC').first
  114. assert_equal 'API test', project.name
  115. assert_equal 'api-test', project.identifier
  116. assert_equal ['issue_tracking', 'repository'], project.enabled_module_names.sort
  117. assert_equal Tracker.all.size, project.trackers.size
  118. assert_response :created
  119. assert_equal 'application/xml', @response.content_type
  120. assert_select 'project id', :text => project.id.to_s
  121. end
  122. test "POST /projects.xml should accept enabled_module_names attribute" do
  123. assert_difference('Project.count') do
  124. post '/projects.xml',
  125. {:project => {:name => 'API test', :identifier => 'api-test', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}},
  126. credentials('admin')
  127. end
  128. project = Project.order('id DESC').first
  129. assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
  130. end
  131. test "POST /projects.xml should accept tracker_ids attribute" do
  132. assert_difference('Project.count') do
  133. post '/projects.xml',
  134. {:project => {:name => 'API test', :identifier => 'api-test', :tracker_ids => [1, 3]}},
  135. credentials('admin')
  136. end
  137. project = Project.order('id DESC').first
  138. assert_equal [1, 3], project.trackers.map(&:id).sort
  139. end
  140. test "POST /projects.xml with invalid parameters should return errors" do
  141. assert_no_difference('Project.count') do
  142. post '/projects.xml', {:project => {:name => 'API test'}}, credentials('admin')
  143. end
  144. assert_response :unprocessable_entity
  145. assert_equal 'application/xml', @response.content_type
  146. assert_select 'errors error', :text => "Identifier cannot be blank"
  147. end
  148. test "PUT /projects/:id.xml with valid parameters should update the project" do
  149. assert_no_difference 'Project.count' do
  150. put '/projects/2.xml', {:project => {:name => 'API update'}}, credentials('jsmith')
  151. end
  152. assert_response :ok
  153. assert_equal '', @response.body
  154. assert_equal 'application/xml', @response.content_type
  155. project = Project.find(2)
  156. assert_equal 'API update', project.name
  157. end
  158. test "PUT /projects/:id.xml should accept enabled_module_names attribute" do
  159. assert_no_difference 'Project.count' do
  160. put '/projects/2.xml', {:project => {:name => 'API update', :enabled_module_names => ['issue_tracking', 'news', 'time_tracking']}}, credentials('admin')
  161. end
  162. assert_response :ok
  163. assert_equal '', @response.body
  164. project = Project.find(2)
  165. assert_equal ['issue_tracking', 'news', 'time_tracking'], project.enabled_module_names.sort
  166. end
  167. test "PUT /projects/:id.xml should accept tracker_ids attribute" do
  168. assert_no_difference 'Project.count' do
  169. put '/projects/2.xml', {:project => {:name => 'API update', :tracker_ids => [1, 3]}}, credentials('admin')
  170. end
  171. assert_response :ok
  172. assert_equal '', @response.body
  173. project = Project.find(2)
  174. assert_equal [1, 3], project.trackers.map(&:id).sort
  175. end
  176. test "PUT /projects/:id.xml with invalid parameters should return errors" do
  177. assert_no_difference('Project.count') do
  178. put '/projects/2.xml', {:project => {:name => ''}}, credentials('admin')
  179. end
  180. assert_response :unprocessable_entity
  181. assert_equal 'application/xml', @response.content_type
  182. assert_select 'errors error', :text => "Name cannot be blank"
  183. end
  184. test "DELETE /projects/:id.xml should delete the project" do
  185. assert_difference('Project.count',-1) do
  186. delete '/projects/2.xml', {}, credentials('admin')
  187. end
  188. assert_response :ok
  189. assert_equal '', @response.body
  190. assert_nil Project.find_by_id(2)
  191. end
  192. end