Skip to content

Commit

Permalink
Pulled out some shared specs to reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Pete Deffendol committed Sep 2, 2010
1 parent d0c3131 commit fadb564
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 81 deletions.
43 changes: 2 additions & 41 deletions spec/mysql/models_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples'
require 'spatial_adapter/mysql'
require 'db/mysql_raw'
require 'models/common'
Expand Down Expand Up @@ -59,46 +60,6 @@
end
end

describe "finding records" do
it 'should retrieve Point objects' do
model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
PointModel.find(model.id).geom.should == GeometryFactory.point
end

it 'should retrieve LineString objects' do
model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
end

it 'should retrieve Polygon objects' do
model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
end

it 'should retrieve MultiPoint objects' do
model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
end

it 'should retrieve MultiLineString objects' do
model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
end

it 'should retrieve MultiPolygon objects' do
model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
end

it 'should retrieve GeometryCollection objects' do
model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
end

it 'should retrieve Geometry objects' do
model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
GeometryModel.find(model.id).geom.should == GeometryFactory.point
end
end
include CommonModelActions
end

43 changes: 3 additions & 40 deletions spec/postgresql/models_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'shared_examples'
require 'spatial_adapter/postgresql'
require 'db/postgis_raw'
require 'models/common'
Expand Down Expand Up @@ -143,47 +144,9 @@
end
end

describe "finding records" do
it 'should retrieve Point objects' do
model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
PointModel.find(model.id).geom.should == GeometryFactory.point
end

it 'should retrieve LineString objects' do
model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
end

it 'should retrieve Polygon objects' do
model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
end

it 'should retrieve MultiPoint objects' do
model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
end

it 'should retrieve MultiLineString objects' do
model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
end

it 'should retrieve MultiPolygon objects' do
model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
end

it 'should retrieve GeometryCollection objects' do
model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
end

it 'should retrieve Geometry objects' do
model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
GeometryModel.find(model.id).geom.should == GeometryFactory.point
end
include CommonModelActions

describe "finding records" do
it 'should retrieve 3D Point (with Z coord) objects' do
model = PointzModel.create(:extra => 'test', :geom => GeometryFactory.pointz)
PointzModel.find(model.id).geom.should == GeometryFactory.pointz
Expand Down
43 changes: 43 additions & 0 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
share_as :CommonModelActions do
describe 'finding records' do
it 'should retrieve Point objects' do
model = PointModel.create(:extra => 'test', :geom => GeometryFactory.point)
PointModel.find(model.id).geom.should == GeometryFactory.point
end

it 'should retrieve LineString objects' do
model = LineStringModel.create(:extra => 'test', :geom => GeometryFactory.line_string)
LineStringModel.find(model.id).geom.should == GeometryFactory.line_string
end

it 'should retrieve Polygon objects' do
model = PolygonModel.create(:extra => 'test', :geom => GeometryFactory.polygon)
PolygonModel.find(model.id).geom.should == GeometryFactory.polygon
end

it 'should retrieve MultiPoint objects' do
model = MultiPointModel.create(:extra => 'test', :geom => GeometryFactory.multi_point)
MultiPointModel.find(model.id).geom.should == GeometryFactory.multi_point
end

it 'should retrieve MultiLineString objects' do
model = MultiLineStringModel.create(:extra => 'test', :geom => GeometryFactory.multi_line_string)
MultiLineStringModel.find(model.id).geom.should == GeometryFactory.multi_line_string
end

it 'should retrieve MultiPolygon objects' do
model = MultiPolygonModel.create(:extra => 'test', :geom => GeometryFactory.multi_polygon)
MultiPolygonModel.find(model.id).geom.should == GeometryFactory.multi_polygon
end

it 'should retrieve GeometryCollection objects' do
model = GeometryCollectionModel.create(:extra => 'test', :geom => GeometryFactory.geometry_collection)
GeometryCollectionModel.find(model.id).geom.should == GeometryFactory.geometry_collection
end

it 'should retrieve Geometry objects' do
model = GeometryModel.create(:extra => 'test', :geom => GeometryFactory.point)
GeometryModel.find(model.id).geom.should == GeometryFactory.point
end
end
end

0 comments on commit fadb564

Please sign in to comment.