Adds membership ids to /users/:id API response.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8805 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
dfbab5d61e
commit
cdcf813fa7
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue