Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 60 lines (48 sloc) 1.846 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
require 'helper'

class TestDatatypes < Test::Unit::TestCase
  def test_pointer
    data = {
      Parse::Protocol::KEY_CLASS_NAME => "DatatypeTestClass",
      Parse::Protocol::KEY_OBJECT_ID => "12345abcd"
    }
    p = Parse::Pointer.new data
    
    assert_equal p.to_json, "{\"__type\":\"Pointer\",\"#{Parse::Protocol::KEY_CLASS_NAME}\":\"DatatypeTestClass\",\"#{Parse::Protocol::KEY_OBJECT_ID}\":\"12345abcd\"}"
  end
  
  def test_date
    date_time = DateTime.now
    data = date_time
    parse_date = Parse::Date.new data
    
    assert_equal parse_date.value, date_time
    assert_equal JSON.parse(parse_date.to_json)["iso"], date_time.iso8601
  end
  
  def test_bytes
    data = {
      "base64" => Base64.encode64("testing bytes!")
    }
    byte = Parse::Bytes.new data

    assert_equal byte.value, "testing bytes!"
    assert_equal JSON.parse(byte.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_BYTES
    assert_equal JSON.parse(byte.to_json)["base64"], Base64.encode64("testing bytes!")
  end
  
  def test_increment
    amount = 5
    increment = Parse::Increment.new amount
    
    assert_equal increment.to_json, "{\"__op\":\"Increment\",\"amount\":#{amount}}"
  end
  
  def test_decrement
    amount = 5
    increment = Parse::Decrement.new amount
    
    assert_equal increment.to_json, "{\"__op\":\"Decrement\",\"amount\":#{amount}}"
  end
  
  def test_geopoint
    # '{"location": {"__type":"GeoPoint", "latitude":40.0, "longitude":-30.0}}'
    data = {
      "longitude" => 40.0,
      "latitude" => -30.0
    }
    gp = Parse::GeoPoint.new data
    
    assert_equal JSON.parse(gp.to_json)["longitude"], data["longitude"]
    assert_equal JSON.parse(gp.to_json)["latitude"], data["latitude"]
    assert_equal JSON.parse(gp.to_json)[Parse::Protocol::KEY_TYPE], Parse::Protocol::TYPE_GEOPOINT
  end
end
Something went wrong with that request. Please try again.