debian-mirror-gitlab/spec/services/pages/delete_service_spec.rb

81 lines
2.2 KiB
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Pages::DeleteService do
2021-03-11 19:13:27 +05:30
let_it_be(:admin) { create(:admin) }
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
let(:project) { create(:project, path: "my.project")}
let!(:domain) { create(:pages_domain, project: project) }
let(:service) { described_class.new(project, admin)}
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
before do
project.mark_pages_as_deployed
end
it 'deletes published pages', :sidekiq_inline do
expect(project.pages_deployed?).to be(true)
2021-04-29 21:17:54 +05:30
expect_next_instance_of(Gitlab::PagesTransfer) do |pages_transfer|
expect(pages_transfer).to receive(:rename_project).and_return true
end
2021-03-11 19:13:27 +05:30
expect(PagesWorker).to receive(:perform_in).with(5.minutes, :remove, project.namespace.full_path, anything)
service.execute
expect(project.pages_deployed?).to be(false)
end
2021-04-29 21:17:54 +05:30
it "doesn't remove anything from the legacy storage", :sidekiq_inline do
allow(Settings.pages.local_store).to receive(:enabled).and_return(false)
2021-03-11 19:13:27 +05:30
expect(project.pages_deployed?).to be(true)
expect(PagesWorker).not_to receive(:perform_in)
service.execute
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
expect(project.pages_deployed?).to be(false)
end
it 'deletes all domains', :sidekiq_inline do
expect(project.pages_domains.count).to eq(1)
service.execute
expect(project.reload.pages_domains.count).to eq(0)
end
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
it 'schedules a destruction of pages deployments' do
expect(DestroyPagesDeploymentsWorker).to(
receive(:perform_async).with(project.id)
)
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
service.execute
end
it 'removes pages deployments', :sidekiq_inline do
create(:pages_deployment, project: project)
2020-11-24 15:15:51 +05:30
2021-03-11 19:13:27 +05:30
expect do
service.execute
end.to change { PagesDeployment.count }.by(-1)
2020-11-24 15:15:51 +05:30
end
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
it 'marks pages as not deployed, deletes domains and schedules worker to remove pages from disk' do
expect(project.pages_deployed?).to eq(true)
expect(project.pages_domains.count).to eq(1)
service.execute
expect(project.pages_deployed?).to eq(false)
expect(project.pages_domains.count).to eq(0)
2021-04-29 21:17:54 +05:30
expect_next_instance_of(Gitlab::PagesTransfer) do |pages_transfer|
expect(pages_transfer).to receive(:rename_project).and_return true
end
2020-01-01 13:55:28 +05:30
2021-03-11 19:13:27 +05:30
Sidekiq::Worker.drain_all
2020-01-01 13:55:28 +05:30
end
end