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

Commit 05be5fb

Browse files
author
Caitlin Bales (MSFT)
authored
Merge pull request #2 from thaixuannguyen/master
[b] Fix looping bug when load paginated results
2 parents 12deaab + 1f814da commit 05be5fb

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
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

microsoft_graph.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ Gem::Specification.new do |spec|
2727
spec.add_development_dependency "simplecov", "~> 0.11.1"
2828
spec.add_development_dependency "webmock", "~> 1.22.6"
2929

30-
spec.add_dependency "nokogiri", "~> 1.6.7.1"
30+
spec.add_dependency "nokogiri", "~> 1.6.7"
3131
end

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)