Skip to content

Commit

Permalink
Merge pull request #156 from bcgov/search-print
Browse files Browse the repository at this point in the history
record_list no longer fails when a record has no resources. Closes #128
  • Loading branch information
ateucher authored Dec 13, 2019
2 parents e81c926 + 29e7485 commit 8d42ea3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions R/utils-classes.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ print.bcdc_recordlist <- function(x, ...) {
cat("\nTitles:\n")
x <- purrr::set_names(x, NULL)
cat(paste(purrr::imap(x[1:n_print], ~ {

if (!nrow(bcdc_tidy_resources(x[[.y]]))) {
return(paste0(.y, ": ",purrr::pluck(.x, "title"),
col_red("\n This record has no resources. bcdata will not be able to access any data."),
"\n ID: ", purrr::pluck(.x, "id"),
"\n Name: ", purrr::pluck(.x, "name")))
}

paste0(
.y, ": ",purrr::pluck(.x, "title"),
" (",
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-search.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2019 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.

context('test bcdc_search')


test_that('works with a record that has no resource', {
skip_on_cran()
skip_if_net_down()
output_path <- tempfile()
suppressWarnings(
verify_output(output_path, {
bcdc_search("Major Railways")
})
)
expect_false(any(grepl("Error", readLines(output_path))))
expect_true(any(grepl("no resources", readLines(output_path))))
})

0 comments on commit 8d42ea3

Please sign in to comment.