annotate .svn/pristine/65/65e9a6c068b35b0498ff2c94d67db3241b91f5be.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2013 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base
Chris@1295 21 fixtures :projects, :users, :issue_categories, :issues,
Chris@1295 22 :roles,
Chris@1295 23 :member_roles,
Chris@1295 24 :members,
Chris@1295 25 :enabled_modules
Chris@1295 26
Chris@1295 27 def setup
Chris@1295 28 Setting.rest_api_enabled = '1'
Chris@1295 29 end
Chris@1295 30
Chris@1295 31 context "GET /projects/:project_id/issue_categories.xml" do
Chris@1295 32 should "return issue categories" do
Chris@1295 33 get '/projects/1/issue_categories.xml', {}, credentials('jsmith')
Chris@1295 34 assert_response :success
Chris@1295 35 assert_equal 'application/xml', @response.content_type
Chris@1295 36 assert_tag :tag => 'issue_categories',
Chris@1295 37 :child => {:tag => 'issue_category', :child => {:tag => 'id', :content => '2'}}
Chris@1295 38 end
Chris@1295 39 end
Chris@1295 40
Chris@1295 41 context "GET /issue_categories/2.xml" do
Chris@1295 42 should "return requested issue category" do
Chris@1295 43 get '/issue_categories/2.xml', {}, credentials('jsmith')
Chris@1295 44 assert_response :success
Chris@1295 45 assert_equal 'application/xml', @response.content_type
Chris@1295 46 assert_tag :tag => 'issue_category',
Chris@1295 47 :child => {:tag => 'id', :content => '2'}
Chris@1295 48 end
Chris@1295 49 end
Chris@1295 50
Chris@1295 51 context "POST /projects/:project_id/issue_categories.xml" do
Chris@1295 52 should "return create issue category" do
Chris@1295 53 assert_difference 'IssueCategory.count' do
Chris@1295 54 post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith')
Chris@1295 55 end
Chris@1295 56 assert_response :created
Chris@1295 57 assert_equal 'application/xml', @response.content_type
Chris@1295 58
Chris@1295 59 category = IssueCategory.first(:order => 'id DESC')
Chris@1295 60 assert_equal 'API', category.name
Chris@1295 61 assert_equal 1, category.project_id
Chris@1295 62 end
Chris@1295 63
Chris@1295 64 context "with invalid parameters" do
Chris@1295 65 should "return errors" do
Chris@1295 66 assert_no_difference 'IssueCategory.count' do
Chris@1295 67 post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
Chris@1295 68 end
Chris@1295 69 assert_response :unprocessable_entity
Chris@1295 70 assert_equal 'application/xml', @response.content_type
Chris@1295 71
Chris@1295 72 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@1295 73 end
Chris@1295 74 end
Chris@1295 75 end
Chris@1295 76
Chris@1295 77 context "PUT /issue_categories/2.xml" do
Chris@1295 78 context "with valid parameters" do
Chris@1295 79 should "update issue category" do
Chris@1295 80 assert_no_difference 'IssueCategory.count' do
Chris@1295 81 put '/issue_categories/2.xml', {:issue_category => {:name => 'API Update'}}, credentials('jsmith')
Chris@1295 82 end
Chris@1295 83 assert_response :ok
Chris@1295 84 assert_equal '', @response.body
Chris@1295 85 assert_equal 'API Update', IssueCategory.find(2).name
Chris@1295 86 end
Chris@1295 87 end
Chris@1295 88
Chris@1295 89 context "with invalid parameters" do
Chris@1295 90 should "return errors" do
Chris@1295 91 assert_no_difference 'IssueCategory.count' do
Chris@1295 92 put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, credentials('jsmith')
Chris@1295 93 end
Chris@1295 94 assert_response :unprocessable_entity
Chris@1295 95 assert_equal 'application/xml', @response.content_type
Chris@1295 96
Chris@1295 97 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"}
Chris@1295 98 end
Chris@1295 99 end
Chris@1295 100 end
Chris@1295 101
Chris@1295 102 context "DELETE /issue_categories/1.xml" do
Chris@1295 103 should "destroy issue categories" do
Chris@1295 104 assert_difference 'IssueCategory.count', -1 do
Chris@1295 105 delete '/issue_categories/1.xml', {}, credentials('jsmith')
Chris@1295 106 end
Chris@1295 107 assert_response :ok
Chris@1295 108 assert_equal '', @response.body
Chris@1295 109 assert_nil IssueCategory.find_by_id(1)
Chris@1295 110 end
Chris@1295 111
Chris@1295 112 should "reassign issues with :reassign_to_id param" do
Chris@1295 113 issue_count = Issue.count(:conditions => {:category_id => 1})
Chris@1295 114 assert issue_count > 0
Chris@1295 115
Chris@1295 116 assert_difference 'IssueCategory.count', -1 do
Chris@1295 117 assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do
Chris@1295 118 delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith')
Chris@1295 119 end
Chris@1295 120 end
Chris@1295 121 assert_response :ok
Chris@1295 122 assert_equal '', @response.body
Chris@1295 123 assert_nil IssueCategory.find_by_id(1)
Chris@1295 124 end
Chris@1295 125 end
Chris@1295 126 end