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

batched_jobs_controller_spec.rb « admin « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a0654c64b4c48e26d14eb0d4ae5851d83d144a2 (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
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Admin::BatchedJobsController, :enable_admin_mode do
  let(:admin) { create(:admin) }

  before do
    sign_in(admin)
  end

  describe 'GET #show' do
    let(:main_database_job) { create(:batched_background_migration_job) }
    let(:default_model) { ActiveRecord::Base }

    it 'fetches the job' do
      get admin_background_migration_batched_job_path(main_database_job.batched_migration, main_database_job)

      expect(response).to have_gitlab_http_status(:ok)
    end

    it 'uses the default connection' do
      expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(default_model.connection).and_yield

      get admin_background_migration_batched_job_path(main_database_job.batched_migration, main_database_job)
    end

    it 'returns a default database record' do
      get admin_background_migration_batched_job_path(main_database_job.batched_migration, main_database_job)

      expect(assigns(:job)).to eql(main_database_job)
    end

    context 'when the job does not exist' do
      let(:invalid_job) { non_existing_record_id }

      it 'returns not found' do
        get admin_background_migration_batched_job_path(main_database_job.batched_migration, invalid_job)

        expect(response).to have_gitlab_http_status(:not_found)
      end
    end

    context 'when multiple database is enabled', :add_ci_connection do
      let(:base_models) { { 'fake_db' => default_model, 'ci' => ci_model } }
      let(:ci_model) { Ci::ApplicationRecord }

      before do
        allow(Gitlab::Database).to receive(:database_base_models).and_return(base_models)
      end

      context 'when CI database is provided' do
        it "uses CI database connection" do
          expect(Gitlab::Database::SharedModel).to receive(:using_connection).with(ci_model.connection).and_yield

          get admin_background_migration_batched_job_path(main_database_job.batched_migration, main_database_job,
            database: 'ci')
        end

        it 'returns a CI database record' do
          ci_database_job = Gitlab::Database::SharedModel.using_connection(ci_model.connection) do
            create(:batched_background_migration_job, :failed)
          end

          get admin_background_migration_batched_job_path(ci_database_job.batched_migration,
            ci_database_job, database: 'ci')

          expect(assigns(:job)).to eql(ci_database_job)
          expect(assigns(:job)).not_to eql(main_database_job)
        end
      end
    end
  end
end