Sha256: a965865769dcef7f47b5a63d74278202ded48dcaba7b3ca243b2b0ab35b14bbb

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

describe Mongoid::Geospatial::LineString do
  describe '(de)mongoize' do
    it 'should support a field mapped as linestring' do
      river = River.new(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
      expect(river.course).to be_a Mongoid::Geospatial::LineString
      expect(river.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
    end

    it 'should update line string too' do
      river = River.create!(name: 'Amazonas')
      river.course = [[1, 1], [1, 1], [9, 9], [9, 9]]
      river.save
      expect(River.first.course).to eq(river.course)
    end

    it 'should support a field mapped as linestring' do
      River.create!(course: [[5, 5], [6, 5], [6, 6], [5, 6]])
      expect(River.first.course).to eq([[5, 5], [6, 5], [6, 6], [5, 6]])
    end

    it 'should have a bounding box' do
      geom = Mongoid::Geospatial::LineString.new [[1, 5], [6, 5], [6, 6], [5, 6]]
      expect(geom.bbox).to eq([[1, 5], [6, 6]])
    end

    it 'should have a center point' do
      geom = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
      expect(geom.center).to eq([5.0, 5.0])
    end

    it 'should have a radius helper' do
      geom = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
      expect(geom.radius(10)).to eq([[5.0, 5.0], 10])
    end

    it 'should have a radius sphere' do
      geom = Mongoid::Geospatial::LineString.new [[1, 1], [1, 1], [9, 9], [9, 9]]
      expect(geom.radius_sphere(10)[1]).to be_within(0.001).of(0.001569)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid-geospatial-4.0.1 spec/mongoid/geospatial/fields/line_string_spec.rb