Commit 678fde08 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Merge branch 'bvl-skip-pages-update-config' into 'master'

Only update pages config if pages are deployed.

See merge request gitlab-org/gitlab!39157
parents 06954d2e 192d4e52
......@@ -11,6 +11,11 @@ module Projects
end
def execute
# If the pages were never deployed, we can't write out the config, as the
# directory would not exist.
# https://gitlab.com/gitlab-org/gitlab/-/issues/235139
return success unless project.pages_deployed?
unless file_equals?(pages_config_file, pages_config_json)
update_file(pages_config_file, pages_config_json)
reload_daemon
......
......@@ -142,6 +142,8 @@ module Projects
end
def update_pages_config
return unless project.pages_deployed?
if Feature.enabled?(:async_update_pages_config, project)
PagesUpdateConfigurationWorker.perform_async(project.id)
else
......
......@@ -3,25 +3,33 @@
require 'spec_helper'
RSpec.describe Projects::UpdatePagesConfigurationService do
let(:project) { create(:project) }
let(:service) { described_class.new(project) }
describe "#execute" do
let(:file) { Tempfile.new('pages-test') }
subject { service.execute }
after do
file.close
file.unlink
context 'when pages are deployed' do
let_it_be(:project) do
create(:project).tap(&:mark_pages_as_deployed)
end
let(:file) { Tempfile.new('pages-test') }
before do
allow(service).to receive(:pages_config_file).and_return(file.path)
end
after do
file.close
file.unlink
end
context 'when configuration changes' do
it 'updates the .update file' do
it 'updates the config and reloads the daemon' do
allow(service).to receive(:update_file).and_call_original
expect(service).to receive(:update_file).with(file.path, an_instance_of(String))
.and_call_original
expect(service).to receive(:reload_daemon).and_call_original
expect(subject).to include(status: :success)
......@@ -50,4 +58,21 @@ RSpec.describe Projects::UpdatePagesConfigurationService do
end
end
end
context 'when pages are not deployed' do
let_it_be(:project) do
create(:project).tap(&:mark_pages_as_not_deployed)
end
it 'returns successfully' do
expect(subject).to eq(status: :success)
end
it 'does not update the config' do
expect(service).not_to receive(:update_file)
subject
end
end
end
end
......@@ -397,18 +397,30 @@ RSpec.describe Projects::UpdateService do
end
shared_examples 'updating pages configuration' do
it 'schedules the `PagesUpdateConfigurationWorker`' do
it 'schedules the `PagesUpdateConfigurationWorker` when pages are deployed' do
project.mark_pages_as_deployed
expect(PagesUpdateConfigurationWorker).to receive(:perform_async).with(project.id)
subject
end
it "does not schedule a job when pages aren't deployed" do
project.mark_pages_as_not_deployed
expect(PagesUpdateConfigurationWorker).not_to receive(:perform_async).with(project.id)
subject
end
context 'when `async_update_pages_config` is disabled' do
before do
stub_feature_flags(async_update_pages_config: false)
end
it 'calls Projects::UpdatePagesConfigurationService' do
it 'calls Projects::UpdatePagesConfigurationService when pages are deployed' do
project.mark_pages_as_deployed
expect(Projects::UpdatePagesConfigurationService)
.to receive(:new)
.with(project)
......@@ -416,6 +428,15 @@ RSpec.describe Projects::UpdateService do
subject
end
it "does not update pages config when pages aren't deployed" do
project.mark_pages_as_not_deployed
expect(Projects::UpdatePagesConfigurationService)
.not_to receive(:new)
subject
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment