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.

projects_test.rb 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2010 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.dirname(__FILE__)}/../../test_helper"
  18. class ApiTest::ProjectsTest < ActionController::IntegrationTest
  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
  22. def setup
  23. Setting.rest_api_enabled = '1'
  24. end
  25. def test_index
  26. get '/projects.xml'
  27. assert_response :success
  28. assert_equal 'application/xml', @response.content_type
  29. end
  30. def test_show
  31. get '/projects/1.xml'
  32. assert_response :success
  33. assert_equal 'application/xml', @response.content_type
  34. end
  35. def test_create
  36. attributes = {:name => 'API test', :identifier => 'api-test'}
  37. assert_difference 'Project.count' do
  38. post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
  39. end
  40. assert_response :created
  41. assert_equal 'application/xml', @response.content_type
  42. project = Project.first(:order => 'id DESC')
  43. attributes.each do |attribute, value|
  44. assert_equal value, project.send(attribute)
  45. end
  46. end
  47. def test_create_failure
  48. attributes = {:name => 'API test'}
  49. assert_no_difference 'Project.count' do
  50. post '/projects.xml', {:project => attributes}, :authorization => credentials('admin')
  51. end
  52. assert_response :unprocessable_entity
  53. assert_equal 'application/xml', @response.content_type
  54. assert_tag :errors, :child => {:tag => 'error', :content => "Identifier can't be blank"}
  55. end
  56. def test_update
  57. attributes = {:name => 'API update'}
  58. assert_no_difference 'Project.count' do
  59. put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
  60. end
  61. assert_response :ok
  62. assert_equal 'application/xml', @response.content_type
  63. project = Project.find(1)
  64. attributes.each do |attribute, value|
  65. assert_equal value, project.send(attribute)
  66. end
  67. end
  68. def test_update_failure
  69. attributes = {:name => ''}
  70. assert_no_difference 'Project.count' do
  71. put '/projects/1.xml', {:project => attributes}, :authorization => credentials('jsmith')
  72. end
  73. assert_response :unprocessable_entity
  74. assert_equal 'application/xml', @response.content_type
  75. assert_tag :errors, :child => {:tag => 'error', :content => "Name can't be blank"}
  76. end
  77. def test_destroy
  78. assert_difference 'Project.count', -1 do
  79. delete '/projects/2.xml', {}, :authorization => credentials('admin')
  80. end
  81. assert_response :ok
  82. assert_equal 'application/xml', @response.content_type
  83. assert_nil Project.find_by_id(2)
  84. end
  85. def credentials(user, password=nil)
  86. ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user)
  87. end
  88. end