2017-08-29 17:56:46 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ClientApi::Users::UserTeamsController, type: :controller do
|
|
|
|
describe 'DELETE #leave_team' do
|
|
|
|
login_user
|
|
|
|
before do
|
|
|
|
@user_one = User.first
|
|
|
|
@user_two = FactoryGirl.create(:user, email: 'sec_user@asdf.com')
|
|
|
|
@team = FactoryGirl.create :team
|
|
|
|
FactoryGirl.create :user_team, team: @team, user: @user_one, role: 2
|
|
|
|
end
|
|
|
|
|
2017-08-30 22:18:21 +08:00
|
|
|
it 'should return HTTP success if user can leave the team' do
|
2017-08-29 17:56:46 +08:00
|
|
|
FactoryGirl.create :user_team, team: @team, user: @user_two, role: 2
|
|
|
|
delete :leave_team, params: { team: @team.id }, format: :json
|
|
|
|
expect(response).to be_success
|
2017-08-30 22:18:21 +08:00
|
|
|
expect(response).to have_http_status(:ok)
|
2017-08-29 17:56:46 +08:00
|
|
|
end
|
|
|
|
|
2017-08-30 22:18:21 +08:00
|
|
|
it 'should return HTTP unprocessable_entity if user can\'t leave the team' do
|
2017-08-29 17:56:46 +08:00
|
|
|
delete :leave_team, params: { team: @team.id }, format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
|
2017-08-30 22:18:21 +08:00
|
|
|
it 'should return HTTP unprocessable_entity if no params given' do
|
2017-08-29 17:56:46 +08:00
|
|
|
delete :leave_team, format: :json
|
|
|
|
expect(response).to_not be_success
|
|
|
|
expect(response).to have_http_status(:unprocessable_entity)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|