Permalink
Browse files

Merge pull request #48 from ericcj/master

make Parse::Object#as_json deep instead of giving you something partially as_json'ed and revert Date#to_s
  • Loading branch information...
2 parents e44b63a + bbd7364 commit 4f6607db9e0297d384b653d8f4bc19a5a52e7938 @adelevie committed Oct 10, 2012
Showing with 18 additions and 8 deletions.
  1. +0 −4 lib/parse/datatypes.rb
  2. +8 −2 lib/parse/object.rb
  3. +10 −2 test/test_object.rb
@@ -75,10 +75,6 @@ def <=>(other)
value <=> other.value
end
- def to_s
- value.to_s
- end
-
def method_missing(method, *args, &block)
if value.respond_to?(method)
value.send(method, *args, &block)
View
@@ -61,7 +61,7 @@ def parse(data)
def new?
self["objectId"].nil?
end
-
+
def safe_json
without_reserved = self.dup
Protocol::RESERVED_KEYS.each { |k| without_reserved.delete(k) }
@@ -103,7 +103,13 @@ def save
def as_json(*a)
Hash[self.map do |key, value|
- [key, value.nil? ? Protocol::DELETE_OP : value]
+ value = if value
+ value.respond_to?(:as_json) ? value.as_json : value
+ else
+ Protocol::DELETE_OP
+ end
+
+ [key, value]
end]
end
View
@@ -25,7 +25,7 @@ def test_object_id
end
def test_pointer
- VCR.use_cassette('test_pointer', :record => :new_episodes) do
+ VCR.use_cassette('test_pointer', :record => :new_episodes) do
post = Parse::Object.new "Post"
assert_nil post.pointer
@@ -89,11 +89,19 @@ def test_deep_parse
end
end
+ def test_deep_as_json
+ VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
+ other = Parse::Object.new "Post"
+ other['date'] = Parse::Date.new(DateTime.now)
+ assert other.as_json['date']['iso']
+ end
+ end
+
def test_nils_delete_keys
VCR.use_cassette('test_nils_delete_keys', :record => :new_episodes) do
post = Parse::Object.new "Post"
post["title"] = "hello"
- post.save
+ post.save
post["title"] = nil
post.save
assert_false post.refresh.keys.include?("title")

0 comments on commit 4f6607d

Please sign in to comment.