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.

versions_test.rb 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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::VersionsTest < Redmine::ApiTest::Base
  19. fixtures :projects, :trackers, :issue_statuses, :issues,
  20. :enumerations, :users, :issue_categories,
  21. :projects_trackers,
  22. :roles,
  23. :member_roles,
  24. :members,
  25. :enabled_modules,
  26. :versions
  27. test "GET /projects/:project_id/versions.xml should return project versions" do
  28. get '/projects/1/versions.xml'
  29. assert_response :success
  30. assert_equal 'application/xml', @response.content_type
  31. assert_select 'versions[type=array] version id', :text => '2' do
  32. assert_select '~ name', :text => '1.0'
  33. end
  34. end
  35. test "POST /projects/:project_id/versions.xml should create the version" do
  36. assert_difference 'Version.count' do
  37. post '/projects/1/versions.xml', {:version => {:name => 'API test'}}, credentials('jsmith')
  38. end
  39. version = Version.order('id DESC').first
  40. assert_equal 'API test', version.name
  41. assert_response :created
  42. assert_equal 'application/xml', @response.content_type
  43. assert_select 'version id', :text => version.id.to_s
  44. end
  45. test "POST /projects/:project_id/versions.xml should create the version with due date" do
  46. assert_difference 'Version.count' do
  47. post '/projects/1/versions.xml', {:version => {:name => 'API test', :due_date => '2012-01-24'}}, credentials('jsmith')
  48. end
  49. version = Version.order('id DESC').first
  50. assert_equal 'API test', version.name
  51. assert_equal Date.parse('2012-01-24'), version.due_date
  52. assert_response :created
  53. assert_equal 'application/xml', @response.content_type
  54. assert_select 'version id', :text => version.id.to_s
  55. end
  56. test "POST /projects/:project_id/versions.xml should create the version with custom fields" do
  57. field = VersionCustomField.generate!
  58. assert_difference 'Version.count' do
  59. post '/projects/1/versions.xml', {
  60. :version => {
  61. :name => 'API test',
  62. :custom_fields => [
  63. {'id' => field.id.to_s, 'value' => 'Some value'}
  64. ]
  65. }
  66. }, credentials('jsmith')
  67. end
  68. version = Version.order('id DESC').first
  69. assert_equal 'API test', version.name
  70. assert_equal 'Some value', version.custom_field_value(field)
  71. assert_response :created
  72. assert_equal 'application/xml', @response.content_type
  73. assert_select 'version>custom_fields>custom_field[id=?]>value', field.id.to_s, 'Some value'
  74. end
  75. test "POST /projects/:project_id/versions.xml with failure should return the errors" do
  76. assert_no_difference('Version.count') do
  77. post '/projects/1/versions.xml', {:version => {:name => ''}}, credentials('jsmith')
  78. end
  79. assert_response :unprocessable_entity
  80. assert_select 'errors error', :text => "Name cannot be blank"
  81. end
  82. test "GET /versions/:id.xml should return the version" do
  83. get '/versions/2.xml'
  84. assert_response :success
  85. assert_equal 'application/xml', @response.content_type
  86. assert_select 'version' do
  87. assert_select 'id', :text => '2'
  88. assert_select 'name', :text => '1.0'
  89. assert_select 'sharing', :text => 'none'
  90. end
  91. end
  92. test "PUT /versions/:id.xml should update the version" do
  93. put '/versions/2.xml', {:version => {:name => 'API update'}}, credentials('jsmith')
  94. assert_response :ok
  95. assert_equal '', @response.body
  96. assert_equal 'API update', Version.find(2).name
  97. end
  98. test "DELETE /versions/:id.xml should destroy the version" do
  99. assert_difference 'Version.count', -1 do
  100. delete '/versions/3.xml', {}, credentials('jsmith')
  101. end
  102. assert_response :ok
  103. assert_equal '', @response.body
  104. assert_nil Version.find_by_id(3)
  105. end
  106. end