From 2d703ff5c4b3e38aa3ea6a8efda97cde42f5e33a Mon Sep 17 00:00:00 2001 From: Thierry Onkelinx Date: Mon, 17 Jun 2024 13:29:24 +0200 Subject: [PATCH] handle citation where the rightsholder are not set fixes #131 --- R/citation_meta_class.R | 15 ++++++++--- tests/testthat/test_d_update_citation.R | 34 ++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/R/citation_meta_class.R b/R/citation_meta_class.R index 6ff32c58..4f4145ac 100644 --- a/R/citation_meta_class.R +++ b/R/citation_meta_class.R @@ -173,13 +173,20 @@ validate_citation <- function(meta) { rightsholder_id <- roles$contributor[roles$role == "copyright holder"] funder_id <- roles$contributor[roles$role == "funder"] notes <- c( + "no rightsholder listed"[ + !is.na(org$get_rightsholder) && length(rightsholder_id) == 0 + ], + "no funder listed"[!is.na(org$get_funder) && length(funder_id) == 0], sprintf("rightsholder differs from `%s`", org$get_rightsholder)[ - !is.na(org$get_rightsholder) && - authors$given[authors$id == rightsholder_id] != org$get_rightsholder + !is.na(org$get_rightsholder) && length(rightsholder_id) >= 1 && + !any( + authors$given[authors$id %in% rightsholder_id] %in% + org$get_rightsholder + ) ], sprintf("funder differs from `%s`", org$get_funder)[ - !is.na(org$get_funder) && - authors$given[authors$id == funder_id] != org$get_funder + !is.na(org$get_funder) && length(funder_id) >= 1 && + !any(org$get_funder %in% authors$given[authors$id == funder_id]) ] ) errors <- c( diff --git a/tests/testthat/test_d_update_citation.R b/tests/testthat/test_d_update_citation.R index 24962a85..753ee733 100644 --- a/tests/testthat/test_d_update_citation.R +++ b/tests/testthat/test_d_update_citation.R @@ -47,13 +47,41 @@ test_that("update_citation() works", { ) writeLines(old_citation, path(path, package, "inst", "CITATION")) + org <- organisation$new() + this_description <- desc(path(path, package)) this_description$add_urls("https://doi.org/10.5281/zenodo.4028303") - org <- organisation$new() - this_description$del_author(org$get_rightsholder) + gsub("([\\(\\)])", "\\\\\\1", org$get_rightsholder) |> + this_description$del_author() + expect_equal(length(this_description$get_authors()), 1) + this_description$write(path(path, package)) + expect_is( + z <- update_citation(path(path, package), quiet = TRUE), "checklist" + ) + expect_equal( + z$.__enclos_env__$private$notes, + c("no rightsholder listed", "no funder listed") + ) this_description$add_author(given = "unit", family = "test", role = "ctb") this_description$add_author(given = "test", family = "unit", role = "cph") this_description$write(path(path, package)) file_delete(path(path, package, ".Rbuildignore")) - expect_is(update_citation(path(path, package), quiet = TRUE), "checklist") + expect_is( + z <- update_citation(path(path, package), quiet = TRUE), "checklist" + ) + expect_equal( + z$.__enclos_env__$private$notes, + c( + "no funder listed", + sprintf("rightsholder differs from `%s`", org$get_rightsholder) + ) + ) + new_org <- organisation$new( + email = NA_character_, funder = NA_character_, rightsholder = "test" + ) + write_organisation(new_org, path(path, package)) + expect_is( + z <- update_citation(path(path, package), quiet = TRUE), "checklist" + ) + expect_length(z$.__enclos_env__$private$notes, 0) })