Permalink
Browse files

Adding JSON oj support, for max performance parsing JSON

  • Loading branch information...
1 parent 11201fa commit 3e12e051060a389e4d5c5606879a916804d94c2b @samlown samlown committed Sep 15, 2012
Showing with 10 additions and 2 deletions.
  1. +1 −0 couchrest_model.gemspec
  2. +1 −0 history.md
  3. +4 −1 lib/couchrest/model/typecast.rb
  4. +1 −0 spec/spec_helper.rb
  5. +3 −1 spec/unit/base_spec.rb
View
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
s.add_dependency(%q<mime-types>, "~> 1.15")
s.add_dependency(%q<activemodel>, "~> 3.0")
s.add_dependency(%q<tzinfo>, "~> 0.3.22")
+ s.add_development_dependency(%q<oj>, "~> 1.3.4")
s.add_development_dependency(%q<rspec>, "~> 2.6.0")
s.add_development_dependency(%q<json>, ["~> 1.5.1"])
s.add_development_dependency(%q<rack-test>, ">= 0.5.7")
View
@@ -11,6 +11,7 @@
* Modified associations to use allow_blank property
* Incorported Rails 3.2 support changes (Thanks @jodosha)
* Kaminari support upgraded to use 0.14.0 API (Thanks @amatsuda)
+ * JSON Oj support, fixed some Time handling issues
## 1.2.0.beta - 2012-06-08
@@ -106,7 +106,10 @@ def typecast_to_date(value)
# Typecasts an arbitrary value to a Time
# Handles both Hashes and Time instances.
def typecast_to_time(value)
- if value.is_a?(Hash)
+ case value
+ when Float # JSON oj already parses Time, FTW.
+ Time.at(value).utc
+ when Hash
typecast_hash_to_time(value)
else
Time.parse_iso8601(value.to_s)
View
@@ -5,6 +5,7 @@
require "rubygems"
require "rspec"
+require 'oj'
require 'couchrest_model'
unless defined?(FIXTURE_PATH)
View
@@ -469,6 +469,7 @@ def set_name; self.name = "foobar"; end
it "should define the updated_at and created_at getters and set the values" do
@obj.save
+ json = @obj.to_json
obj = WithDefaultValues.get(@obj.id)
obj.should be_an_instance_of(WithDefaultValues)
obj.created_at.should be_an_instance_of(Time)
@@ -487,7 +488,8 @@ def set_name; self.name = "foobar"; end
it "should set the time on create" do
(Time.now - @art.created_at).should < 2
foundart = Article.get @art.id
- foundart.created_at.should == foundart.updated_at
+ # Use string for comparison to cope with microsecond differences
+ foundart.created_at.to_s.should == foundart.updated_at.to_s
end
it "should set the time on update" do
@art.title = "new title" # only saved if @art.changed? == true

0 comments on commit 3e12e05

Please sign in to comment.