Skip to content

Commit ea54c01

Browse files
toph-allengithub-actions[bot]nealrichardson
authored
chore: adjust page_offset() to always respect limit (#472)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Neal Richardson <neal.p.richardson@gmail.com>
1 parent 787eeed commit ea54c01

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

R/page.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ page_offset <- function(client, req, limit = Inf) {
9393
new_expr <- NULL
9494
new_req <- NULL
9595
}
96-
return(agg_response)
96+
# Make sure we never return more than `limit` records
97+
head(agg_response, limit)
9798
}
9899

99100
optional_progress_bar <- function(...) {
@@ -102,8 +103,7 @@ optional_progress_bar <- function(...) {
102103
} else {
103104
# Return a mock object that behaves enough like a progress bar object
104105
list(
105-
tick = function() {
106-
}
106+
tick = function() {}
107107
)
108108
}
109109
}

tests/testthat/2025.09.0/__api__/v1/search/content-d37a6d.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Used in test-content.R
1+
// Used in test-content.R and test-page.R
22
{
3-
"total": 3,
3+
"total": 4,
44
"current_page": 1,
55
"results": [
66
{
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
// Used in test-content.R
1+
// Used in test-content.R and test-page.R
22
{
3-
"total": 3,
3+
"total": 4,
44
"current_page": 2,
55
"results": [
66
{
77
"guid": "abc12345",
88
"name": "blobfish-report",
99
"title": "blobfish report"
10+
},
11+
{
12+
"guid": "abc12346",
13+
"name": "blobfish-report-final",
14+
"title": "blobfish report (v2)"
1015
}
1116
]
12-
}
17+
}

tests/testthat/test-content.R

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,15 @@ with_mock_dir("2025.09.0", {
493493

494494
test_that("content search fetches multiple pages correctly", {
495495
res <- search_content(client, q = "blobfish")
496-
expect_equal(length(res), 3)
496+
expect_equal(length(res), 4)
497497
expect_equal(
498498
purrr::map_chr(res, list("content", "title")),
499-
c("blobfish dashboard", "blobfish api", "blobfish report")
499+
c(
500+
"blobfish dashboard",
501+
"blobfish api",
502+
"blobfish report",
503+
"blobfish report (v2)"
504+
)
500505
)
501506
})
502507

tests/testthat/test-page.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
with_mock_dir("2025.09.0", {
2+
client <- Connect$new(
3+
server = "https://connect.example",
4+
api_key = "not-a-key"
5+
)
6+
7+
test_that("page_offset respects a specified 'limit' ", {
8+
# These mocks return four results across two pages.
9+
res <- search_content(client, q = "blobfish", limit = 3)
10+
expect_equal(length(res), 3)
11+
expect_equal(
12+
purrr::map_chr(res, list("content", "title")),
13+
c("blobfish dashboard", "blobfish api", "blobfish report")
14+
)
15+
})
16+
})

0 commit comments

Comments
 (0)