Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #162 from tombuckley/patch-simple-username-check
Browse files Browse the repository at this point in the history
verify no spaces in usernames for get_favorites
  • Loading branch information
mkearney authored Jan 1, 2018
2 parents d6b881d + 84bf297 commit 7f3a756
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/favorites.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ get_favorites_call <- function(user,
token <- check_token(token)
}
## check inputs
stopifnot(is.atomic(user), is.numeric(n))
stopifnot(is.atomic(user), is.numeric(n), sapply(user, is.valid.username))
if (length(user) == 0L) {
stop("No user found", call. = FALSE)
}
Expand Down
4 changes: 4 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -563,3 +563,7 @@ obs2string <- function(x, sep) {
x[is.na(x)] <- ""
paste(x, collapse = sep)
}

is.valid.username <- function(username) {
!grepl(' ', username);
}
6 changes: 6 additions & 0 deletions tests/testthat/test_get_favorites.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ test_that("get_favorites returns tweets data", {
expect_gt(ncol(users_data(x)), 15)
expect_named(users_data(x))
})

test_that("get_favorites throws an error if usernames have spaces in them", {
n <- 2
token <- readRDS("twitter_tokens")
expect_error(get_favorites(c("elonmusk","elon musk"), n=n))
})

0 comments on commit 7f3a756

Please sign in to comment.