Sha256: 27c3b32b5d07331f50de9c2bb3b90da75365e9d0c573dcf5ae33158ecc53e4dc

Contents?: true

Size: 1.24 KB

Versions: 67

Compression:

Stored size: 1.24 KB

Contents

require 'rails_helper'

describe PgEngine::DateJumper do
  subject do
    jumper.send(method, days, exclude_holidays:)
  end

  let(:method) { self.class.metadata[:method] }
  let(:jumper) { described_class.new(start_date) }
  let(:start_date) { Date.new(2024, 8, 16) }
  let(:days) { 5 }
  let(:exclude_holidays) { false }

  def fake_holiday(date)
    allow(Holidays).to receive(:on).and_call_original
    allow(Holidays).to receive(:on).with(date, anything)
                                   .and_return([:some_fake_holiday])
  end

  describe 'business_forward', method: 'business_forward' do
    it do
      expect(subject).to eq Date.new(2024, 8, 23)
    end

    context 'excluding holidays' do
      before do
        fake_holiday(Date.new(2024, 8, 23))
      end

      let(:exclude_holidays) { true }

      it do
        expect(subject).to eq Date.new(2024, 8, 26)
      end
    end
  end

  describe 'business_forward', method: 'business_backward' do
    it do
      expect(subject).to eq Date.new(2024, 8, 9)
    end

    context 'excluding holidays' do
      before do
        fake_holiday(Date.new(2024, 8, 14))
      end

      let(:exclude_holidays) { true }

      it do
        expect(subject).to eq Date.new(2024, 8, 8)
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
pg_rails-7.6.28 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.27 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.26 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.25 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.24 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.24.pre.5 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.24.pre.4 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.24.pre.3 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.23 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.22 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.22.pre.3 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.22.pre.2 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.22.pre.1 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.11 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.10 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.9 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.8 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.7 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb
pg_rails-7.6.21.pre.6 pg_engine/spec/lib/pg_engine/date_jumper_spec.rb