Skip to content

Commit

Permalink
Update development dependencies and restore commented-out tests for s…
Browse files Browse the repository at this point in the history
…patial features
  • Loading branch information
jeff.dean committed Mar 4, 2025
1 parent 0e4131a commit c042503
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 47 deletions.
2 changes: 1 addition & 1 deletion activerecord-mysql2rgeo-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
spec.add_dependency "rgeo", "~> 3.0"

spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "minitest", "~> 5.4"
spec.add_development_dependency "mocha", "~> 2.1"
spec.add_development_dependency "appraisal", "~> 2.0"
Expand Down
91 changes: 45 additions & 46 deletions test/tasks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ def test_empty_sql_dump
assert(sql !~ /CREATE TABLE/)
end

# def test_sql_dump
# setup_database_tasks
# connection.create_table(:spatial_test, force: true) do |t|
# t.point "latlon", geographic: true
# t.geometry "geo_col", srid: 4326
# t.column "poly", :multi_polygon, srid: 4326
# end
# ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
# data = File.read(tmp_sql_filename)
# assert_includes data, "`latlon` point"
# assert_includes data, "`geo_col` geometry"
# assert_includes data, "`poly` multipolygon"
# end
#
# def test_index_sql_dump
# setup_database_tasks
# connection.create_table(:spatial_test, force: true) do |t|
# t.point "latlon", null: false, geographic: true
# t.string "name"
# end
# connection.add_index :spatial_test, :latlon, type: :spatial
# connection.add_index :spatial_test, :name, using: :btree
# ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
# data = File.read(tmp_sql_filename)
# assert_includes data, "`latlon` point"
# assert_includes data, "SPATIAL KEY `index_spatial_test_on_latlon` (`latlon`)"
# assert_includes data, "KEY `index_spatial_test_on_name` (`name`) USING BTREE"
# end
def test_sql_dump
setup_database_tasks
connection.create_table(:spatial_test, force: true) do |t|
t.point "latlon", geographic: true
t.geometry "geo_col", srid: 4326
t.column "poly", :multi_polygon, srid: 4326
end
ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
data = File.read(tmp_sql_filename)
assert_includes data, "`latlon` point"
assert_includes data, "`geo_col` geometry"
assert_includes data, "`poly` multipolygon"
end

def test_index_sql_dump
setup_database_tasks
connection.create_table(:spatial_test, force: true) do |t|
t.point "latlon", null: false, geographic: true
t.string "name"
end
connection.add_index :spatial_test, :latlon, type: :spatial
connection.add_index :spatial_test, :name, using: :btree
ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
data = File.read(tmp_sql_filename)
assert_includes data, "`latlon` point"
assert_includes data, "SPATIAL KEY `index_spatial_test_on_latlon` (`latlon`)"
assert_includes data, "KEY `index_spatial_test_on_name` (`name`) USING BTREE"
end

def test_empty_schema_dump
setup_database_tasks
Expand All @@ -58,8 +58,8 @@ def test_basic_geometry_schema_dump
ActiveRecord::SchemaDumper.dump(connection, file)
end
data = File.read(tmp_sql_filename)
assert_includes data, "t.geometry \"object1\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}"
assert_includes data, "t.geometry \"object2\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}"
assert_includes data, "t.geometry \"object1\", limit: {type: \"geometry\", srid: #{connection.default_srid}"
assert_includes data, "t.geometry \"object2\", limit: {type: \"geometry\", srid: #{connection.default_srid}"
end

def test_basic_geography_schema_dump
Expand All @@ -72,13 +72,13 @@ def test_basic_geography_schema_dump
ActiveRecord::SchemaDumper.dump(connection, file)
end
data = File.read(tmp_sql_filename)
assert_includes data, %(t.geometry "latlon1", limit: {:type=>"point", :srid=>0})
assert_includes data, %(t.geometry "latlon1", limit: {type: "point", srid: 0})
if connection.supports_index_sort_order?
assert_includes(data,
%(t.geometry "latlon2", limit: {:type=>"point", :srid=>4326}))
%(t.geometry "latlon2", limit: {type: "point", srid: 4326}))
else
assert_includes(data,
%(t.geometry "latlon2", limit: {:type=>"point", :srid=>0}))
%(t.geometry "latlon2", limit: {type: "point", srid: 0}))
end
end

Expand All @@ -92,22 +92,21 @@ def test_index_schema_dump
ActiveRecord::SchemaDumper.dump(connection, file)
end
data = File.read(tmp_sql_filename)
puts data
assert_includes data, %(t.geometry "latlon", limit: {:type=>"point", :srid=>0}, null: false)
assert_includes data, %(t.geometry "latlon", limit: {type: "point", srid: 0}, null: false)
assert_includes data, %(t.index ["latlon"], name: "index_spatial_test_on_latlon", type: :spatial)
end

# def test_add_index_with_no_options
# setup_database_tasks
# connection.create_table(:test, force: true) do |t|
# t.string "name"
# end
# connection.add_index :test, :name
# ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
# data = File.read(tmp_sql_filename)
# assert_includes data, "KEY `index_test_on_name` (`name`)"
# end
#
def test_add_index_with_no_options
setup_database_tasks
connection.create_table(:test, force: true) do |t|
t.string "name"
end
connection.add_index :test, :name
ActiveRecord::Tasks::DatabaseTasks.structure_dump(new_connection, tmp_sql_filename)
data = File.read(tmp_sql_filename)
assert_includes data, "KEY `index_test_on_name` (`name`)"
end

# def test_add_index_via_references
# setup_database_tasks
# connection.create_table(:cats, force: true)
Expand Down

0 comments on commit c042503

Please sign in to comment.