Skip to content

Commit

Permalink
Test schema and sql dump of indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
teeparham committed May 16, 2014
1 parent 16af25e commit 789e06f
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions test/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,28 @@ def test_empty_sql_dump
def test_basic_geography_sql_dump
setup_database_tasks
connection.create_table(:spatial_test) do |t|
t.point "latlon", :geographic => true
t.point "latlon", geographic: true
end
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
data = ::File.read(tmp_sql_filename)
assert(data.index('latlon geography(Point,4326)'))
end

def test_index_sql_dump
setup_database_tasks
connection.create_table(:spatial_test) do |t|
t.point "latlon", geographic: true
t.string "name"
end
connection.add_index :spatial_test, :latlon, spatial: true
connection.add_index :spatial_test, :name, using: :btree
::ActiveRecord::Tasks::DatabaseTasks.structure_dump(TasksTest.new_database_config, tmp_sql_filename)
data = ::File.read(tmp_sql_filename)
assert(data.index('latlon geography(Point,4326)'))
assert data.index('CREATE INDEX index_spatial_test_on_latlon ON spatial_test USING gist (latlon);')
assert data.index('CREATE INDEX index_spatial_test_on_name ON spatial_test USING btree (name);')
end

def test_empty_schema_dump
setup_database_tasks
::File.open(tmp_sql_filename, "w:utf-8") do |file|
Expand All @@ -61,7 +76,7 @@ def test_basic_geometry_schema_dump
setup_database_tasks
connection.create_table(:spatial_test) do |t|
t.geometry 'object1'
t.spatial "object2", :limit => { :srid => connection.default_srid, :type => "geometry" }
t.spatial "object2", limit: { srid: connection.default_srid, type: "geometry" }
end
::File.open(tmp_sql_filename, "w:utf-8") do |file|
::ActiveRecord::SchemaDumper.dump(connection, file)
Expand All @@ -74,8 +89,8 @@ def test_basic_geometry_schema_dump
def test_basic_geography_schema_dump
setup_database_tasks
connection.create_table(:spatial_test) do |t|
t.point "latlon1", :geographic => true
t.spatial "latlon2", :limit => { :srid => 4326, :type => "point", :geographic => true}
t.point "latlon1", geographic: true
t.spatial "latlon2", limit: { srid: 4326, type: "point", geographic: true }
end
::File.open(tmp_sql_filename, "w:utf-8") do |file|
::ActiveRecord::SchemaDumper.dump(connection, file)
Expand All @@ -85,6 +100,19 @@ def test_basic_geography_schema_dump
assert(data.index('t.spatial "latlon2", limit: {:srid=>4326, :type=>"point", :geographic=>true}'))
end

def test_index_schema_dump
setup_database_tasks
connection.create_table(:spatial_test) do |t|
t.point "latlon", geographic: true
end
connection.add_index :spatial_test, :latlon, spatial: true
::File.open(tmp_sql_filename, "w:utf-8") do |file|
::ActiveRecord::SchemaDumper.dump(connection, file)
end
data = ::File.read(tmp_sql_filename)
assert data.index('t.spatial "latlon", limit: {:srid=>4326, :type=>"point", :geographic=>true}')
assert data.index('add_index "spatial_test", ["latlon"], :name => "index_spatial_test_on_latlon", :spatial => true')
end
end

private
Expand Down

0 comments on commit 789e06f

Please sign in to comment.