Sha256: 739fab67308ed3212204e1c7405f926ea0b2d5241db84b9e3526556c27a1dd6b

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 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[LAT].must_equal @args[LAT]
    hash[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.7 spec/circle_spec.rb