Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed test for empty json in getContentAsDataFrame() #97

Merged
merged 11 commits into from
Sep 8, 2016
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
# See README.md for instructions, or for more configuration options,
# see the wiki:
# http://docs.travis-ci.com/user/languages/r/
sudo: false

language: r
cache: packages
r:
- oldrel
- release
- devel

language: R
sudo: required
warnings_are_errors: true

before_script:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Description: Provides easier interaction with
format and manages throttling by 'Socrata'.
Users can upload data to Socrata portals directly
from R.
Version: 1.7.1-10
Date: 2016-03-11
Version: 1.7.1-13
Date: 2016-09-07
Author: Hugh Devlin, Ph. D., Tom Schenk, Jr., and John Malc
Maintainer: "Tom Schenk Jr." <developers@cityofchicago.org>
Depends:
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ Bug fixes:
* Fixes bug where dates are incorrectly read when first date is a blank ([#68](https://github.com/Chicago/RSocrata/issues/68))
* Dates are now handled using `POSIXct` instead of `POSIXlt` ([#8](https://github.com/Chicago/RSocrata/issues/8))
* Added additional unit testing ([#28](https://github.com/Chicago/RSocrata/issues/68))
* Artifacts from Appveyor CI can now be directly submitted to CRAN ([#77](https://github.com/Chicago/RSocrata/issues/77))
* Artifacts from Appveyor CI can now be directly submitted to CRAN ([#77](https://github.com/Chicago/RSocrata/issues/77))
* Fixed issue where JSON may occasionally come back with a final NULL that is not "[]" (in this example it was "[]\n"). This caused `getDataFrame` to get stuckin an infinite loop while waiting for "[]". Thank you @kevinsmgov for documenting this bug in issue ([#96](https://github.com/Chicago/RSocrata/issues/96))

3 changes: 1 addition & 2 deletions R/RSocrata.R
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ getContentAsDataFrame <- function(response) {
encoding = "utf-8")),
stringsAsFactors = FALSE), # automatic parsing
'application/json' =
if(httr::content(response,
as = 'text') == "[ ]") # empty json?
if(length(httr::content(response)) == 0) # empty json?
data.frame() # empty data frame
else
data.frame(t(sapply(httr::content(response), unlist)),
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-all.R
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,25 @@ test_that("fully replace a dataset", {
expect_equal(df_in$x, as.numeric(df_out$x), label = "x values")
expect_equal(df_in$y, as.numeric(df_out$y), label = "y values")
})


context("getContentAsDataFrame")

test_that("getContentAsDataFrame does not get caught in infinite loop", {

## This is the original url suggested, but it causes the rbind issue
# u <- paste0("https://data.smgov.net/resource/xx64-wi4x.json?$",
# "select=incident_number,incident_date,call_type,received_time,",
# "cleared_time,census_tract_2010_geoid",
# "&$where=incident_date=%272016-08-21%27")

## This request has been modified to avoid the rbind issue
u <- paste0("https://data.smgov.net/resource/xx64-wi4x.json?$",
"select=incident_number,incident_date,call_type,received_time,",
"cleared_time,census_tract_2010_geoid",
"&$where=incident_date=%272016-08-27%27%20and%20",
"census_tract_2010_geoid%20is%20not%20null")
df <- read.socrata(u)
expect_equal("data.frame", class(df), label="class")
})