Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 1f814da

Browse files
author
Thai Xuan + Duc Pham
committed
[b] Fix looping bug when load paginated results
1 parent 5629a34 commit 1f814da

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/microsoft_graph/collection_association.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def <<(new_member)
159159

160160
def each(start = 0)
161161
return to_enum(:each, start) unless block_given?
162-
@next_link = query_path
162+
@next_link ||= query_path
163163
Array(@internal_values[start..-1]).each do |element|
164164
yield(element)
165165
end
@@ -207,6 +207,8 @@ def fetch_next_page
207207
end
208208
end
209209
@next_link = result[:attributes]['@odata.next_link']
210+
@next_link.sub!(MicrosoftGraph::BASE_URL, "") if @next_link
211+
210212
result[:attributes]['value'].each do |entity_hash|
211213
klass =
212214
if member_type = specified_member_type(entity_hash)
@@ -216,7 +218,7 @@ def fetch_next_page
216218
end
217219
@internal_values.push klass.new(attributes: entity_hash, parent: self, persisted: true)
218220
end
219-
@loaded = result[:attributes]['@odata.next_link'].nil?
221+
@loaded = @next_link.nil?
220222
end
221223

222224
def default_member_class

spec/microsoft_graph/collection_association_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@
183183
]
184184
}
185185
stub_request(:get, "https://graph.microsoft.com/v1.0/users/USER123/calendars")
186-
.to_return({ body: first_page_body.to_json }).times(1).then
186+
.to_return({ body: first_page_body.to_json }).times(1)
187+
stub_request(:get, "https://graph.microsoft.com/v1.0/users/USER123/calendars?$skip=1")
187188
.to_return({ body: second_page_body.to_json }).times(1)
188189
end
189190
Given(:me) { graph.me }

0 commit comments

Comments
 (0)