debian-mirror-gitlab/spec/services/projects/update_pages_configuration_service_spec.rb

70 lines
1.7 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Projects::UpdatePagesConfigurationService do
2019-03-02 22:35:43 +05:30
let(:service) { described_class.new(project) }
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
describe "#execute" do
2019-03-02 22:35:43 +05:30
subject { service.execute }
2020-10-24 23:57:45 +05:30
context 'when pages are deployed' do
let_it_be(:project) do
create(:project).tap(&:mark_pages_as_deployed)
end
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
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
2019-03-02 22:35:43 +05:30
2020-10-24 23:57:45 +05:30
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
2019-03-02 22:35:43 +05:30
2020-10-24 23:57:45 +05:30
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
2019-03-02 22:35:43 +05:30
end
2020-10-24 23:57:45 +05:30
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)
2019-03-02 22:35:43 +05:30
end
2020-10-24 23:57:45 +05:30
it 'does not update the config' do
expect(service).not_to receive(:update_file)
2017-08-17 22:00:37 +05:30
2020-10-24 23:57:45 +05:30
subject
2019-03-02 22:35:43 +05:30
end
2017-08-17 22:00:37 +05:30
end
end
end