Mercurial > hg > soundsoftware-site
comparison .svn/pristine/9c/9c9aeef26ca0ef44d1a985d89461dafc7a3e74a3.svn-base @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2011 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 | |
18 require File.expand_path('../../../test_helper', __FILE__) | |
19 | |
20 class ApiTest::IssueCategoriesTest < ActionController::IntegrationTest | |
21 fixtures :projects, :users, :issue_categories, :issues, | |
22 :roles, | |
23 :member_roles, | |
24 :members, | |
25 :enabled_modules | |
26 | |
27 def setup | |
28 Setting.rest_api_enabled = '1' | |
29 end | |
30 | |
31 context "GET /projects/:project_id/issue_categories.xml" do | |
32 should "return issue categories" do | |
33 get '/projects/1/issue_categories.xml', {}, :authorization => credentials('jsmith') | |
34 assert_response :success | |
35 assert_equal 'application/xml', @response.content_type | |
36 assert_tag :tag => 'issue_categories', | |
37 :child => {:tag => 'issue_category', :child => {:tag => 'id', :content => '2'}} | |
38 end | |
39 end | |
40 | |
41 context "GET /issue_categories/2.xml" do | |
42 should "return requested issue category" do | |
43 get '/issue_categories/2.xml', {}, :authorization => credentials('jsmith') | |
44 assert_response :success | |
45 assert_equal 'application/xml', @response.content_type | |
46 assert_tag :tag => 'issue_category', | |
47 :child => {:tag => 'id', :content => '2'} | |
48 end | |
49 end | |
50 | |
51 context "POST /projects/:project_id/issue_categories.xml" do | |
52 should "return create issue category" do | |
53 assert_difference 'IssueCategory.count' do | |
54 post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, :authorization => credentials('jsmith') | |
55 end | |
56 assert_response :created | |
57 assert_equal 'application/xml', @response.content_type | |
58 | |
59 category = IssueCategory.first(:order => 'id DESC') | |
60 assert_equal 'API', category.name | |
61 assert_equal 1, category.project_id | |
62 end | |
63 | |
64 context "with invalid parameters" do | |
65 should "return errors" do | |
66 assert_no_difference 'IssueCategory.count' do | |
67 post '/projects/1/issue_categories.xml', {:issue_category => {:name => ''}}, :authorization => credentials('jsmith') | |
68 end | |
69 assert_response :unprocessable_entity | |
70 assert_equal 'application/xml', @response.content_type | |
71 | |
72 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} | |
73 end | |
74 end | |
75 end | |
76 | |
77 context "PUT /issue_categories/2.xml" do | |
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'}}, :authorization => credentials('jsmith') | |
82 end | |
83 assert_response :ok | |
84 assert_equal 'API Update', IssueCategory.find(2).name | |
85 end | |
86 end | |
87 | |
88 context "with invalid parameters" do | |
89 should "return errors" do | |
90 assert_no_difference 'IssueCategory.count' do | |
91 put '/issue_categories/2.xml', {:issue_category => {:name => ''}}, :authorization => credentials('jsmith') | |
92 end | |
93 assert_response :unprocessable_entity | |
94 assert_equal 'application/xml', @response.content_type | |
95 | |
96 assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} | |
97 end | |
98 end | |
99 end | |
100 | |
101 context "DELETE /issue_categories/1.xml" do | |
102 should "destroy issue categories" do | |
103 assert_difference 'IssueCategory.count', -1 do | |
104 delete '/issue_categories/1.xml', {}, :authorization => credentials('jsmith') | |
105 end | |
106 assert_response :ok | |
107 assert_nil IssueCategory.find_by_id(1) | |
108 end | |
109 | |
110 should "reassign issues with :reassign_to_id param" do | |
111 issue_count = Issue.count(:conditions => {:category_id => 1}) | |
112 assert issue_count > 0 | |
113 | |
114 assert_difference 'IssueCategory.count', -1 do | |
115 assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do | |
116 delete '/issue_categories/1.xml', {:reassign_to_id => 2}, :authorization => credentials('jsmith') | |
117 end | |
118 end | |
119 assert_response :ok | |
120 assert_nil IssueCategory.find_by_id(1) | |
121 end | |
122 end | |
123 | |
124 def credentials(user, password=nil) | |
125 ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) | |
126 end | |
127 end |