Skip to content

Commit

Permalink
handle citation where the rightsholder are not set
Browse files Browse the repository at this point in the history
fixes #131
  • Loading branch information
ThierryO committed Jun 17, 2024
1 parent 0828fcb commit 2d703ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
15 changes: 11 additions & 4 deletions R/citation_meta_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
34 changes: 31 additions & 3 deletions tests/testthat/test_d_update_citation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 2d703ff

Please sign in to comment.