Skip to content

Commit c19d965

Browse files
inkstakpeterfication
authored andcommitted
[Fix ctran#430] Handle columns from activerecord-postgis-adapter (ctran#694)
Same problem returned by @janosrusiczki in ctran#430 Spatial columns with activerecord-postgis-adapter (5.2.2) are not displayed nice ``` # name :string(3) # active :boolean default(FALSE), not null # geom :geometry({:srid= geometry, 4326 ``` That's come from activerecord-postgis-adapter, with redefined columns as such : ``` #<ActiveRecord::ConnectionAdapters::PostGIS::SpatialColumn @sql_type="geometry(Geometry,4326)", @geo_type="Geometry", @geometric_type=RGeo::Feature::Geometry, @srid=4326, @limit={:srid=>4326, :type=>"geometry"} [...] > ``` This fix displays them like this : ``` # name :string(3) # active :boolean default(FALSE), not null # geometry :geometry geometry, 4326 ``` Another possibility would have been to display them as below, but it involves a lot of extra-spaces for other columns. ``` # name :string(3) # active :boolean default(FALSE), not null # geometry :geometry(Geometry, 4326) ```
1 parent cc7628a commit c19d965

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.rubocop_todo.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ Lint/ShadowingOuterLocalVariable:
408408

409409
# Offense count: 20
410410
Metrics/AbcSize:
411-
Max: 139
411+
Max: 141
412412

413413
# Offense count: 28
414414
# Configuration parameters: CountComments, ExcludedMethods.

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def get_schema_info(klass, header, options = {})
264264

265265
if col_type == 'decimal'
266266
col_type << "(#{col.precision}, #{col.scale})"
267-
elsif col_type != 'spatial'
267+
elsif !%w[spatial geometry geography].include?(col_type)
268268
if col.limit
269269
if col.limit.is_a? Array
270270
attrs << "(#{col.limit.join(', ')})"

spec/lib/annotate/annotate_models_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,32 @@ def self.when_called_with(options = {})
10551055
#
10561056
EOS
10571057

1058+
mocked_columns_with_geometries = [
1059+
[:id, :integer, { limit: 8 }],
1060+
[:active, :boolean, { default: false, null: false }],
1061+
[:geometry, :geometry, {
1062+
geometric_type: 'Geometry', srid: 4326,
1063+
limit: { srid: 4326, type: 'geometry' }
1064+
}],
1065+
[:location, :geography, {
1066+
geometric_type: 'Point', srid: 0,
1067+
limit: { srid: 0, type: 'geometry' }
1068+
}]
1069+
]
1070+
1071+
when_called_with with_columns: mocked_columns_with_geometries, returns:
1072+
<<-EOS.strip_heredoc
1073+
# Schema Info
1074+
#
1075+
# Table name: users
1076+
#
1077+
# id :integer not null, primary key
1078+
# active :boolean default(FALSE), not null
1079+
# geometry :geometry not null, geometry, 4326
1080+
# location :geography not null, point, 0
1081+
#
1082+
EOS
1083+
10581084
it 'should get schema info as RDoc' do
10591085
klass = mock_class(:users,
10601086
:id,

0 commit comments

Comments
 (0)