summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-08-11 09:07:25 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-08-23 11:16:14 -0700
commit5d35f31762750169569eb5ae9ce51b9af8a91793 (patch)
tree1f23d0cd156fc05791bc16d9d105868477c189b2 /spec
parent3759f4e96d3800260e3d942dd225867c13e78b33 (diff)
downloadffi-yajl-5d35f31762750169569eb5ae9ce51b9af8a91793.tar.gz
add datetime encoding
necessary for ohai json_gem spec complies with JSON gem format. this also arguably fixes issues with yajl-ruby where it does not encode date objects correctly.
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/encoder_spec.rb15
-rw-r--r--spec/ffi_yajl/json_gem_spec.rb14
2 files changed, 21 insertions, 8 deletions
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index 67945e0..969481a 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -60,4 +60,19 @@ describe "FFI_Yajl::Encoder" do
end
end
+ it "can encode Date objects" do
+ ruby = Date.parse('2001-02-03')
+ expect(encoder.encode(ruby)).to eq( %q{"2001-02-03"} )
+ end
+
+ it "can encode Time objects" do
+ ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
+ expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 13:05:06 -0800"} )
+ end
+
+ it "can encode DateTime objects" do
+ ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00')
+ expect(encoder.encode(ruby)).to eq( %q{"2001-02-03T04:05:06+07:00"} )
+ end
+
end
diff --git a/spec/ffi_yajl/json_gem_spec.rb b/spec/ffi_yajl/json_gem_spec.rb
index 36233eb..bfb9e2b 100644
--- a/spec/ffi_yajl/json_gem_spec.rb
+++ b/spec/ffi_yajl/json_gem_spec.rb
@@ -149,18 +149,18 @@ describe "JSON Gem Compat API" do
end
it "encodes Time values correctly" do
- t = Time.new
- expect(t.to_json).to eq( %Q{"#{t.to_s}"} )
+ t = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
+ expect(t.to_json).to eq( %Q{"2001-02-02 13:05:06 -0800"} )
end
it "encodes Date values correctly" do
- da = Date.new
- expect(da.to_json).to eq( %Q{"#{da.to_s}"} )
+ da = Date.parse('2001-02-03')
+ expect(da.to_json).to eq( %Q{"2001-02-03"} )
end
it "encodes DateTime values correctly" do
- dt = DateTime.new
- expect(dt.to_json).to eq( %Q{"#{dt.to_s}"} )
+ dt = DateTime.parse('2001-02-03T04:05:06.1+07:00')
+ expect(dt.to_json).to eq( %Q{"2001-02-03T04:05:06+07:00"} )
end
end
@@ -230,7 +230,6 @@ describe "JSON Gem Compat API" do
it_behaves_like "handles encoding and parsing correctly"
end
-
context "when dealing with common UTF-8 symbols" do
let(:ruby) { [ "© ≠ €! \01" ] }
let(:json) { "[\"© ≠ €! \\u0001\"]" }
@@ -277,7 +276,6 @@ describe "JSON Gem Compat API" do
end
end
-
context "when encoding basic types with #to_json" do
it "Array#to_json should work" do
expect([ "a", "b", "c" ].to_json).to eq(%Q{["a","b","c"]})