Sha256: 4363f7e34d997b7ecd6785c8e399148366ba7e4116a731c3eceb40c2be2e949e

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require File.join File.dirname(__FILE__), 'env.rb'

include CartoJson

describe CartoJson::Circle do
  before do
    @args = {LAT => 45.52, LNG => -122.681944, :radius => 500}
  end

  it 'should create a circle with valid data' do

    circle = Circle.new @args
    circle.is_a?(Circle).must_equal true
    circle.type.must_equal :circle
    circle.class.type.must_equal :circle

    hash = MultiJson.decode(circle.to_json, :symbolize_keys => true)

    hash[:center][LAT].must_equal @args[LAT]
    hash[:center][LNG].must_equal @args[LNG]
    hash[:radius].must_equal @args[:radius]
  end

  it 'should fail with negative radius' do
    lambda {
      Circle.new @args.merge(:radius => -40)
    }.must_raise CartoJson::InvalidRadiusError
  end

  it 'should fail with crazy lat and lng' do
    lambda {
      Circle.new @args.merge(LAT => -31337)
    }.must_raise CartoJson::InputError

    lambda {
      Circle.new @args.merge(LNG => -31337)
    }.must_raise CartoJson::InputError
  end

  it 'fails for wkt' do
    lambda { Circle.new(@args).to_wkt }.must_raise CartoJson::NotImplementedError
  end

  it 'converts to point' do
    p = Circle.new(@args).to_point
    @args.delete :radius

    np = Point.new(@args)
    p.send(LAT).must_equal np.send(LAT)
    p.send(LNG).must_equal np.send(LNG)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carto_json-0.0.6 spec/circle_spec.rb