rename_more_reserved_project_names_spec.rb 1.6 KB
Newer Older
1 2 3 4 5 6 7
# encoding: utf-8

require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170313133418_rename_more_reserved_project_names.rb')

# This migration uses multiple threads, and thus different transactions. This
# means data created in this spec may not be visible to some threads. To work
8 9
# around this we use the DELETE cleaning strategy.
describe RenameMoreReservedProjectNames, :delete do
10
  let(:migration) { described_class.new }
11
  let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
12 13 14 15 16 17 18 19

  before do
    project.path = 'artifacts'
    project.save!(validate: false)
  end

  describe '#up' do
    context 'when project repository exists' do
20 21 22
      before do
        project.create_repository
      end
23 24 25 26 27 28 29 30 31 32 33

      context 'when no exception is raised' do
        it 'renames project with reserved names' do
          migration.up

          expect(project.reload.path).to eq('artifacts0')
        end
      end

      context 'when exception is raised during rename' do
        before do
34 35 36 37 38 39 40 41 42 43
          service = instance_double('service')

          allow(service)
            .to receive(:execute)
            .and_raise(Projects::AfterRenameService::RenameFailedError)

          allow(Projects::AfterRenameService)
            .to receive(:new)
            .with(project)
            .and_return(service)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        end

        it 'captures exception from project rename' do
          expect { migration.up }.not_to raise_error
        end
      end
    end

    context 'when project repository does not exist' do
      it 'does not raise error' do
        expect { migration.up }.not_to raise_error
      end
    end
  end
end