Sha256: c00eceba89b93d741ec17147672aed817cdb760481fe76168e5deba5576d1436

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module QueueBus
  describe Heartbeat do
    def now_attributes
      {
        'epoch_seconds' => (Time.now.to_i / 60) * 60, # rounded
        'epoch_minutes' => Time.now.to_i / 60,
        'epoch_hours'   => Time.now.to_i / (60 * 60),
        'epoch_days'    => Time.now.to_i / (60 * 60 * 24),
        'minute' => Time.now.min,
        'hour'   => Time.now.hour,
        'day'    => Time.now.day,
        'month'  => Time.now.month,
        'year'   => Time.now.year,
        'yday'   => Time.now.yday,
        'wday'   => Time.now.wday
      }
    end

    it 'should publish the current time once' do
      Timecop.freeze '12/12/2013 12:01:19' do
        expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
        Heartbeat.perform
      end

      Timecop.freeze '12/12/2013 12:01:40' do
        Heartbeat.perform
      end
    end

    it 'should publish a minute later' do
      Timecop.freeze '12/12/2013 12:01:19' do
        expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
        Heartbeat.perform
      end

      Timecop.freeze '12/12/2013 12:02:01' do
        expect(QueueBus).to receive(:publish).with('heartbeat_minutes', now_attributes)
        Heartbeat.perform
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sidekiq-bus-0.9.0 spec/heartbeat_spec.rb
sidekiq-bus-0.8.2 spec/heartbeat_spec.rb