2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-27 01:58:42 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe Projects::UpdatePagesConfigurationService do
|
2019-01-16 12:00:43 +00:00
|
|
|
let(:service) { described_class.new(project) }
|
2017-01-27 01:58:42 +00:00
|
|
|
|
2020-08-07 18:09:53 +00:00
|
|
|
describe "#execute" do
|
2019-01-16 12:00:43 +00:00
|
|
|
subject { service.execute }
|
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
context 'when pages are deployed' do
|
|
|
|
let_it_be(:project) do
|
|
|
|
create(:project).tap(&:mark_pages_as_deployed)
|
|
|
|
end
|
2017-01-27 01:58:42 +00:00
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
let(:file) { Tempfile.new('pages-test') }
|
2019-01-16 12:00:43 +00:00
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
before do
|
|
|
|
allow(service).to receive(:pages_config_file).and_return(file.path)
|
|
|
|
end
|
2019-01-16 12:00:43 +00:00
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
after do
|
|
|
|
file.close
|
|
|
|
file.unlink
|
2019-01-16 12:00:43 +00:00
|
|
|
end
|
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
context 'when configuration changes' do
|
|
|
|
it 'updates the config and reloads the daemon' do
|
|
|
|
expect(service).to receive(:update_file).with(file.path, an_instance_of(String))
|
|
|
|
.and_call_original
|
2021-02-23 18:10:40 +00:00
|
|
|
allow(service).to receive(:update_file).with(File.join(::Settings.pages.path, '.update'),
|
|
|
|
an_instance_of(String)).and_call_original
|
|
|
|
|
|
|
|
expect(subject).to include(status: :success)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't update configuration files if updates on legacy storage are disabled" do
|
2021-04-06 12:09:21 +00:00
|
|
|
allow(Settings.pages.local_store).to receive(:enabled).and_return(false)
|
2021-02-23 18:10:40 +00:00
|
|
|
|
|
|
|
expect(service).not_to receive(:update_file)
|
2020-08-13 21:10:04 +00:00
|
|
|
|
|
|
|
expect(subject).to include(status: :success)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when configuration does not change' do
|
|
|
|
before do
|
|
|
|
# we set the configuration
|
|
|
|
service.execute
|
|
|
|
end
|
|
|
|
|
2021-02-23 18:10:40 +00:00
|
|
|
it 'does not update anything' do
|
|
|
|
expect(service).not_to receive(:update_file)
|
2020-08-13 21:10:04 +00:00
|
|
|
|
|
|
|
expect(subject).to include(status: :success)
|
|
|
|
end
|
2019-01-16 12:00:43 +00:00
|
|
|
end
|
2017-01-27 01:58:42 +00:00
|
|
|
end
|
2020-08-07 18:09:53 +00:00
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
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)
|
2020-08-07 18:09:53 +00:00
|
|
|
|
2020-08-13 21:10:04 +00:00
|
|
|
subject
|
2020-08-07 18:09:53 +00:00
|
|
|
end
|
|
|
|
end
|
2017-01-27 01:58:42 +00:00
|
|
|
end
|
|
|
|
end
|