Skip to content

Commit

Permalink
Merge pull request #127 from srt32/st-add-spatial-column-non-geographic
Browse files Browse the repository at this point in the history
Conflicts: lib/active_record/connection_adapters/postgis_adapter/main_adapter.rb
  • Loading branch information
teeparham committed Jun 16, 2014
2 parents ba81ec8 + ad32a0c commit c3b3c0b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ def create_table(table_name, options = {}, &block)
end
table_definition.non_geographic_spatial_columns.each do |col|
options = {
default: col.default,
has_m: col.has_m?,
has_z: col.has_z?,
srid: col.srid
null: col.null,
srid: col.srid,
type: col.spatial_type,
}
column_name = col.name.to_s
type = col.spatial_type
Expand Down Expand Up @@ -182,6 +185,7 @@ def add_spatial_column(table_name, column_name, type, options)
type = "#{type}M" if has_m && !has_z
dimensions = set_dimensions(has_m, has_z)
execute("SELECT AddGeometryColumn('#{quote_string(table_name)}', '#{quote_string(column_name)}', #{srid}, '#{quote_string(type)}', #{dimensions})")
change_column_null(table_name, column_name, false, options[:default]) if options[:null] == false
end
end

Expand Down
9 changes: 6 additions & 3 deletions test/ddl_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ def test_add_geometry_column
def test_add_geometry_column_null_false
klass = create_ar_class
klass.connection.create_table(:spatial_test) do |t|
t.column('latlon', :geometry, null: false)
t.column('latlon_null', :geometry, null: false)
t.column('latlon', :geometry)
end
geometry_column = klass.columns.first
null_false_column = klass.columns[1]
null_true_column = klass.columns[2]

refute(geometry_column.null, 'Column should be null: false')
refute(null_false_column.null, 'Column should be null: false')
assert(null_true_column.null, 'Column should be null: true')
end

def test_add_geography_column
Expand Down

0 comments on commit c3b3c0b

Please sign in to comment.