@@ -24,20 +24,14 class Redmine::ApiTest::EnumerationsTest < Redmine::ApiTest::Base | |||
|
24 | 24 | Setting.rest_api_enabled = '1' |
|
25 | 25 | end |
|
26 | 26 | |
|
27 |
|
|
|
28 | context "GET" do | |
|
29 | ||
|
30 | should "return priorities" do | |
|
31 | get '/enumerations/issue_priorities.xml' | |
|
32 | ||
|
33 | assert_response :success | |
|
34 | assert_equal 'application/xml', response.content_type | |
|
35 | assert_select 'issue_priorities[type=array]' do | |
|
36 | assert_select 'issue_priority' do | |
|
37 | assert_select 'id', :text => '6' | |
|
38 | assert_select 'name', :text => 'High' | |
|
39 | end | |
|
40 | end | |
|
27 | test "GET /enumerations/issue_priorities.xml should return priorities" do | |
|
28 | get '/enumerations/issue_priorities.xml' | |
|
29 | assert_response :success | |
|
30 | assert_equal 'application/xml', response.content_type | |
|
31 | assert_select 'issue_priorities[type=array]' do | |
|
32 | assert_select 'issue_priority' do | |
|
33 | assert_select 'id', :text => '6' | |
|
34 | assert_select 'name', :text => 'High' | |
|
41 | 35 | end |
|
42 | 36 | end |
|
43 | 37 | end |
@@ -24,189 +24,147 class Redmine::ApiTest::GroupsTest < Redmine::ApiTest::Base | |||
|
24 | 24 | Setting.rest_api_enabled = '1' |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | context "GET /groups" do | |
|
28 | context ".xml" do | |
|
29 | should "require authentication" do | |
|
30 | get '/groups.xml' | |
|
31 | assert_response 401 | |
|
32 | end | |
|
27 | test "GET /groups.xml should require authentication" do | |
|
28 | get '/groups.xml' | |
|
29 | assert_response 401 | |
|
30 | end | |
|
33 | 31 | |
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 | ||
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 |
|
|
|
43 | end | |
|
44 | end | |
|
32 | test "GET /groups.xml should return groups" do | |
|
33 | get '/groups.xml', {}, credentials('admin') | |
|
34 | assert_response :success | |
|
35 | assert_equal 'application/xml', response.content_type | |
|
36 | ||
|
37 | assert_select 'groups' do | |
|
38 | assert_select 'group' do | |
|
39 | assert_select 'name', :text => 'A Team' | |
|
40 | assert_select 'id', :text => '10' | |
|
45 | 41 | end |
|
46 | 42 | end |
|
43 | end | |
|
47 | 44 | |
|
48 | context ".json" do | |
|
49 | should "require authentication" do | |
|
50 | get '/groups.json' | |
|
51 | assert_response 401 | |
|
52 | end | |
|
45 | test "GET /groups.json should require authentication" do | |
|
46 | get '/groups.json' | |
|
47 | assert_response 401 | |
|
48 | end | |
|
53 | 49 | |
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
|
58 | ||
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
50 | test "GET /groups.json should return groups" do | |
|
51 | get '/groups.json', {}, credentials('admin') | |
|
52 | assert_response :success | |
|
53 | assert_equal 'application/json', response.content_type | |
|
54 | ||
|
55 | json = MultiJson.load(response.body) | |
|
56 | groups = json['groups'] | |
|
57 | assert_kind_of Array, groups | |
|
58 | group = groups.detect {|g| g['name'] == 'A Team'} | |
|
59 | assert_not_nil group | |
|
60 | assert_equal({'id' => 10, 'name' => 'A Team'}, group) | |
|
61 | end | |
|
62 | ||
|
63 | test "GET /groups/:id.xml should return the group with its users" do | |
|
64 | get '/groups/10.xml', {}, credentials('admin') | |
|
65 | assert_response :success | |
|
66 | assert_equal 'application/xml', response.content_type | |
|
67 | ||
|
68 | assert_select 'group' do | |
|
69 | assert_select 'name', :text => 'A Team' | |
|
70 | assert_select 'id', :text => '10' | |
|
66 | 71 | end |
|
67 | 72 | end |
|
68 | 73 | |
|
69 | context "GET /groups/:id" do | |
|
70 | context ".xml" do | |
|
71 | should "return the group with its users" do | |
|
72 | get '/groups/10.xml', {}, credentials('admin') | |
|
73 | assert_response :success | |
|
74 | assert_equal 'application/xml', response.content_type | |
|
75 | ||
|
76 | assert_select 'group' do | |
|
77 | assert_select 'name', :text => 'A Team' | |
|
78 | assert_select 'id', :text => '10' | |
|
79 | end | |
|
80 | end | |
|
74 | test "GET /groups/:id.xml should include users if requested" do | |
|
75 | get '/groups/10.xml?include=users', {}, credentials('admin') | |
|
76 | assert_response :success | |
|
77 | assert_equal 'application/xml', response.content_type | |
|
81 | 78 | |
|
82 | should "include users if requested" do | |
|
83 | get '/groups/10.xml?include=users', {}, credentials('admin') | |
|
84 | assert_response :success | |
|
85 | assert_equal 'application/xml', response.content_type | |
|
86 | ||
|
87 | assert_select 'group' do | |
|
88 | assert_select 'users' do | |
|
89 | assert_select 'user', Group.find(10).users.count | |
|
90 | assert_select 'user[id=8]' | |
|
91 | end | |
|
92 | end | |
|
79 | assert_select 'group' do | |
|
80 | assert_select 'users' do | |
|
81 | assert_select 'user', Group.find(10).users.count | |
|
82 | assert_select 'user[id=8]' | |
|
93 | 83 | end |
|
84 | end | |
|
85 | end | |
|
94 | 86 | |
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
87 | test "GET /groups/:id.xml include memberships if requested" do | |
|
88 | get '/groups/10.xml?include=memberships', {}, credentials('admin') | |
|
89 | assert_response :success | |
|
90 | assert_equal 'application/xml', response.content_type | |
|
99 | 91 | |
|
100 |
|
|
|
101 |
|
|
|
102 | end | |
|
103 | end | |
|
92 | assert_select 'group' do | |
|
93 | assert_select 'memberships' | |
|
104 | 94 | end |
|
105 | 95 | end |
|
106 | 96 | |
|
107 | context "POST /groups" do | |
|
108 | context "with valid parameters" do | |
|
109 | context ".xml" do | |
|
110 | should "create groups" do | |
|
111 | assert_difference('Group.count') do | |
|
112 | post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin') | |
|
113 | assert_response :created | |
|
114 | assert_equal 'application/xml', response.content_type | |
|
115 | end | |
|
116 | ||
|
117 | group = Group.order('id DESC').first | |
|
118 | assert_equal 'Test', group.name | |
|
119 | assert_equal [2, 3], group.users.map(&:id).sort | |
|
120 | ||
|
121 | assert_select 'group' do | |
|
122 | assert_select 'name', :text => 'Test' | |
|
123 | end | |
|
124 | end | |
|
125 | end | |
|
97 | test "POST /groups.xml with valid parameters should create the group" do | |
|
98 | assert_difference('Group.count') do | |
|
99 | post '/groups.xml', {:group => {:name => 'Test', :user_ids => [2, 3]}}, credentials('admin') | |
|
100 | assert_response :created | |
|
101 | assert_equal 'application/xml', response.content_type | |
|
126 | 102 | end |
|
127 | 103 | |
|
128 | context "with invalid parameters" do | |
|
129 | context ".xml" do | |
|
130 | should "return errors" do | |
|
131 | assert_no_difference('Group.count') do | |
|
132 | post '/groups.xml', {:group => {:name => ''}}, credentials('admin') | |
|
133 | end | |
|
134 | assert_response :unprocessable_entity | |
|
135 | assert_equal 'application/xml', response.content_type | |
|
136 | ||
|
137 | assert_select 'errors' do | |
|
138 | assert_select 'error', :text => /Name can't be blank/ | |
|
139 | end | |
|
140 | end | |
|
141 | end | |
|
104 | group = Group.order('id DESC').first | |
|
105 | assert_equal 'Test', group.name | |
|
106 | assert_equal [2, 3], group.users.map(&:id).sort | |
|
107 | ||
|
108 | assert_select 'group' do | |
|
109 | assert_select 'name', :text => 'Test' | |
|
142 | 110 | end |
|
143 | 111 | end |
|
144 | 112 | |
|
145 | context "PUT /groups/:id" do | |
|
146 | context "with valid parameters" do | |
|
147 | context ".xml" do | |
|
148 | should "update the group" do | |
|
149 | put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin') | |
|
150 | assert_response :ok | |
|
151 | assert_equal '', @response.body | |
|
152 | ||
|
153 | group = Group.find(10) | |
|
154 | assert_equal 'New name', group.name | |
|
155 | assert_equal [2, 3], group.users.map(&:id).sort | |
|
156 | end | |
|
157 | end | |
|
113 | test "POST /groups.xml with invalid parameters should return errors" do | |
|
114 | assert_no_difference('Group.count') do | |
|
115 | post '/groups.xml', {:group => {:name => ''}}, credentials('admin') | |
|
158 | 116 | end |
|
117 | assert_response :unprocessable_entity | |
|
118 | assert_equal 'application/xml', response.content_type | |
|
159 | 119 | |
|
160 | context "with invalid parameters" do | |
|
161 | context ".xml" do | |
|
162 | should "return errors" do | |
|
163 | put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin') | |
|
164 | assert_response :unprocessable_entity | |
|
165 | assert_equal 'application/xml', response.content_type | |
|
166 | ||
|
167 | assert_select 'errors' do | |
|
168 | assert_select 'error', :text => /Name can't be blank/ | |
|
169 | end | |
|
170 | end | |
|
171 | end | |
|
120 | assert_select 'errors' do | |
|
121 | assert_select 'error', :text => /Name can't be blank/ | |
|
172 | 122 | end |
|
173 | 123 | end |
|
174 | 124 | |
|
175 | context "DELETE /groups/:id" do | |
|
176 | context ".xml" do | |
|
177 | should "delete the group" do | |
|
178 | assert_difference 'Group.count', -1 do | |
|
179 | delete '/groups/10.xml', {}, credentials('admin') | |
|
180 | assert_response :ok | |
|
181 | assert_equal '', @response.body | |
|
182 | end | |
|
183 |
|
|
|
125 | test "PUT /groups/:id.xml with valid parameters should update the group" do | |
|
126 | put '/groups/10.xml', {:group => {:name => 'New name', :user_ids => [2, 3]}}, credentials('admin') | |
|
127 | assert_response :ok | |
|
128 | assert_equal '', @response.body | |
|
129 | ||
|
130 | group = Group.find(10) | |
|
131 | assert_equal 'New name', group.name | |
|
132 | assert_equal [2, 3], group.users.map(&:id).sort | |
|
133 | end | |
|
134 | ||
|
135 | test "PUT /groups/:id.xml with invalid parameters should return errors" do | |
|
136 | put '/groups/10.xml', {:group => {:name => ''}}, credentials('admin') | |
|
137 | assert_response :unprocessable_entity | |
|
138 | assert_equal 'application/xml', response.content_type | |
|
139 | ||
|
140 | assert_select 'errors' do | |
|
141 | assert_select 'error', :text => /Name can't be blank/ | |
|
184 | 142 | end |
|
185 | 143 | end |
|
186 | 144 | |
|
187 | context "POST /groups/:id/users" do | |
|
188 | context ".xml" do | |
|
189 | should "add user to the group" do | |
|
190 | assert_difference 'Group.find(10).users.count' do | |
|
191 | post '/groups/10/users.xml', {:user_id => 5}, credentials('admin') | |
|
192 | assert_response :ok | |
|
193 | assert_equal '', @response.body | |
|
194 | end | |
|
195 | assert_include User.find(5), Group.find(10).users | |
|
196 | end | |
|
145 | test "DELETE /groups/:id.xml should delete the group" do | |
|
146 | assert_difference 'Group.count', -1 do | |
|
147 | delete '/groups/10.xml', {}, credentials('admin') | |
|
148 | assert_response :ok | |
|
149 | assert_equal '', @response.body | |
|
197 | 150 | end |
|
198 | 151 | end |
|
199 | 152 | |
|
200 | context "DELETE /groups/:id/users/:user_id" do | |
|
201 | context ".xml" do | |
|
202 | should "remove user from the group" do | |
|
203 | assert_difference 'Group.find(10).users.count', -1 do | |
|
204 | delete '/groups/10/users/8.xml', {}, credentials('admin') | |
|
205 | assert_response :ok | |
|
206 | assert_equal '', @response.body | |
|
207 |
|
|
|
208 | assert_not_include User.find(8), Group.find(10).users | |
|
209 | end | |
|
153 | test "POST /groups/:id/users.xml should add user to the group" do | |
|
154 | assert_difference 'Group.find(10).users.count' do | |
|
155 | post '/groups/10/users.xml', {:user_id => 5}, credentials('admin') | |
|
156 | assert_response :ok | |
|
157 | assert_equal '', @response.body | |
|
158 | end | |
|
159 | assert_include User.find(5), Group.find(10).users | |
|
160 | end | |
|
161 | ||
|
162 | test "DELETE /groups/:id/users/:user_id.xml should remove user from the group" do | |
|
163 | assert_difference 'Group.find(10).users.count', -1 do | |
|
164 | delete '/groups/10/users/8.xml', {}, credentials('admin') | |
|
165 | assert_response :ok | |
|
166 | assert_equal '', @response.body | |
|
210 | 167 | end |
|
168 | assert_not_include User.find(8), Group.find(10).users | |
|
211 | 169 | end |
|
212 | 170 | end |
@@ -28,99 +28,83 class Redmine::ApiTest::IssueCategoriesTest < Redmine::ApiTest::Base | |||
|
28 | 28 | Setting.rest_api_enabled = '1' |
|
29 | 29 | end |
|
30 | 30 | |
|
31 |
|
|
|
32 | should "return issue categories" do | |
|
33 | get '/projects/1/issue_categories.xml', {}, 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 | |
|
31 | test "GET /projects/:project_id/issue_categories.xml should return the issue categories" do | |
|
32 | get '/projects/1/issue_categories.xml', {}, credentials('jsmith') | |
|
33 | assert_response :success | |
|
34 | assert_equal 'application/xml', @response.content_type | |
|
35 | assert_tag :tag => 'issue_categories', | |
|
36 | :child => {:tag => 'issue_category', :child => {:tag => 'id', :content => '2'}} | |
|
39 | 37 | end |
|
40 | 38 | |
|
41 |
|
|
|
42 | should "return requested issue category" do | |
|
43 | get '/issue_categories/2.xml', {}, 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 | |
|
39 | test "GET /issue_categories/:id.xml should return the issue category" do | |
|
40 | get '/issue_categories/2.xml', {}, credentials('jsmith') | |
|
41 | assert_response :success | |
|
42 | assert_equal 'application/xml', @response.content_type | |
|
43 | assert_tag :tag => 'issue_category', | |
|
44 | :child => {:tag => 'id', :content => '2'} | |
|
49 | 45 | end |
|
50 | 46 | |
|
51 |
|
|
|
52 | should "return create issue category" do | |
|
53 | assert_difference 'IssueCategory.count' do | |
|
54 | post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, 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 | |
|
47 | test "POST /projects/:project_id/issue_categories.xml should return create issue category" do | |
|
48 | assert_difference 'IssueCategory.count' do | |
|
49 | post '/projects/1/issue_categories.xml', {:issue_category => {:name => 'API'}}, credentials('jsmith') | |
|
62 | 50 | end |
|
51 | assert_response :created | |
|
52 | assert_equal 'application/xml', @response.content_type | |
|
63 | 53 | |
|
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 => ''}}, credentials('jsmith') | |
|
68 | end | |
|
69 | assert_response :unprocessable_entity | |
|
70 | assert_equal 'application/xml', @response.content_type | |
|
54 | category = IssueCategory.first(:order => 'id DESC') | |
|
55 | assert_equal 'API', category.name | |
|
56 | assert_equal 1, category.project_id | |
|
57 | end | |
|
71 | 58 | |
|
72 | assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} | |
|
73 | end | |
|
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') | |
|
74 | 62 | end |
|
63 | assert_response :unprocessable_entity | |
|
64 | assert_equal 'application/xml', @response.content_type | |
|
65 | ||
|
66 | assert_tag 'errors', :child => {:tag => 'error', :content => "Name can't be blank"} | |
|
75 | 67 | end |
|
76 | 68 | |
|
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'}}, credentials('jsmith') | |
|
82 | end | |
|
83 | assert_response :ok | |
|
84 | assert_equal '', @response.body | |
|
85 | assert_equal 'API Update', IssueCategory.find(2).name | |
|
86 | end | |
|
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') | |
|
87 | 72 | end |
|
73 | assert_response :ok | |
|
74 | assert_equal '', @response.body | |
|
75 | assert_equal 'API Update', IssueCategory.find(2).name | |
|
76 | end | |
|
88 | 77 | |
|
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 | |
|
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') | |
|
99 | 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"} | |
|
100 | 86 | end |
|
101 | 87 | |
|
102 |
|
|
|
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) | |
|
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') | |
|
110 | 91 | end |
|
92 | assert_response :ok | |
|
93 | assert_equal '', @response.body | |
|
94 | assert_nil IssueCategory.find_by_id(1) | |
|
95 | end | |
|
111 | 96 | |
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
97 | test "DELETE /issue_categories/:id.xml should reassign issues with :reassign_to_id param" do | |
|
98 | issue_count = Issue.count(:conditions => {:category_id => 1}) | |
|
99 | assert issue_count > 0 | |
|
115 | 100 | |
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 | end | |
|
101 | assert_difference 'IssueCategory.count', -1 do | |
|
102 | assert_difference 'Issue.count(:conditions => {:category_id => 2})', 3 do | |
|
103 | delete '/issue_categories/1.xml', {:reassign_to_id => 2}, credentials('jsmith') | |
|
120 | 104 | end |
|
121 | assert_response :ok | |
|
122 | assert_equal '', @response.body | |
|
123 | assert_nil IssueCategory.find_by_id(1) | |
|
124 | 105 | end |
|
106 | assert_response :ok | |
|
107 | assert_equal '', @response.body | |
|
108 | assert_nil IssueCategory.find_by_id(1) | |
|
125 | 109 | end |
|
126 | 110 | end |
@@ -31,76 +31,62 class Redmine::ApiTest::IssueRelationsTest < Redmine::ApiTest::Base | |||
|
31 | 31 | Setting.rest_api_enabled = '1' |
|
32 | 32 | end |
|
33 | 33 | |
|
34 |
|
|
|
35 | context "GET" do | |
|
36 | should "return issue relations" do | |
|
37 | get '/issues/9/relations.xml', {}, credentials('jsmith') | |
|
34 | test "GET /issues/:issue_id/relations.xml should return issue relations" do | |
|
35 | get '/issues/9/relations.xml', {}, credentials('jsmith') | |
|
38 | 36 | |
|
39 |
|
|
|
40 |
|
|
|
37 | assert_response :success | |
|
38 | assert_equal 'application/xml', @response.content_type | |
|
41 | 39 | |
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 | end | |
|
53 | ||
|
54 | context "POST" do | |
|
55 | should "create a relation" do | |
|
56 | assert_difference('IssueRelation.count') do | |
|
57 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith') | |
|
58 | end | |
|
40 | assert_tag :tag => 'relations', | |
|
41 | :attributes => { :type => 'array' }, | |
|
42 | :child => { | |
|
43 | :tag => 'relation', | |
|
44 | :child => { | |
|
45 | :tag => 'id', | |
|
46 | :content => '1' | |
|
47 | } | |
|
48 | } | |
|
49 | end | |
|
59 | 50 | |
|
60 | relation = IssueRelation.first(:order => 'id DESC') | |
|
61 | assert_equal 2, relation.issue_from_id | |
|
62 | assert_equal 7, relation.issue_to_id | |
|
63 | assert_equal 'relates', relation.relation_type | |
|
51 | test "POST /issues/:issue_id/relations.xml should create the relation" do | |
|
52 | assert_difference('IssueRelation.count') do | |
|
53 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'relates'}}, credentials('jsmith') | |
|
54 | end | |
|
64 | 55 | |
|
65 | assert_response :created | |
|
66 | assert_equal 'application/xml', @response.content_type | |
|
67 | assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s} | |
|
68 | end | |
|
56 | relation = IssueRelation.first(:order => 'id DESC') | |
|
57 | assert_equal 2, relation.issue_from_id | |
|
58 | assert_equal 7, relation.issue_to_id | |
|
59 | assert_equal 'relates', relation.relation_type | |
|
69 | 60 | |
|
70 | context "with failure" do | |
|
71 | should "return the errors" do | |
|
72 | assert_no_difference('IssueRelation.count') do | |
|
73 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith') | |
|
74 | end | |
|
61 | assert_response :created | |
|
62 | assert_equal 'application/xml', @response.content_type | |
|
63 | assert_tag 'relation', :child => {:tag => 'id', :content => relation.id.to_s} | |
|
64 | end | |
|
75 | 65 | |
|
76 | assert_response :unprocessable_entity | |
|
77 | assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/} | |
|
78 | end | |
|
79 | end | |
|
66 | test "POST /issues/:issue_id/relations.xml with failure should return errors" do | |
|
67 | assert_no_difference('IssueRelation.count') do | |
|
68 | post '/issues/2/relations.xml', {:relation => {:issue_to_id => 7, :relation_type => 'foo'}}, credentials('jsmith') | |
|
80 | 69 | end |
|
81 | end | |
|
82 | 70 | |
|
83 | context "/relations/:id" do | |
|
84 | context "GET" do | |
|
85 | should "return the relation" do | |
|
86 | get '/relations/2.xml', {}, credentials('jsmith') | |
|
71 | assert_response :unprocessable_entity | |
|
72 | assert_tag :errors, :child => {:tag => 'error', :content => /relation_type is not included in the list/} | |
|
73 | end | |
|
87 | 74 | |
|
88 | assert_response :success | |
|
89 | assert_equal 'application/xml', @response.content_type | |
|
90 | assert_tag 'relation', :child => {:tag => 'id', :content => '2'} | |
|
91 | end | |
|
92 | end | |
|
75 | test "GET /relations/:id.xml should return the relation" do | |
|
76 | get '/relations/2.xml', {}, credentials('jsmith') | |
|
93 | 77 | |
|
94 | context "DELETE" do | |
|
95 | should "delete the relation" do | |
|
96 | assert_difference('IssueRelation.count', -1) do | |
|
97 | delete '/relations/2.xml', {}, credentials('jsmith') | |
|
98 | end | |
|
78 | assert_response :success | |
|
79 | assert_equal 'application/xml', @response.content_type | |
|
80 | assert_tag 'relation', :child => {:tag => 'id', :content => '2'} | |
|
81 | end | |
|
99 | 82 | |
|
100 | assert_response :ok | |
|
101 | assert_equal '', @response.body | |
|
102 | assert_nil IssueRelation.find_by_id(2) | |
|
103 | end | |
|
83 | test "DELETE /relations/:id.xml should delete the relation" do | |
|
84 | assert_difference('IssueRelation.count', -1) do | |
|
85 | delete '/relations/2.xml', {}, credentials('jsmith') | |
|
104 | 86 | end |
|
87 | ||
|
88 | assert_response :ok | |
|
89 | assert_equal '', @response.body | |
|
90 | assert_nil IssueRelation.find_by_id(2) | |
|
105 | 91 | end |
|
106 | 92 | end |
@@ -24,28 +24,23 class Redmine::ApiTest::IssueStatusesTest < Redmine::ApiTest::Base | |||
|
24 | 24 | Setting.rest_api_enabled = '1' |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | context "/issue_statuses" do | |
|
28 | context "GET" do | |
|
27 | test "GET /issue_statuses.xml should return issue statuses" do | |
|
28 | get '/issue_statuses.xml' | |
|
29 | 29 | |
|
30 | should "return issue statuses" do | |
|
31 | get '/issue_statuses.xml' | |
|
32 | ||
|
33 | assert_response :success | |
|
34 | assert_equal 'application/xml', @response.content_type | |
|
35 |
|
|
|
36 | :attributes => {:type => 'array'}, | |
|
37 |
: |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
|
42 | :sibling => { | |
|
43 | :tag => 'name', | |
|
44 | :content => 'Assigned' | |
|
45 | } | |
|
46 | } | |
|
30 | assert_response :success | |
|
31 | assert_equal 'application/xml', @response.content_type | |
|
32 | assert_tag :tag => 'issue_statuses', | |
|
33 | :attributes => {:type => 'array'}, | |
|
34 | :child => { | |
|
35 | :tag => 'issue_status', | |
|
36 | :child => { | |
|
37 | :tag => 'id', | |
|
38 | :content => '2', | |
|
39 | :sibling => { | |
|
40 | :tag => 'name', | |
|
41 | :content => 'Assigned' | |
|
47 | 42 | } |
|
48 |
|
|
|
49 | end | |
|
43 | } | |
|
44 | } | |
|
50 | 45 | end |
|
51 | 46 | end |
@@ -24,177 +24,149 class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base | |||
|
24 | 24 | Setting.rest_api_enabled = '1' |
|
25 | 25 | end |
|
26 | 26 | |
|
27 |
|
|
|
28 | context "GET" do | |
|
29 | context "xml" do | |
|
30 | should "return memberships" do | |
|
31 | get '/projects/1/memberships.xml', {}, credentials('jsmith') | |
|
32 | ||
|
33 | assert_response :success | |
|
34 | assert_equal 'application/xml', @response.content_type | |
|
35 |
|
|
|
36 | :attributes => {:type => 'array'}, | |
|
37 |
|
|
|
38 |
|
|
|
27 | test "GET /projects/:project_id/memberships.xml should return memberships" do | |
|
28 | get '/projects/1/memberships.xml', {}, credentials('jsmith') | |
|
29 | ||
|
30 | assert_response :success | |
|
31 | assert_equal 'application/xml', @response.content_type | |
|
32 | assert_tag :tag => 'memberships', | |
|
33 | :attributes => {:type => 'array'}, | |
|
34 | :child => { | |
|
35 | :tag => 'membership', | |
|
36 | :child => { | |
|
37 | :tag => 'id', | |
|
38 | :content => '2', | |
|
39 | :sibling => { | |
|
40 | :tag => 'user', | |
|
41 | :attributes => {:id => '3', :name => 'Dave Lopper'}, | |
|
42 | :sibling => { | |
|
43 | :tag => 'roles', | |
|
39 | 44 | :child => { |
|
40 |
:tag => ' |
|
|
41 | :content => '2', | |
|
42 | :sibling => { | |
|
43 | :tag => 'user', | |
|
44 | :attributes => {:id => '3', :name => 'Dave Lopper'}, | |
|
45 | :sibling => { | |
|
46 | :tag => 'roles', | |
|
47 | :child => { | |
|
48 | :tag => 'role', | |
|
49 | :attributes => {:id => '2', :name => 'Developer'} | |
|
50 | } | |
|
51 | } | |
|
52 | } | |
|
45 | :tag => 'role', | |
|
46 | :attributes => {:id => '2', :name => 'Developer'} | |
|
53 | 47 | } |
|
54 | 48 | } |
|
55 |
|
|
|
56 |
|
|
|
57 | ||
|
58 | context "json" do | |
|
59 | should "return memberships" do | |
|
60 | get '/projects/1/memberships.json', {}, credentials('jsmith') | |
|
61 | ||
|
62 | assert_response :success | |
|
63 | assert_equal 'application/json', @response.content_type | |
|
64 | json = ActiveSupport::JSON.decode(response.body) | |
|
65 | assert_equal({ | |
|
66 | "memberships" => | |
|
67 | [{"id"=>1, | |
|
68 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
69 |
|
|
|
70 |
|
|
|
71 | {"id"=>2, | |
|
72 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
73 |
|
|
|
74 |
|
|
|
75 | "limit" => 25, | |
|
76 |
|
|
|
77 | "offset" => 0}, | |
|
78 | json) | |
|
79 | end | |
|
80 |
|
|
|
81 | end | |
|
49 | } | |
|
50 | } | |
|
51 | } | |
|
52 | end | |
|
53 | ||
|
54 | test "GET /projects/:project_id/memberships.json should return memberships" do | |
|
55 | get '/projects/1/memberships.json', {}, credentials('jsmith') | |
|
56 | ||
|
57 | assert_response :success | |
|
58 | assert_equal 'application/json', @response.content_type | |
|
59 | json = ActiveSupport::JSON.decode(response.body) | |
|
60 | assert_equal({ | |
|
61 | "memberships" => | |
|
62 | [{"id"=>1, | |
|
63 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
64 | "roles" => [{"name"=>"Manager", "id"=>1}], | |
|
65 | "user" => {"name"=>"John Smith", "id"=>2}}, | |
|
66 | {"id"=>2, | |
|
67 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
68 | "roles" => [{"name"=>"Developer", "id"=>2}], | |
|
69 | "user" => {"name"=>"Dave Lopper", "id"=>3}}], | |
|
70 | "limit" => 25, | |
|
71 | "total_count" => 2, | |
|
72 | "offset" => 0}, | |
|
73 | json) | |
|
74 | end | |
|
75 | ||
|
76 | test "POST /projects/:project_id/memberships.xml should create the membership" do | |
|
77 | assert_difference 'Member.count' do | |
|
78 | post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith') | |
|
82 | 79 | |
|
83 | context "POST" do | |
|
84 | context "xml" do | |
|
85 | should "create membership" do | |
|
86 | assert_difference 'Member.count' do | |
|
87 | post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith') | |
|
88 | ||
|
89 | assert_response :created | |
|
90 | end | |
|
91 | end | |
|
92 | ||
|
93 | should "return errors on failure" do | |
|
94 | assert_no_difference 'Member.count' do | |
|
95 | post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith') | |
|
96 | ||
|
97 | assert_response :unprocessable_entity | |
|
98 | assert_equal 'application/xml', @response.content_type | |
|
99 | assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"} | |
|
100 | end | |
|
101 | end | |
|
102 | end | |
|
80 | assert_response :created | |
|
103 | 81 | end |
|
104 | 82 | end |
|
105 | 83 | |
|
106 | context "/memberships/:id" do | |
|
107 | context "GET" do | |
|
108 | context "xml" do | |
|
109 | should "return the membership" do | |
|
110 | get '/memberships/2.xml', {}, credentials('jsmith') | |
|
84 | test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do | |
|
85 | assert_no_difference 'Member.count' do | |
|
86 | post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith') | |
|
111 | 87 | |
|
112 |
|
|
|
113 |
|
|
|
114 | assert_tag :tag => 'membership', | |
|
88 | assert_response :unprocessable_entity | |
|
89 | assert_equal 'application/xml', @response.content_type | |
|
90 | assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"} | |
|
91 | end | |
|
92 | end | |
|
93 | ||
|
94 | test "GET /memberships/:id.xml should return the membership" do | |
|
95 | get '/memberships/2.xml', {}, credentials('jsmith') | |
|
96 | ||
|
97 | assert_response :success | |
|
98 | assert_equal 'application/xml', @response.content_type | |
|
99 | assert_tag :tag => 'membership', | |
|
100 | :child => { | |
|
101 | :tag => 'id', | |
|
102 | :content => '2', | |
|
103 | :sibling => { | |
|
104 | :tag => 'user', | |
|
105 | :attributes => {:id => '3', :name => 'Dave Lopper'}, | |
|
106 | :sibling => { | |
|
107 | :tag => 'roles', | |
|
115 | 108 | :child => { |
|
116 |
:tag => ' |
|
|
117 | :content => '2', | |
|
118 | :sibling => { | |
|
119 | :tag => 'user', | |
|
120 | :attributes => {:id => '3', :name => 'Dave Lopper'}, | |
|
121 | :sibling => { | |
|
122 | :tag => 'roles', | |
|
123 | :child => { | |
|
124 | :tag => 'role', | |
|
125 | :attributes => {:id => '2', :name => 'Developer'} | |
|
126 | } | |
|
127 | } | |
|
128 | } | |
|
109 | :tag => 'role', | |
|
110 | :attributes => {:id => '2', :name => 'Developer'} | |
|
129 | 111 | } |
|
130 |
|
|
|
131 |
|
|
|
132 | ||
|
133 | context "json" do | |
|
134 | should "return the membership" do | |
|
135 | get '/memberships/2.json', {}, credentials('jsmith') | |
|
136 | ||
|
137 | assert_response :success | |
|
138 | assert_equal 'application/json', @response.content_type | |
|
139 | json = ActiveSupport::JSON.decode(response.body) | |
|
140 | assert_equal( | |
|
141 | {"membership" => { | |
|
142 | "id" => 2, | |
|
143 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
144 |
|
|
|
145 |
|
|
|
146 | }, | |
|
147 | json) | |
|
148 |
|
|
|
149 |
|
|
|
112 | } | |
|
113 | } | |
|
114 | } | |
|
115 | end | |
|
116 | ||
|
117 | test "GET /memberships/:id.json should return the membership" do | |
|
118 | get '/memberships/2.json', {}, credentials('jsmith') | |
|
119 | ||
|
120 | assert_response :success | |
|
121 | assert_equal 'application/json', @response.content_type | |
|
122 | json = ActiveSupport::JSON.decode(response.body) | |
|
123 | assert_equal( | |
|
124 | {"membership" => { | |
|
125 | "id" => 2, | |
|
126 | "project" => {"name"=>"eCookbook", "id"=>1}, | |
|
127 | "roles" => [{"name"=>"Developer", "id"=>2}], | |
|
128 | "user" => {"name"=>"Dave Lopper", "id"=>3}} | |
|
129 | }, | |
|
130 | json) | |
|
131 | end | |
|
132 | ||
|
133 | test "PUT /memberships/:id.xml should update the membership" do | |
|
134 | assert_not_equal [1,2], Member.find(2).role_ids.sort | |
|
135 | assert_no_difference 'Member.count' do | |
|
136 | put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith') | |
|
137 | ||
|
138 | assert_response :ok | |
|
139 | assert_equal '', @response.body | |
|
150 | 140 | end |
|
141 | member = Member.find(2) | |
|
142 | assert_equal [1,2], member.role_ids.sort | |
|
143 | end | |
|
144 | ||
|
145 | test "PUT /memberships/:id.xml with invalid parameters should return errors" do | |
|
146 | put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith') | |
|
151 | 147 | |
|
152 | context "PUT" do | |
|
153 | context "xml" do | |
|
154 | should "update membership" do | |
|
155 | assert_not_equal [1,2], Member.find(2).role_ids.sort | |
|
156 | assert_no_difference 'Member.count' do | |
|
157 | put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith') | |
|
158 | ||
|
159 | assert_response :ok | |
|
160 | assert_equal '', @response.body | |
|
161 | end | |
|
162 | member = Member.find(2) | |
|
163 | assert_equal [1,2], member.role_ids.sort | |
|
164 | end | |
|
165 | ||
|
166 | should "return errors on failure" do | |
|
167 | put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith') | |
|
168 | ||
|
169 | assert_response :unprocessable_entity | |
|
170 | assert_equal 'application/xml', @response.content_type | |
|
171 | assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/} | |
|
172 | end | |
|
173 | end | |
|
148 | assert_response :unprocessable_entity | |
|
149 | assert_equal 'application/xml', @response.content_type | |
|
150 | assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/} | |
|
151 | end | |
|
152 | ||
|
153 | test "DELETE /memberships/:id.xml should destroy the membership" do | |
|
154 | assert_difference 'Member.count', -1 do | |
|
155 | delete '/memberships/2.xml', {}, credentials('jsmith') | |
|
156 | ||
|
157 | assert_response :ok | |
|
158 | assert_equal '', @response.body | |
|
174 | 159 | end |
|
160 | assert_nil Member.find_by_id(2) | |
|
161 | end | |
|
162 | ||
|
163 | test "DELETE /memberships/:id.xml should respond with 422 on failure" do | |
|
164 | assert_no_difference 'Member.count' do | |
|
165 | # A membership with an inherited role can't be deleted | |
|
166 | Member.find(2).member_roles.first.update_attribute :inherited_from, 99 | |
|
167 | delete '/memberships/2.xml', {}, credentials('jsmith') | |
|
175 | 168 | |
|
176 | context "DELETE" do | |
|
177 | context "xml" do | |
|
178 | should "destroy membership" do | |
|
179 | assert_difference 'Member.count', -1 do | |
|
180 | delete '/memberships/2.xml', {}, credentials('jsmith') | |
|
181 | ||
|
182 | assert_response :ok | |
|
183 | assert_equal '', @response.body | |
|
184 | end | |
|
185 | assert_nil Member.find_by_id(2) | |
|
186 | end | |
|
187 | ||
|
188 | should "respond with 422 on failure" do | |
|
189 | assert_no_difference 'Member.count' do | |
|
190 | # A membership with an inherited role can't be deleted | |
|
191 | Member.find(2).member_roles.first.update_attribute :inherited_from, 99 | |
|
192 | delete '/memberships/2.xml', {}, credentials('jsmith') | |
|
193 | ||
|
194 | assert_response :unprocessable_entity | |
|
195 | end | |
|
196 | end | |
|
197 | end | |
|
169 | assert_response :unprocessable_entity | |
|
198 | 170 | end |
|
199 | 171 | end |
|
200 | 172 | end |
@@ -31,67 +31,54 class Redmine::ApiTest::NewsTest < Redmine::ApiTest::Base | |||
|
31 | 31 | Setting.rest_api_enabled = '1' |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | context "GET /news" do | |
|
35 | context ".xml" do | |
|
36 | should "return news" do | |
|
37 | get '/news.xml' | |
|
34 | should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") | |
|
35 | should_allow_api_authentication(:get, "/projects/onlinestore/news.json") | |
|
38 | 36 | |
|
39 | assert_tag :tag => 'news', | |
|
40 | :attributes => {:type => 'array'}, | |
|
41 | :child => { | |
|
42 | :tag => 'news', | |
|
43 | :child => { | |
|
44 | :tag => 'id', | |
|
45 | :content => '2' | |
|
46 | } | |
|
47 | } | |
|
48 | end | |
|
49 | end | |
|
37 | test "GET /news.xml should return news" do | |
|
38 | get '/news.xml' | |
|
50 | 39 | |
|
51 | context ".json" do | |
|
52 | should "return news" do | |
|
53 | get '/news.json' | |
|
54 | ||
|
55 | json = ActiveSupport::JSON.decode(response.body) | |
|
56 | assert_kind_of Hash, json | |
|
57 | assert_kind_of Array, json['news'] | |
|
58 | assert_kind_of Hash, json['news'].first | |
|
59 | assert_equal 2, json['news'].first['id'] | |
|
60 | end | |
|
61 | end | |
|
40 | assert_tag :tag => 'news', | |
|
41 | :attributes => {:type => 'array'}, | |
|
42 | :child => { | |
|
43 | :tag => 'news', | |
|
44 | :child => { | |
|
45 | :tag => 'id', | |
|
46 | :content => '2' | |
|
47 | } | |
|
48 | } | |
|
62 | 49 | end |
|
63 | 50 | |
|
64 | context "GET /projects/:project_id/news" do | |
|
65 | context ".xml" do | |
|
66 | should_allow_api_authentication(:get, "/projects/onlinestore/news.xml") | |
|
51 | test "GET /news.json should return news" do | |
|
52 | get '/news.json' | |
|
67 | 53 | |
|
68 | should "return news" do | |
|
69 | get '/projects/ecookbook/news.xml' | |
|
54 | json = ActiveSupport::JSON.decode(response.body) | |
|
55 | assert_kind_of Hash, json | |
|
56 | assert_kind_of Array, json['news'] | |
|
57 | assert_kind_of Hash, json['news'].first | |
|
58 | assert_equal 2, json['news'].first['id'] | |
|
59 | end | |
|
70 | 60 | |
|
71 | assert_tag :tag => 'news', | |
|
72 | :attributes => {:type => 'array'}, | |
|
73 | :child => { | |
|
74 | :tag => 'news', | |
|
75 | :child => { | |
|
76 | :tag => 'id', | |
|
77 | :content => '2' | |
|
78 | } | |
|
79 | } | |
|
80 | end | |
|
81 | end | |
|
61 | test "GET /projects/:project_id/news.xml should return news" do | |
|
62 | get '/projects/ecookbook/news.xml' | |
|
82 | 63 | |
|
83 | context ".json" do | |
|
84 | should_allow_api_authentication(:get, "/projects/onlinestore/news.json") | |
|
64 | assert_tag :tag => 'news', | |
|
65 | :attributes => {:type => 'array'}, | |
|
66 | :child => { | |
|
67 | :tag => 'news', | |
|
68 | :child => { | |
|
69 | :tag => 'id', | |
|
70 | :content => '2' | |
|
71 | } | |
|
72 | } | |
|
73 | end | |
|
85 | 74 | |
|
86 | should "return news" do | |
|
87 |
|
|
|
75 | test "GET /projects/:project_id/news.json should return news" do | |
|
76 | get '/projects/ecookbook/news.json' | |
|
88 | 77 | |
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 | end | |
|
95 | end | |
|
78 | json = ActiveSupport::JSON.decode(response.body) | |
|
79 | assert_kind_of Hash, json | |
|
80 | assert_kind_of Array, json['news'] | |
|
81 | assert_kind_of Hash, json['news'].first | |
|
82 | assert_equal 2, json['news'].first['id'] | |
|
96 | 83 | end |
|
97 | 84 | end |
General Comments 0
You need to be logged in to leave comments.
Login now