Skip to content

Instantly share code, notes, and snippets.

@invisiblefunnel
Created May 9, 2014 20:59
Show Gist options
  • Select an option

  • Save invisiblefunnel/591fa9223f305fdbfe49 to your computer and use it in GitHub Desktop.

Select an option

Save invisiblefunnel/591fa9223f305fdbfe49 to your computer and use it in GitHub Desktop.
require 'spec_helper'
require 'geo_ruby/geojson'
describe "GeoJSON serialization" do
before do
@geometry = {"type"=>"Point", "coordinates"=>[102.0, 0.5]}
Georelevent::App.database.create_table? :birds do
primary_key :id
column :geom, :geometry
end
inbound = ->(v){ GeoRuby::GeojsonParser.new.send(:parse_geohash, v, GeoRuby::SimpleFeatures::DEFAULT_SRID).as_ewkt }
outbound = ->(v){ puts v;GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb(v).as_json.stringify_keys }
@c = Class.new(Sequel::Model(:birds)) do
plugin :serialization
serialize_attributes [inbound, outbound], :geom
end
Georelevent::App.database.sqls.clear
end
after do
Georelevent::App.database << 'DROP TABLE birds;'
end
it "should allow setting additional serializable attributes via plugin :serialization call" do
bird_id = @c.create(geom: @geometry).id
sql = Georelevent::App.database.sqls.join(' ')
expect(sql).to match /INSERT INTO \"birds\" \(\"geom\"\) VALUES \('SRID=4326;POINT\(102.0 0.5\)'\)/
bird = @c.first!(id: bird_id)
expect(bird.geom).to eq @geometry
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment