summaryrefslogtreecommitdiff
path: root/spec/services/projects/update_pages_configuration_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/projects/update_pages_configuration_service_spec.rb')
-rw-r--r--spec/services/projects/update_pages_configuration_service_spec.rb78
1 files changed, 56 insertions, 22 deletions
diff --git a/spec/services/projects/update_pages_configuration_service_spec.rb b/spec/services/projects/update_pages_configuration_service_spec.rb
index c4c9fc779fa..9f7ebd40df6 100644
--- a/spec/services/projects/update_pages_configuration_service_spec.rb
+++ b/spec/services/projects/update_pages_configuration_service_spec.rb
@@ -3,41 +3,75 @@
require 'spec_helper'
RSpec.describe Projects::UpdatePagesConfigurationService do
- let(:project) { create(:project) }
let(:service) { described_class.new(project) }
- describe "#update" do
- let(:file) { Tempfile.new('pages-test') }
-
+ describe "#execute" do
subject { service.execute }
- after do
- file.close
- file.unlink
- end
+ context 'when pages are deployed' do
+ let_it_be(:project) do
+ create(:project).tap(&:mark_pages_as_deployed)
+ end
- before do
- allow(service).to receive(:pages_config_file).and_return(file.path)
- 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 config and reloads the daemon' do
+ allow(service).to receive(:update_file).and_call_original
- context 'when configuration changes' do
- it 'updates the .update file' do
- expect(service).to receive(:reload_daemon).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, reload: true)
+ expect(subject).to include(status: :success)
+ end
+ end
+
+ context 'when configuration does not change' do
+ before do
+ # we set the configuration
+ service.execute
+ end
+
+ it 'does not update the .update file' do
+ expect(service).not_to receive(:reload_daemon)
+
+ expect(subject).to include(status: :success)
+ end
+ end
+
+ context 'when an error occurs' do
+ it 'returns an error object' do
+ e = StandardError.new("Failure")
+ allow(service).to receive(:reload_daemon).and_raise(e)
+
+ expect(subject).to eq(status: :error, message: "Failure", exception: e)
+ end
end
end
- context 'when configuration does not change' do
- before do
- # we set the configuration
- service.execute
+ 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 .update file' do
- expect(service).not_to receive(:reload_daemon)
+ it 'does not update the config' do
+ expect(service).not_to receive(:update_file)
- expect(subject).to include(status: :success, reload: false)
+ subject
end
end
end