diff options
-rw-r--r-- | ext/ffi_yajl/ext/encoder/encoder.c | 12 | ||||
-rw-r--r-- | spec/ffi_yajl/json_gem_spec.rb | 7 |
2 files changed, 7 insertions, 12 deletions
diff --git a/ext/ffi_yajl/ext/encoder/encoder.c b/ext/ffi_yajl/ext/encoder/encoder.c index ade2199..004a11b 100644 --- a/ext/ffi_yajl/ext/encoder/encoder.c +++ b/ext/ffi_yajl/ext/encoder/encoder.c @@ -139,11 +139,13 @@ static VALUE rb_cString_ffi_yajl(VALUE self, VALUE yajl_gen, VALUE state) { return Qnil; } -// FIXME: args is a splat/varargs, does it matter? and what about the block? static VALUE rb_cObject_to_json(VALUE self, VALUE args) { - // FIXME: need to wrap quotes around this + // FIXME: probably a bit too honeybadger about ignoring the arity of this function completely + ID sym_to_s = rb_intern("to_s"); VALUE str; - str = rb_any_to_s(self); + + str = rb_funcall(self, sym_to_s, 0); + str = rb_str_concat(rb_str_concat(rb_str_new2("\""), str), rb_str_new2("\"")); return str; } @@ -171,8 +173,8 @@ void Init_encoder() { rb_define_method(rb_cBignum, "ffi_yajl", rb_cBignum_ffi_yajl, 2); rb_define_method(rb_cFloat, "ffi_yajl", rb_cFloat_ffi_yajl, 2); rb_define_method(rb_cString, "ffi_yajl", rb_cString_ffi_yajl, 2); -// FIXME: make this conditional on ActiveSupport not being defined: - rb_define_method(rb_cObject, "to_json", rb_cObject_to_json, 1); rb_define_method(rb_cObject, "ffi_yajl", rb_cObject_ffi_yajl, 2); +// FIXME: make this conditional on ActiveSupport not being defined: + rb_define_method(rb_cObject, "to_json", rb_cObject_to_json, -2); } diff --git a/spec/ffi_yajl/json_gem_spec.rb b/spec/ffi_yajl/json_gem_spec.rb index 8d23d07..7d290c4 100644 --- a/spec/ffi_yajl/json_gem_spec.rb +++ b/spec/ffi_yajl/json_gem_spec.rb @@ -127,31 +127,26 @@ describe "JSON Gem Compat API" do context "when encode arbitrary classes via their default to_json method" do it "encodes random classes correctly" do - pending "FIXME (native extension only)" d = Dummy.new expect(d.to_json).to eq( %Q{"#{d.to_s}"} ) end it "encodes Time values correctly" do - pending "FIXME (native extension only)" t = Time.new expect(t.to_json).to eq( %Q{"#{t.to_s}"} ) end it "encodes Date values correctly" do - pending "FIXME (native extension only)" da = Date.new expect(da.to_json).to eq( %Q{"#{da.to_s}"} ) end it "encodes DateTime values correctly" do - pending "FIXME (native extension only)" dt = DateTime.new expect(dt.to_json).to eq( %Q{"#{dt.to_s}"} ) end it "and DateTime's are really ISO8601s" do - pending "FIXME (native extension only)" dt = DateTime.new expect(dt.to_json).to eq( %Q{"#{dt.iso8601}"} ) end @@ -171,7 +166,6 @@ describe "JSON Gem Compat API" do expect{ JSON.parse("blah") }.to raise_error(JSON::ParserError) end it "should raise JSON::GeneratorError on encoding NaN" do - pending "FIXME (native extension only)" expect{ JSON.generate(0.0/0.0) }.to raise_error(JSON::GeneratorError) end it "should raise JSON::GeneratorError on encoding a partial UTF-8 character" do @@ -193,7 +187,6 @@ describe "JSON Gem Compat API" do context "when encoding strings" do it "should render empty string correctly" do - pending "FIXME (native extension only)" expect(''.to_json).to eq( %q{""} ) end it "should encode backspace character" do |