Sha256: 0a622ffd1ab424409aab9b90c053b44d8a82fcee4fb019740c73b09c82a1d73d

Contents?: true

Size: 1.27 KB

Versions: 15

Compression:

Stored size: 1.27 KB

Contents

require "spec_helper"

describe DataMapper::Property::ParseGeoPoint do
  subject { property }

  let(:property) { User.properties[:location] }

  describe "#dump" do
    subject { property.dump value }

    let(:value) { { "lat" => "20", "lng" => "50" } }

    it { should eq("__type" => "GeoPoint", "latitude" => value["lat"].to_f, "longitude" => value["lng"].to_f) }

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end
  end

  describe "#load" do
    subject { property.load value }

    let(:value) { { "__type" => "GeoPoint", "latitude" => 20.0, "longitude" => 50.0 } }

    it { should eq("lat" => value["latitude"], "lng" => value["longitude"]) }

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end
  end

  describe "#valid?" do
    subject { property.valid? value }

    let(:value) { { "lat" => lat, "lng" => lng } }
    let(:lat)   { "20.0" }
    let(:lng)   { "50.0" }

    it { should be_true }

    context "when lat is nil" do
      let(:lat) { nil }

      it { should be_false }
    end

    context "when lng is nil" do
      let(:lng) { nil }

      it { should be_false }
    end

    context "when value is nil" do
      let(:value) { nil }

      it { should be_true }
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dm-parse-0.3.10 spec/parse_geo_point_spec.rb
dm-parse-0.3.9 spec/parse_geo_point_spec.rb
dm-parse-0.3.8 spec/parse_geo_point_spec.rb
dm-parse-0.3.7 spec/parse_geo_point_spec.rb
dm-parse-0.3.6 spec/parse_geo_point_spec.rb
dm-parse-0.3.5 spec/parse_geo_point_spec.rb
dm-parse-0.3.4 spec/parse_geo_point_spec.rb
dm-parse-0.3.3 spec/parse_geo_point_spec.rb
dm-parse-0.3.2 spec/parse_geo_point_spec.rb
dm-parse-0.3.1 spec/parse_geo_point_spec.rb
dm-parse-0.3.0 spec/parse_geo_point_spec.rb
dm-parse-0.2.3 spec/parse_geo_point_spec.rb
dm-parse-0.2.2 spec/parse_geo_point_spec.rb
dm-parse-0.2.1 spec/parse_geo_point_spec.rb
dm-parse-0.2.0 spec/parse_geo_point_spec.rb