Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pages_update_configuration_worker_spec.rb « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ff3727646c7f26e426fb33ecc3952570b2489c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
require "spec_helper"

RSpec.describe PagesUpdateConfigurationWorker do
  let_it_be(:project) { create(:project) }

  describe "#perform" do
    it "does not break if the project doesn't exist" do
      expect { subject.perform(-1) }.not_to raise_error
    end

    it "calls the correct service" do
      expect_next_instance_of(Projects::UpdatePagesConfigurationService, project) do |service|
        expect(service).to receive(:execute).and_return({})
      end

      subject.perform(project.id)
    end

    it_behaves_like "an idempotent worker" do
      let(:job_args) { [project.id] }
      let(:pages_dir) { Dir.mktmpdir }
      let(:config_path) { File.join(pages_dir, "config.json") }

      before do
        allow(Project).to receive(:find_by_id).with(project.id).and_return(project)
        allow(project).to receive(:pages_path).and_return(pages_dir)

        # Make sure _some_ config exists
        FileUtils.touch(config_path)
      end

      after do
        FileUtils.remove_entry(pages_dir)
      end

      it "only updates the config file once" do
        described_class.new.perform(project.id)

        expect(File.mtime(config_path)).not_to be_nil
        expect { subject }.not_to change { File.mtime(config_path) }
      end
    end
  end

  describe '#perform_async' do
    it "calls the correct service", :sidekiq_inline do
      expect_next_instance_of(Projects::UpdatePagesConfigurationService, project) do |service|
        expect(service).to receive(:execute).and_return(status: :success)
      end

      described_class.perform_async(project.id)
    end

    it "doesn't schedule a worker if updates on legacy storage are disabled", :sidekiq_inline do
      stub_feature_flags(pages_update_legacy_storage: false)

      expect(Projects::UpdatePagesConfigurationService).not_to receive(:new)

      described_class.perform_async(project.id)
    end
  end
end