Mercurial > hg > soundsoftware-site
comparison .svn/pristine/ac/ac7626843625f32674cf1d8a662e9e3a05d37cf1.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../../test_helper', __FILE__) | |
19 | |
20 class Redmine::ApiTest::MembershipsTest < Redmine::ApiTest::Base | |
21 fixtures :projects, :users, :roles, :members, :member_roles | |
22 | |
23 def setup | |
24 Setting.rest_api_enabled = '1' | |
25 end | |
26 | |
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', | |
44 :child => { | |
45 :tag => 'role', | |
46 :attributes => {:id => '2', :name => 'Developer'} | |
47 } | |
48 } | |
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 "GET /projects/:project_id/memberships.xml should succeed for closed project" do | |
77 project = Project.find(1) | |
78 project.close | |
79 assert !project.reload.active? | |
80 get '/projects/1/memberships.json', {}, credentials('jsmith') | |
81 assert_response :success | |
82 end | |
83 | |
84 test "POST /projects/:project_id/memberships.xml should create the membership" do | |
85 assert_difference 'Member.count' do | |
86 post '/projects/1/memberships.xml', {:membership => {:user_id => 7, :role_ids => [2,3]}}, credentials('jsmith') | |
87 | |
88 assert_response :created | |
89 end | |
90 end | |
91 | |
92 test "POST /projects/:project_id/memberships.xml with invalid parameters should return errors" do | |
93 assert_no_difference 'Member.count' do | |
94 post '/projects/1/memberships.xml', {:membership => {:role_ids => [2,3]}}, credentials('jsmith') | |
95 | |
96 assert_response :unprocessable_entity | |
97 assert_equal 'application/xml', @response.content_type | |
98 assert_tag 'errors', :child => {:tag => 'error', :content => "Principal can't be blank"} | |
99 end | |
100 end | |
101 | |
102 test "GET /memberships/:id.xml should return the membership" do | |
103 get '/memberships/2.xml', {}, credentials('jsmith') | |
104 | |
105 assert_response :success | |
106 assert_equal 'application/xml', @response.content_type | |
107 assert_tag :tag => 'membership', | |
108 :child => { | |
109 :tag => 'id', | |
110 :content => '2', | |
111 :sibling => { | |
112 :tag => 'user', | |
113 :attributes => {:id => '3', :name => 'Dave Lopper'}, | |
114 :sibling => { | |
115 :tag => 'roles', | |
116 :child => { | |
117 :tag => 'role', | |
118 :attributes => {:id => '2', :name => 'Developer'} | |
119 } | |
120 } | |
121 } | |
122 } | |
123 end | |
124 | |
125 test "GET /memberships/:id.json should return the membership" do | |
126 get '/memberships/2.json', {}, credentials('jsmith') | |
127 | |
128 assert_response :success | |
129 assert_equal 'application/json', @response.content_type | |
130 json = ActiveSupport::JSON.decode(response.body) | |
131 assert_equal( | |
132 {"membership" => { | |
133 "id" => 2, | |
134 "project" => {"name"=>"eCookbook", "id"=>1}, | |
135 "roles" => [{"name"=>"Developer", "id"=>2}], | |
136 "user" => {"name"=>"Dave Lopper", "id"=>3}} | |
137 }, | |
138 json) | |
139 end | |
140 | |
141 test "PUT /memberships/:id.xml should update the membership" do | |
142 assert_not_equal [1,2], Member.find(2).role_ids.sort | |
143 assert_no_difference 'Member.count' do | |
144 put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [1,2]}}, credentials('jsmith') | |
145 | |
146 assert_response :ok | |
147 assert_equal '', @response.body | |
148 end | |
149 member = Member.find(2) | |
150 assert_equal [1,2], member.role_ids.sort | |
151 end | |
152 | |
153 test "PUT /memberships/:id.xml with invalid parameters should return errors" do | |
154 put '/memberships/2.xml', {:membership => {:user_id => 3, :role_ids => [99]}}, credentials('jsmith') | |
155 | |
156 assert_response :unprocessable_entity | |
157 assert_equal 'application/xml', @response.content_type | |
158 assert_tag 'errors', :child => {:tag => 'error', :content => /member_roles is invalid/} | |
159 end | |
160 | |
161 test "DELETE /memberships/:id.xml should destroy the membership" do | |
162 assert_difference 'Member.count', -1 do | |
163 delete '/memberships/2.xml', {}, credentials('jsmith') | |
164 | |
165 assert_response :ok | |
166 assert_equal '', @response.body | |
167 end | |
168 assert_nil Member.find_by_id(2) | |
169 end | |
170 | |
171 test "DELETE /memberships/:id.xml should respond with 422 on failure" do | |
172 assert_no_difference 'Member.count' do | |
173 # A membership with an inherited role can't be deleted | |
174 Member.find(2).member_roles.first.update_attribute :inherited_from, 99 | |
175 delete '/memberships/2.xml', {}, credentials('jsmith') | |
176 | |
177 assert_response :unprocessable_entity | |
178 end | |
179 end | |
180 end |