comparison test/integration/api_test/issue_categories_test.rb @ 1526:404aa68d4227

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