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