docbrown/spec/lib/throttled_call_spec.rb
Michael Kohl 667437ebf2
[15-minute fix] Add ThrottledCall to DisplayAdEventsController (#12924)
* Add ThrottledCall to DisplayAdEventsController

* Update old spec
2021-03-09 09:06:11 +07:00

26 lines
687 B
Ruby

require "rails_helper"
class TestService
def call(*); end
end
RSpec.describe ThrottledCall, throttled_call: true do
let(:service) { TestService.new }
before do
allow(service).to receive(:call)
end
it "calls the block if the call is not currently throttled" do
described_class.perform(:test, throttle_for: 1.minute) { service.call }
expect(service).to have_received(:call)
end
it "does not call the block if the call is currently throttled" do
described_class.perform(:test, throttle_for: 1.minute) { service.call }
described_class.perform(:test, throttle_for: 1.minute) { service.call }
expect(service).to have_received(:call).once
end
end