Commit 98e1f5b1 authored by jplang's avatar jplang

Adds membership ids to /users/:id API response.

git-svn-id: https://svn.redmine.org/redmine/trunk@8805 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 6052c5f1
......@@ -12,10 +12,15 @@ api.user do
api.array :memberships do
@memberships.each do |membership|
api.membership do
api.id membership.id
api.project :id => membership.project.id, :name => membership.project.name
api.array :roles do
membership.roles.each do |role|
api.role :id => role.id, :name => role.name
membership.member_roles.each do |member_role|
if member_role.role
attrs = {:id => member_role.role.id, :name => member_role.role.name}
attrs.merge!(:inherited => true) if member_role.inherited_from.present?
api.role attrs
end
end
end
end if membership.project
......
......@@ -34,20 +34,48 @@ class ApiTest::UsersTest < ActionController::IntegrationTest
should "return requested user" do
get '/users/2.xml'
assert_response :success
assert_tag :tag => 'user',
:child => {:tag => 'id', :content => '2'}
end
context "with include=memberships" do
should "include memberships" do
get '/users/2.xml?include=memberships'
assert_response :success
assert_tag :tag => 'memberships',
:parent => {:tag => 'user'},
:children => {:count => 1}
end
end
end
context ".json" do
should "return requested user" do
get '/users/2.json'
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Hash, json
assert_kind_of Hash, json['user']
assert_equal 2, json['user']['id']
end
context "with include=memberships" do
should "include memberships" do
get '/users/2.json?include=memberships'
assert_response :success
json = ActiveSupport::JSON.decode(response.body)
assert_kind_of Array, json['user']['memberships']
assert_equal [{
"id"=>1,
"project"=>{"name"=>"eCookbook", "id"=>1},
"roles"=>[{"name"=>"Manager", "id"=>1}]
}], json['user']['memberships']
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment