Skip to content

Commit

Permalink
Fix for breaking API change in jsonlite 0.9.22. See jeroen/jsonlite#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
Neal Richardson committed Jun 15, 2016
1 parent a7277b0 commit 48012c2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
@@ -1,6 +1,7 @@
### crunch 1.10.3 (under development)
* Fix `as.data.frame`/`as.environment` for `CrunchDataset` when a variable alias contained an apostrophe.
* Better print method for project `MemberCatalog`.
* Fix for [change in 'jsonlite' API](https://github.com/jeroenooms/jsonlite/issues/130#issuecomment-225971209) in its v0.9.22

### crunch 1.10.2
* `exportDataset` to download a CSV or SAV file of a dataset. `write.csv` convenience method for CSV export.
Expand Down
1 change: 1 addition & 0 deletions R/json.R
Expand Up @@ -38,6 +38,7 @@ setMethod("jsonprep", "OrderGroup", .jsonprep.ordergroup)
##' @rdname tojson-crunch
##' @export
toJSON <- function (x, ...) {
if (is.null(x)) return(jsonlite::toJSON(emptyObject()))
out <- jsonlite::toJSON(jsonprep(x), auto_unbox=TRUE, null="null", na="null", force=TRUE, ...)
# cat(out)
return(out)
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-active-filter.R
Expand Up @@ -8,6 +8,9 @@ with_mock_HTTP({
test_that("A clean dataset has NULL activeFilter", {
expect_null(activeFilter(ds))
})
test_that("A null filter becomes valid JSON", {
expect_equal(unclass(toJSON(zcl(activeFilter(ds)))), "{}")
})
test_that("Getting a variable from a clean dataset has NULL activeFilter", {
expect_null(activeFilter(ds$gender))
})
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-misc.R
Expand Up @@ -90,6 +90,11 @@ test_that("null function always returns null", {
expect_null(null(stop("yo!")))
})

test_that("JSON behavior for NULL (handle jsonlite API change in 0.9.22)", {
expect_equal(unclass(toJSON(NULL)), "{}")
expect_equal(unclass(toJSON(list(x=NULL))), '{"x":null}')
})

test_that("setIfNotAlready", {
with(temp.options(crunch.test.opt1="previous",
crunch.test.opt2=NULL,
Expand Down

0 comments on commit 48012c2

Please sign in to comment.