Skip to content

Commit

Permalink
Merge pull request #121 from mzsanford/ruby_2_1_to_h
Browse files Browse the repository at this point in the history
Add Ruby 2.1 testing and Ruby 2.1 support
  • Loading branch information
adelevie committed Mar 12, 2014
2 parents 4a5f933 + 6ad2fcc commit 086ed88
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -4,4 +4,6 @@ pkg
lib/.DS_Store
lib/parse/.DS_Store

test/cloud_functions/MyCloudCode/config/global.json
.bundle

test/cloud_functions/MyCloudCode/config/global.json
3 changes: 2 additions & 1 deletion .travis.yml
@@ -1,9 +1,10 @@
language: ruby
rvm:
- 2.1.0
- 2.0.0
- 1.9.3
- 1.9.2
- jruby-19mode

env:
- PARSE_APPLICATION_ID=Slw1ACyMSVguo79pWvfIq15pkUjfwTLNPpL4984b PARSE_REST_API_KEY=qJKM8CGOAn70WOyR16f16YbyKWM0nBJCEbbtAMOm
- PARSE_APPLICATION_ID=Slw1ACyMSVguo79pWvfIq15pkUjfwTLNPpL4984b PARSE_REST_API_KEY=qJKM8CGOAn70WOyR16f16YbyKWM0nBJCEbbtAMOm
7 changes: 6 additions & 1 deletion lib/parse/object.rb
Expand Up @@ -95,9 +95,14 @@ def rest_api_hash
self.merge(Parse::Protocol::KEY_CLASS_NAME => class_name)
end

# Handle the addition of Array#to_h in Ruby 2.1
def should_call_to_h?(value)
value.respond_to?(:to_h) && !value.kind_of?(Array)
end

def to_h(*a)
Hash[rest_api_hash.map do |key, value|
[key, value.respond_to?(:to_h) ? value.to_h : value]
[key, should_call_to_h?(value) ? value.to_h : value]
end]
end
alias :as_json :to_h
Expand Down
9 changes: 9 additions & 0 deletions test/test_object.rb
Expand Up @@ -132,6 +132,15 @@ def test_deep_as_json
end
end

def test_deep_as_json_with_array
VCR.use_cassette('test_deep_as_json', :record => :new_episodes) do
other = Parse::Object.new "Post"
other['date'] = Parse::Date.new(DateTime.now)
other['array'] = [1, 2]
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"
Expand Down

0 comments on commit 086ed88

Please sign in to comment.