#671: added #remove_member action for platforms API, updated specs

This commit is contained in:
Vokhmin Alexey V 2012-10-09 21:07:10 +04:00
parent 109afad259
commit e5c6707594
3 changed files with 61 additions and 9 deletions

View File

@ -43,13 +43,7 @@ class Api::V1::PlatformsController < Api::V1::BaseController
end end
def add_member def add_member
if params[:type] == 'User' if member.present? && @platform.add_member(member)
member = User
elsif params[:type] == 'Group'
member = Group
end
member = member.where(:id => params[:member_id]).first if member
if member && @platform.add_member(member)
render :json => { render :json => {
:platform => { :platform => {
:id => @platform.id, :id => @platform.id,
@ -61,4 +55,30 @@ class Api::V1::PlatformsController < Api::V1::BaseController
end end
end end
def remove_member
if member.present? && @platform.remove_member(member)
render :json => {
:platform => {
:id => @platform.id,
:message => "#{member.class.to_s} '#{member.id}' has been removed from platform successfully"
}
}.to_json
else
render :json => validation_failed(@platform), :status => 422
end
end
private
def member
return @member if @member
if params[:type] == 'User'
member = User
elsif params[:type] == 'Group'
member = Group
end
@member = member.where(:id => params[:member_id]).first if member
@member ||= ''
end
end end

View File

@ -27,6 +27,7 @@ Rosa::Application.routes.draw do
member { member {
get :members get :members
put :add_member put :add_member
delete :remove_member
} }
end end
resources :repositories, :only => [:show] resources :repositories, :only => [:show]

View File

@ -37,7 +37,7 @@ shared_examples_for 'api platform user with writer rights' do
put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end end
it 'should be able to perform update action' do it 'should be able to perform add_member action' do
response.should be_success response.should be_success
end end
it 'ensures that new member has been added to platform' do it 'ensures that new member has been added to platform' do
@ -45,6 +45,21 @@ shared_examples_for 'api platform user with writer rights' do
end end
end end
context 'api platform user with remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@platform.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should be able to perform update action' do
response.should be_success
end
it 'ensures that member has been removed from platform' do
@platform.members.should_not include(member)
end
end
end end
shared_examples_for 'api platform user without writer rights' do shared_examples_for 'api platform user without writer rights' do
@ -69,13 +84,29 @@ shared_examples_for 'api platform user without writer rights' do
put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json put :add_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end end
it 'should not be able to perform update action' do it 'should not be able to perform add_member action' do
response.should_not be_success response.should_not be_success
end end
it 'ensures that new member has not been added to platform' do it 'ensures that new member has not been added to platform' do
@platform.members.should_not include(member) @platform.members.should_not include(member)
end end
end end
context 'api platform user without remove_member rights' do
let(:member) { FactoryGirl.create(:user) }
before do
@platform.add_member(member)
delete :remove_member, {:member_id => member.id, :type => 'User', :id => @platform.id}, :format => :json
end
it 'should be able to perform update action' do
response.should_not be_success
end
it 'ensures that member has not been removed from platform' do
@platform.members.should include(member)
end
end
end end
shared_examples_for 'api platform user with reader rights for hidden platform' do shared_examples_for 'api platform user with reader rights for hidden platform' do