Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct behavior of non-geographic null: false columns #127

Merged
merged 2 commits into from
Jun 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ 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?,
null: col.null,
srid: col.srid,
type: col.spatial_type,
}
Expand Down Expand Up @@ -180,6 +182,7 @@ def add_spatial_column(table_name, column_name, info = {}, type = nil, 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