Skip to content

fix: drop the page limit calculation #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 10, 2020
Merged
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
9 changes: 2 additions & 7 deletions lib/twilio-ruby/framework/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,13 @@ def delete(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: n
end

def read_limits(limit = nil, page_size = nil)
page_limit = nil

unless limit.nil?
# If there is no user-specified page_size, pick the most network efficient size
unless limit.nil? || page_size
page_size = limit
page_limit = (limit / page_size.to_f).ceil
end

{
limit: limit || nil,
page_size: page_size || nil,
page_limit: page_limit
page_size: page_size || nil
}
end

Expand Down
42 changes: 42 additions & 0 deletions spec/framework/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,48 @@
expect(actual).to_not eq(nil)
end

describe 'stream' do
before(:each) do
@holodeck.mock(
Twilio::Response.new(
200,
'{
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=1",
"messages": [{"body": "payload0"}, {"body": "payload1"}]
}'
)
)
@holodeck.mock(
Twilio::Response.new(
200,
'{
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=2",
"messages": [{"body": "payload2"}, {"body": "payload3"}]
}'
)
)
@holodeck.mock(
Twilio::Response.new(
200,
'{
"next_page_uri": null,
"messages": [{"body": "payload4"}]
}'
)
)
end

it 'streams all results' do
actual = @client.messages.stream
expect(actual.count).to eq(5)
end

it 'limits results' do
actual = @client.messages.stream(limit: 3)
expect(actual.count).to eq(3)
end
end

it 'receives create responses' do
@holodeck.mock(
Twilio::Response.new(
Expand Down
6 changes: 3 additions & 3 deletions spec/holodeck/holodeck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def to_s
ANY = Request.new(any: true)

def initialize
@response = nil
@responses = []
@requests = []
end

def mock(response)
@response = response
@responses << response
end

def request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, _timeout = nil)
Expand All @@ -57,7 +57,7 @@ def request(host, port, method, url, params = {}, data = {}, headers = {}, auth
headers: headers,
auth: auth
)
@response
@responses.shift
end

def has_request?(request)
Expand Down