migration_options_spec.rb 2.2 KB
Newer Older
1 2
# frozen_string_literal: true

3
require 'fast_spec_helper'
4 5 6 7 8 9 10 11

RSpec.describe Elastic::MigrationOptions do
  let(:migration_class) do
    Class.new do
      include Elastic::MigrationOptions
    end
  end

12 13
  shared_examples_for 'a boolean option' do |option|
    subject { migration_class.new.public_send("#{option}?") }
14 15 16 17 18

    it 'defaults to false' do
      expect(subject).to be_falsey
    end

19 20
    it "respects when #{option} is set for the class" do
      migration_class.public_send("#{option}!")
21 22 23 24 25

      expect(subject).to be_truthy
    end
  end

26 27 28 29 30 31 32 33 34 35 36 37
  describe '#batched?' do
    it_behaves_like 'a boolean option', :batched
  end

  describe '#pause_indexing?' do
    it_behaves_like 'a boolean option', :pause_indexing
  end

  describe '#space_requirements?' do
    it_behaves_like 'a boolean option', :space_requirements
  end

38 39 40 41 42 43 44 45 46 47 48 49 50
  describe '#throttle_delay' do
    subject { migration_class.new.throttle_delay }

    it 'has a default' do
      expect(subject).to eq(described_class::DEFAULT_THROTTLE_DELAY)
    end

    it 'respects when throttle_delay is set for the class' do
      migration_class.throttle_delay 30.seconds

      expect(subject).to eq(30.seconds)
    end
  end
51 52 53 54 55 56 57 58 59 60 61 62 63 64

  describe '#batch_size' do
    subject { migration_class.new.batch_size }

    it 'has a default' do
      expect(subject).to eq(described_class::DEFAULT_BATCH_SIZE)
    end

    it 'respects when batch_size is set for the class' do
      migration_class.batch_size 10000

      expect(subject).to eq(10000)
    end
  end
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

  describe '#retry_on_failure?' do
    subject { migration_class.new.retry_on_failure? }

    it 'returns false when max_attempts is not set' do
      expect(subject).to be_falsey
    end

    it 'returns true when max_attempts is set' do
      migration_class.retry_on_failure

      expect(subject).to be_truthy
    end
  end

  describe '#max_attempts' do
    subject { migration_class.new.max_attempts }

    it 'returns default when retry_on_failure is set' do
      migration_class.retry_on_failure

      expect(subject).to eq(described_class::DEFAULT_MAX_ATTEMPTS)
    end

    it 'returns max_attempts when it is set' do
      migration_class.retry_on_failure max_attempts: 1_000

      expect(subject).to eq(1_000)
    end
  end
95
end