1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe CheckInitialSetup, feature_category: :system_access do
controller(ApplicationController) do
# `described_class` is not available in this context
include CheckInitialSetup
skip_before_action :authenticate_user!
def index
if in_initial_setup_state?
head :ok
else
head :no_content
end
end
end
shared_examples 'is in_initial_setup_state?' do
it 'is in_initial_setup_state?' do
response = get :index
expect(response).to have_gitlab_http_status(:ok)
end
end
shared_examples 'is not in_initial_setup_state?' do
it 'is not in_initial_setup_state?' do
response = get :index
expect(response).to have_gitlab_http_status(:no_content)
end
end
context 'when db is empty' do
include_examples 'is not in_initial_setup_state?'
end
context 'when one admin user named root' do
let(:username) { 'root' }
let(:password_automatically_set) { true }
before do
create(
:admin,
username: username,
password_automatically_set: password_automatically_set
)
end
include_examples 'is in_initial_setup_state?'
context 'when username is not root' do
let(:username) { 'capybara' }
include_examples 'is in_initial_setup_state?'
end
context 'when password reset flag is not set' do
let(:password_automatically_set) { false }
include_examples 'is not in_initial_setup_state?'
end
context 'when multiple users exist' do
before do
create(:user)
end
include_examples 'is not in_initial_setup_state?'
end
context 'when multiple admins exist' do
before do
create(:admin)
end
include_examples 'is not in_initial_setup_state?'
end
end
end
|