Sha256: 83a5a77f5c57bb73450f5af82d2ce36257d2e1df5b0cc2e87a3fb0051f7643fe

Contents?: true

Size: 1.4 KB

Versions: 35

Compression:

Stored size: 1.4 KB

Contents

require 'core/spec_helper'

describe ZendeskAPI::Middleware::Response::ParseIsoDates do
  def fake_response(data)
    stub_json_request(:get, %r{blergh}, data)
    response = client.connection.get("blergh")
    expect(response.status).to eq(200)
    response
  end

  let(:parsed){
    if RUBY_VERSION > "1.9"
      "2012-02-01 13:14:15 UTC"
    else
      "Wed Feb 01 13:14:15 UTC 2012"
    end
  }

  it "should parse dates" do
    expect(fake_response('{"x":"2012-02-01T13:14:15Z"}').body["x"].to_s).to eq(parsed)
  end

  it "should parse nested dates in hash" do
    expect(fake_response('{"x":{"y":"2012-02-01T13:14:15Z"}}').body["x"]["y"].to_s).to eq(parsed)
  end

  it "should parse nested dates in arrays" do
    expect(fake_response('{"x":[{"y":"2012-02-01T13:14:15Z"}]}').body["x"][0]["y"].to_s).to eq(parsed)
  end

  it "should not blow up on empty body" do
    expect(fake_response('').body).to eq('')
  end

  it "should leave arrays with ids alone" do
    expect(fake_response('{"x":[1,2,3]}').body).to eq({"x" => [1,2,3]})
  end

  it "should not parse date-like things" do
    expect(fake_response('{"x":"2012-02-01T13:14:15Z bla"}').body["x"].to_s).to eq("2012-02-01T13:14:15Z bla")
    expect(fake_response('{"x":"12012-02-01T13:14:15Z"}').body["x"].to_s).to eq("12012-02-01T13:14:15Z")
    expect(fake_response(%Q{{"x":"2012-02-01T13:14:15Z\\nfoo"}}).body["x"].to_s).to eq("2012-02-01T13:14:15Z\nfoo")
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
zendesk_api-1.13.1 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.12.1 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.12.0 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.7 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.6 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.5 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.4 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.3 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.2 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.1 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.11.0 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.10.0 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.6 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.5 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.4 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.3 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.2 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.1 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.9.0 spec/core/middleware/response/parse_iso_dates_spec.rb
zendesk_api-1.8.0 spec/core/middleware/response/parse_iso_dates_spec.rb