@@ -1,132 +1,187 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2010 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require "#{File.dirname(__FILE__)}/../test_helper" |
|
19 | 19 | |
|
20 | 20 | class IssuesApiTest < ActionController::IntegrationTest |
|
21 | 21 | fixtures :projects, |
|
22 | 22 | :users, |
|
23 | 23 | :roles, |
|
24 | 24 | :members, |
|
25 | 25 | :member_roles, |
|
26 | 26 | :issues, |
|
27 | 27 | :issue_statuses, |
|
28 | 28 | :versions, |
|
29 | 29 | :trackers, |
|
30 | 30 | :projects_trackers, |
|
31 | 31 | :issue_categories, |
|
32 | 32 | :enabled_modules, |
|
33 | 33 | :enumerations, |
|
34 | 34 | :attachments, |
|
35 | 35 | :workflows, |
|
36 | 36 | :custom_fields, |
|
37 | 37 | :custom_values, |
|
38 | 38 | :custom_fields_projects, |
|
39 | 39 | :custom_fields_trackers, |
|
40 | 40 | :time_entries, |
|
41 | 41 | :journals, |
|
42 | 42 | :journal_details, |
|
43 | 43 | :queries |
|
44 | 44 | |
|
45 | 45 | def setup |
|
46 | 46 | Setting.rest_api_enabled = '1' |
|
47 | 47 | end |
|
48 | ||
|
49 | def test_index | |
|
50 | get '/issues.xml' | |
|
51 | assert_response :success | |
|
52 | assert_equal 'application/xml', @response.content_type | |
|
48 | ||
|
49 | context "/index.xml" do | |
|
50 | setup do | |
|
51 | get '/issues.xml' | |
|
52 | end | |
|
53 | ||
|
54 | should_respond_with :success | |
|
55 | should_respond_with_content_type 'application/xml' | |
|
53 | 56 | end |
|
54 | 57 | |
|
55 |
|
|
|
56 | get '/issues.xml?status_id=5' | |
|
57 | assert_response :success | |
|
58 | assert_equal 'application/xml', @response.content_type | |
|
59 | assert_tag :tag => 'issues', | |
|
60 | :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}), | |
|
61 | :only => { :tag => 'issue' } } | |
|
62 | end | |
|
58 | context "/index.xml with filter" do | |
|
59 | setup do | |
|
60 | get '/issues.xml?status_id=5' | |
|
61 | end | |
|
63 | 62 | |
|
64 | def test_show | |
|
65 | get '/issues/1.xml' | |
|
66 | assert_response :success | |
|
67 | assert_equal 'application/xml', @response.content_type | |
|
63 | should_respond_with :success | |
|
64 | should_respond_with_content_type 'application/xml' | |
|
65 | should "show only issues with the status_id" do | |
|
66 | assert_tag :tag => 'issues', | |
|
67 | :children => { :count => Issue.visible.count(:conditions => {:status_id => 5}), | |
|
68 | :only => { :tag => 'issue' } } | |
|
69 | end | |
|
68 | 70 | end |
|
71 | ||
|
72 | context "/issues/1.xml" do | |
|
73 | setup do | |
|
74 | get '/issues/1.xml' | |
|
75 | end | |
|
69 | 76 | |
|
70 | def test_create | |
|
71 | attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3} | |
|
72 | assert_difference 'Issue.count' do | |
|
73 | post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith') | |
|
77 | should_respond_with :success | |
|
78 | should_respond_with_content_type 'application/xml' | |
|
79 | end | |
|
80 | ||
|
81 | context "POST /issues.xml" do | |
|
82 | setup do | |
|
83 | @issue_count = Issue.count | |
|
84 | @attributes = {:project_id => 1, :subject => 'API test', :tracker_id => 2, :status_id => 3} | |
|
85 | post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith') | |
|
74 | 86 | end |
|
75 | assert_response :created | |
|
76 | assert_equal 'application/xml', @response.content_type | |
|
77 | issue = Issue.first(:order => 'id DESC') | |
|
78 | attributes.each do |attribute, value| | |
|
79 | assert_equal value, issue.send(attribute) | |
|
87 | ||
|
88 | should_respond_with :created | |
|
89 | should_respond_with_content_type 'application/xml' | |
|
90 | ||
|
91 | should "create an issue with the attributes" do | |
|
92 | assert_equal Issue.count, @issue_count + 1 | |
|
93 | ||
|
94 | issue = Issue.first(:order => 'id DESC') | |
|
95 | @attributes.each do |attribute, value| | |
|
96 | assert_equal value, issue.send(attribute) | |
|
97 | end | |
|
80 | 98 | end |
|
81 | 99 | end |
|
82 | 100 | |
|
83 | def test_create_failure | |
|
84 | attributes = {:project_id => 1} | |
|
85 | assert_no_difference 'Issue.count' do | |
|
86 | post '/issues.xml', {:issue => attributes}, :authorization => credentials('jsmith') | |
|
87 | end | |
|
88 | assert_response :unprocessable_entity | |
|
89 | assert_equal 'application/xml', @response.content_type | |
|
90 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
|
101 | context "POST /issues.xml with failure" do | |
|
102 | setup do | |
|
103 | @attributes = {:project_id => 1} | |
|
104 | post '/issues.xml', {:issue => @attributes}, :authorization => credentials('jsmith') | |
|
105 | end | |
|
106 | ||
|
107 | should_respond_with :unprocessable_entity | |
|
108 | should_respond_with_content_type 'application/xml' | |
|
109 | ||
|
110 | should "have an errors tag" do | |
|
111 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
|
112 | end | |
|
91 | 113 | end |
|
92 | 114 | |
|
93 | def test_update | |
|
94 | attributes = {:subject => 'API update'} | |
|
95 | assert_no_difference 'Issue.count' do | |
|
96 | assert_difference 'Journal.count' do | |
|
97 | put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith') | |
|
98 | end | |
|
115 | context "PUT /issues/1.xml" do | |
|
116 | setup do | |
|
117 | @issue_count = Issue.count | |
|
118 | @journal_count = Journal.count | |
|
119 | @attributes = {:subject => 'API update'} | |
|
120 | ||
|
121 | put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith') | |
|
99 | 122 | end |
|
100 | assert_response :ok | |
|
101 | assert_equal 'application/xml', @response.content_type | |
|
102 | issue = Issue.find(1) | |
|
103 | attributes.each do |attribute, value| | |
|
104 | assert_equal value, issue.send(attribute) | |
|
123 | ||
|
124 | should_respond_with :ok | |
|
125 | should_respond_with_content_type 'application/xml' | |
|
126 | ||
|
127 | should "not create a new issue" do | |
|
128 | assert_equal Issue.count, @issue_count | |
|
105 | 129 | end |
|
106 | end | |
|
107 | ||
|
108 | def test_update_failure | |
|
109 | attributes = {:subject => ''} | |
|
110 | assert_no_difference 'Issue.count' do | |
|
111 | assert_no_difference 'Journal.count' do | |
|
112 | put '/issues/1.xml', {:issue => attributes}, :authorization => credentials('jsmith') | |
|
130 | ||
|
131 | should "create a new journal" do | |
|
132 | assert_equal Journal.count, @journal_count + 1 | |
|
133 | end | |
|
134 | ||
|
135 | should "update the issue" do | |
|
136 | issue = Issue.find(1) | |
|
137 | @attributes.each do |attribute, value| | |
|
138 | assert_equal value, issue.send(attribute) | |
|
113 | 139 | end |
|
114 | 140 | end |
|
115 | assert_response :unprocessable_entity | |
|
116 | assert_equal 'application/xml', @response.content_type | |
|
117 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
|
141 | ||
|
118 | 142 | end |
|
143 | ||
|
144 | context "PUT /issues/1.xml with failed update" do | |
|
145 | setup do | |
|
146 | @attributes = {:subject => ''} | |
|
147 | @issue_count = Issue.count | |
|
148 | @journal_count = Journal.count | |
|
149 | ||
|
150 | put '/issues/1.xml', {:issue => @attributes}, :authorization => credentials('jsmith') | |
|
151 | end | |
|
119 | 152 | |
|
120 | def test_destroy | |
|
121 | assert_difference 'Issue.count', -1 do | |
|
153 | should_respond_with :unprocessable_entity | |
|
154 | should_respond_with_content_type 'application/xml' | |
|
155 | ||
|
156 | should "not create a new issue" do | |
|
157 | assert_equal Issue.count, @issue_count | |
|
158 | end | |
|
159 | ||
|
160 | should "not create a new journal" do | |
|
161 | assert_equal Journal.count, @journal_count | |
|
162 | end | |
|
163 | ||
|
164 | should "have an errors tag" do | |
|
165 | assert_tag :errors, :child => {:tag => 'error', :content => "Subject can't be blank"} | |
|
166 | end | |
|
167 | end | |
|
168 | ||
|
169 | context "DELETE /issues/1.xml" do | |
|
170 | setup do | |
|
171 | @issue_count = Issue.count | |
|
122 | 172 | delete '/issues/1.xml', {}, :authorization => credentials('jsmith') |
|
123 | 173 | end |
|
124 | assert_response :ok | |
|
125 | assert_equal 'application/xml', @response.content_type | |
|
126 | assert_nil Issue.find_by_id(1) | |
|
174 | ||
|
175 | should_respond_with :ok | |
|
176 | should_respond_with_content_type 'application/xml' | |
|
177 | ||
|
178 | should "delete the issue" do | |
|
179 | assert_equal Issue.count, @issue_count -1 | |
|
180 | assert_nil Issue.find_by_id(1) | |
|
181 | end | |
|
127 | 182 | end |
|
128 | 183 | |
|
129 | 184 | def credentials(user, password=nil) |
|
130 | 185 | ActionController::HttpAuthentication::Basic.encode_credentials(user, password || user) |
|
131 | 186 | end |
|
132 | 187 | end |
General Comments 0
You need to be logged in to leave comments.
Login now