Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/fbe/octo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ def with_disable_auto_paginate # rubocop:disable Layout/EmptyLineBetweenDefs
o =
intercepted(o) do |e, m, args, _r|
next unless e == :before
next if %i[off_quota? print_trace! rate_limit rate_limit!].include?(m)
next if %i[
off_quota? print_trace! rate_limit rate_limit! rate_limit_remaining rate_limit_remaining!
ratelimit ratelimit! ratelimit_remaining ratelimit_remaining!
].include?(m)
next if m == :get && %w[/rate_limit rate_limit].include?(args.first)
if Fbe::SEARCH_METHODS.include?(m)
raise(Fbe::OffQuota, "We are off-quota on the search resource, can't do #{m}()") if
Expand Down
16 changes: 16 additions & 0 deletions test/fbe/test_octo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,22 @@ def test_rate_limit_bang_works_when_off_quota
assert_not_requested(:get, 'https://api.github.com/user/42')
end

def test_rate_limit_aliases_work_when_off_quota
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
body: { rate: { limit: 5000, remaining: 7, reset: 1 } }.to_json,
headers: { 'Content-Type' => 'application/json', 'X-RateLimit-Remaining' => '7' }
)
o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'github_token' => 'fake-token' }))
assert_predicate(o, :off_quota?)
%i[ratelimit ratelimit!].each do |m|
assert_equal(7, o.public_send(m).remaining, "#{m} was refused off-quota")
end
%i[rate_limit_remaining rate_limit_remaining! ratelimit_remaining ratelimit_remaining!].each do |m|
assert_equal(7, o.public_send(m), "#{m} was refused off-quota")
end
end

def test_raw_rate_limit_works_when_off_quota
WebMock.disable_net_connect!
stub_request(:get, 'https://api.github.com/rate_limit').to_return(
Expand Down
Loading