Skip to content

Commit dd6aec3

Browse files
author
childish-sambino
authored
fix: drop the page limit calculation (#530)
Dropping the page limit calculation since it doesn't make sense to be calculated from a record limit.
1 parent 8f806b8 commit dd6aec3

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

lib/twilio-ruby/framework/version.rb

+2-7
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,13 @@ def delete(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: n
112112
end
113113

114114
def read_limits(limit = nil, page_size = nil)
115-
page_limit = nil
116-
117-
unless limit.nil?
118-
# If there is no user-specified page_size, pick the most network efficient size
115+
unless limit.nil? || page_size
119116
page_size = limit
120-
page_limit = (limit / page_size.to_f).ceil
121117
end
122118

123119
{
124120
limit: limit || nil,
125-
page_size: page_size || nil,
126-
page_limit: page_limit
121+
page_size: page_size || nil
127122
}
128123
end
129124

spec/framework/version_spec.rb

+42
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,48 @@
2121
expect(actual).to_not eq(nil)
2222
end
2323

24+
describe 'stream' do
25+
before(:each) do
26+
@holodeck.mock(
27+
Twilio::Response.new(
28+
200,
29+
'{
30+
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=1",
31+
"messages": [{"body": "payload0"}, {"body": "payload1"}]
32+
}'
33+
)
34+
)
35+
@holodeck.mock(
36+
Twilio::Response.new(
37+
200,
38+
'{
39+
"next_page_uri": "/2010-04-01/Accounts/AC123/Messages.json?Page=2",
40+
"messages": [{"body": "payload2"}, {"body": "payload3"}]
41+
}'
42+
)
43+
)
44+
@holodeck.mock(
45+
Twilio::Response.new(
46+
200,
47+
'{
48+
"next_page_uri": null,
49+
"messages": [{"body": "payload4"}]
50+
}'
51+
)
52+
)
53+
end
54+
55+
it 'streams all results' do
56+
actual = @client.messages.stream
57+
expect(actual.count).to eq(5)
58+
end
59+
60+
it 'limits results' do
61+
actual = @client.messages.stream(limit: 3)
62+
expect(actual.count).to eq(3)
63+
end
64+
end
65+
2466
it 'receives create responses' do
2567
@holodeck.mock(
2668
Twilio::Response.new(

spec/holodeck/holodeck.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def to_s
4040
ANY = Request.new(any: true)
4141

4242
def initialize
43-
@response = nil
43+
@responses = []
4444
@requests = []
4545
end
4646

4747
def mock(response)
48-
@response = response
48+
@responses << response
4949
end
5050

5151
def request(host, port, method, url, params = {}, data = {}, headers = {}, auth = nil, _timeout = nil)
@@ -57,7 +57,7 @@ def request(host, port, method, url, params = {}, data = {}, headers = {}, auth
5757
headers: headers,
5858
auth: auth
5959
)
60-
@response
60+
@responses.shift
6161
end
6262

6363
def has_request?(request)

0 commit comments

Comments
 (0)