annotate .svn/pristine/65/65e9a6c068b35b0498ff2c94d67db3241b91f5be.svn-base @ 1464:261b3d9a4903 redmine-2.4

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