Class: ActiveRecord::ConnectionAdapters::PostGIS::SpatialColumnAssertion

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgis/test_helpers.rb

Overview

Chainable spatial column assertion class

Instance Method Summary collapse

Constructor Details

#initialize(geometry, test_case, msg_prefix = nil) ⇒ SpatialColumnAssertion



127
128
129
130
131
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 127

def initialize(geometry, test_case, msg_prefix = nil)
  @geometry = geometry
  @test_case = test_case
  @msg_prefix = msg_prefix
end

Instance Method Details

#has_mObject



140
141
142
143
144
145
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 140

def has_m
  msg = build_message("to have M dimension")
  has_m = detect_has_m(@geometry)
  @test_case.assert has_m, msg
  self
end

#has_srid(expected_srid) ⇒ Object



147
148
149
150
151
152
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 147

def has_srid(expected_srid)
  msg = build_message("to have SRID #{expected_srid}")
  actual_srid = @geometry.srid
  @test_case.assert_equal expected_srid, actual_srid, msg
  self
end

#has_zObject



133
134
135
136
137
138
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 133

def has_z
  msg = build_message("to have Z dimension")
  has_z = detect_has_z(@geometry)
  @test_case.assert has_z, msg
  self
end

#is_cartesianObject



171
172
173
174
175
176
177
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 171

def is_cartesian
  msg = build_message("to be cartesian")
  # Check if factory is cartesian
  is_cart = !(@geometry.factory.respond_to?(:spherical?) && @geometry.factory.spherical?)
  @test_case.assert is_cart, msg
  self
end

#is_geographicObject



163
164
165
166
167
168
169
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 163

def is_geographic
  msg = build_message("to be geographic")
  # Check if factory is geographic
  is_geo = @geometry.factory.respond_to?(:spherical?) && @geometry.factory.spherical?
  @test_case.assert is_geo, msg
  self
end

#is_type(expected_type) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/active_record/connection_adapters/postgis/test_helpers.rb', line 154

def is_type(expected_type)
  msg = build_message("to be of type #{expected_type}")
  actual_type = @geometry.geometry_type.type_name.downcase
  expected_type = expected_type.to_s.downcase.gsub("_", "")
  actual_type = actual_type.gsub("_", "")
  @test_case.assert_equal expected_type, actual_type, msg
  self
end