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