travis-api/spec/unit/endpoint/requests/throttle_spec.rb
2016-06-19 14:35:54 +02:00

19 lines
708 B
Ruby

describe Travis::Api::App::Services::ScheduleRequest::Throttle do
let(:repo) { Factory(:repository) }
subject { described_class.new(repo.slug) }
it 'does not throttle by default' do
expect(subject.throttled?).to eq false
end
it 'throttles with more then N requests for the same repo in the last hour' do
10.times { Request.create!(repository: repo, event_type: 'api', result: 'accepted') }
expect(subject.throttled?).to eq true
end
it 'does not throttle with more then N requests for other repos in the last hour' do
10.times { Request.create!(repository: Factory(:repository), event_type: 'api', result: 'accepted') }
expect(subject.throttled?).to eq false
end
end