2019-04-15 06:17:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 14:08:28 -04:00
|
|
|
RSpec.describe InvitesController do
|
2015-10-20 03:28:28 -04:00
|
|
|
let(:token) { '123456' }
|
2020-07-07 08:09:16 -04:00
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let(:member) { create(:project_member, :invited, invite_token: token, invite_email: user.email) }
|
|
|
|
let(:project_members) { member.source.users }
|
2015-10-20 03:28:28 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
controller.instance_variable_set(:@member, member)
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
2020-07-07 08:09:16 -04:00
|
|
|
describe 'GET #show' do
|
|
|
|
it 'accepts user if invite email matches signed in user' do
|
|
|
|
expect do
|
|
|
|
get :show, params: { id: token }
|
|
|
|
end.to change { project_members.include?(user) }.from(false).to(true)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
|
|
|
expect(flash[:notice]).to include 'You have been granted'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'forces re-confirmation if email does not match signed in user' do
|
|
|
|
member.invite_email = 'bogus@email.com'
|
|
|
|
|
|
|
|
expect do
|
|
|
|
get :show, params: { id: token }
|
|
|
|
end.not_to change { project_members.include?(user) }
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(flash[:notice]).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST #accept' do
|
2015-10-20 03:28:28 -04:00
|
|
|
it 'accepts user' do
|
2020-07-07 08:09:16 -04:00
|
|
|
expect do
|
|
|
|
post :accept, params: { id: token }
|
|
|
|
end.to change { project_members.include?(user) }.from(false).to(true)
|
2015-10-20 03:28:28 -04:00
|
|
|
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2015-10-20 03:28:28 -04:00
|
|
|
expect(flash[:notice]).to include 'You have been granted'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #decline' do
|
|
|
|
it 'declines user' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :decline, params: { id: token }
|
2015-10-20 03:28:28 -04:00
|
|
|
|
2020-07-07 08:09:16 -04:00
|
|
|
expect { member.reload }.to raise_error ActiveRecord::RecordNotFound
|
2020-01-27 07:08:35 -05:00
|
|
|
expect(response).to have_gitlab_http_status(:found)
|
2015-10-20 03:28:28 -04:00
|
|
|
expect(flash[:notice]).to include 'You have declined the invitation to join'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|