From adb4e9a41dc76cd80533c0848b3df98aa19f4792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Wed, 8 Feb 2017 17:32:45 +0900 Subject: [PATCH 01/11] add tasks_test --- .../mysql2rgeo/column_methods.rb | 2 +- .../mysql2rgeo/spatial_table_definition.rb | 3 + .../connection_adapters/mysql2rgeo_adapter.rb | 34 ++-- test/tasks_test.rb | 146 ++++++++++++++++++ 4 files changed, 168 insertions(+), 17 deletions(-) create mode 100644 test/tasks_test.rb diff --git a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb index ad9dcea..8ee3ec1 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb @@ -3,7 +3,7 @@ module ConnectionAdapters module Mysql2Rgeo module ColumnMethods def spatial(name, options = {}) - raise "You must set a type. For example: 't.spatial limit: { type: 'point' }'" if options[:limit].blank? || options[:limit][:type].blank? + raise "You must set a type. For example: 't.spatial :object1, limit: { type: 'point' }'" if options[:limit].blank? || options[:limit][:type].blank? column(name, options[:limit][:type], options) end diff --git a/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb b/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb index 7127c4b..644b461 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb @@ -67,6 +67,9 @@ def srid=(value) @srid = value end end + + class SpatialIndexDefinition < Struct.new(*IndexDefinition.members, :spatial) + end end end end diff --git a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb index cc8c385..814ec8b 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb @@ -22,17 +22,17 @@ class Mysql2RgeoAdapter < Mysql2Adapter include Mysql2Rgeo::SchemaStatements SPATIAL_COLUMN_OPTIONS = - { - geometry: {}, - geometrycollection: {}, - linestring: {}, - spatial: { type: "geometry" }.freeze, - point: {}, - polygon: {}, - multilinestring: {}, - multipoint: {}, - multipolygon: {}, - }.freeze + { + geometry: {}, + geometrycollection: {}, + linestring: {}, + spatial: { type: "geometry" }.freeze, + point: {}, + polygon: {}, + multilinestring: {}, + multipoint: {}, + multipolygon: {}, + }.freeze # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html DEFAULT_SRID = 0 @@ -67,11 +67,13 @@ def indexes(table_name, _name = nil) #:nodoc: mysql_index_type = row[:Index_type].downcase.to_sym index_type = INDEX_TYPES.include?(mysql_index_type) ? mysql_index_type : nil index_using = INDEX_USINGS.include?(mysql_index_type) ? mysql_index_type : nil - if mysql_index_type != :spatial - indexes << IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], [], nil, nil, index_type, index_using, row[:Index_comment].presence) - else - indexes << RGeo::ActiveRecord::SpatialIndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique] == 0, [], [], row[:Index_type] == "SPATIAL") - end + options = [row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], [], nil, nil, index_type, index_using, row[:Index_comment].presence] + indexes << if mysql_index_type == :spatial + options.push(true) + Mysql2Rgeo::SpatialIndexDefinition.new(*options) + else + IndexDefinition.new(*options) + end end indexes.last.columns << row[:Column_name] diff --git a/test/tasks_test.rb b/test/tasks_test.rb new file mode 100644 index 0000000..bf8acf5 --- /dev/null +++ b/test/tasks_test.rb @@ -0,0 +1,146 @@ +require "test_helper" +require "active_record/schema_dumper" + +class TasksTest < ActiveSupport::TestCase # :nodoc: + NEW_CONNECTION = { + "adapter" => "mysql2rgeo", + "host" => "127.0.0.1", + "database" => "mysql2rgeo_tasks_test", + "username" => "root", + "password" => "" + } + + def test_empty_sql_dump + setup_database_tasks + ActiveRecord::Tasks::DatabaseTasks.structure_dump(NEW_CONNECTION, tmp_sql_filename) + sql = File.read(tmp_sql_filename) + 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(data.index("`latlon` point")) + assert(data.index("`geo_col` geometry")) + assert(data.index("`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(data.index("`latlon` point")) + assert data.index("SPATIAL KEY `index_spatial_test_on_latlon` (`latlon`)") + assert data.index("KEY `index_spatial_test_on_name` (`name`) USING BTREE") + end + + def test_empty_schema_dump + setup_database_tasks + File.open(tmp_sql_filename, "w:utf-8") do |file| + ActiveRecord::SchemaDumper.dump(::ActiveRecord::Base.connection, file) + end + data = File.read(tmp_sql_filename) + assert(data.index("ActiveRecord::Schema")) + end + + def test_basic_geometry_schema_dump + setup_database_tasks + connection.create_table(:spatial_test, force: true) do |t| + t.geometry "object1" + t.spatial "object2", srid: connection.default_srid, limit: { type: "geometry" } + end + 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 \"object1\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") + assert data.index("t.spatial \"object2\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") + end + + def test_basic_geography_schema_dump + setup_database_tasks + connection.create_table(:spatial_test, force: true) do |t| + 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) + end + data = File.read(tmp_sql_filename) + assert data.index(%(t.spatial "latlon1", limit: {:type=>"point", :srid=>0})) + assert data.index(%(t.spatial "latlon2", limit: {:type=>"point", :srid=>0})) + end + + def test_index_schema_dump + setup_database_tasks + connection.create_table(:spatial_test, force: true) do |t| + t.point "latlon", null: false, geographic: true + end + connection.add_index :spatial_test, :latlon, type: :spatial + 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: {:type=>"point", :srid=>0}, null: false)) + assert data.index(%(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 data.index("KEY `index_test_on_name` (`name`)") + end + + def test_add_index_via_references + setup_database_tasks + connection.create_table(:cats, force: true) + connection.create_table(:dogs, force: true) do |t| + t.references :cats, index: true + end + ActiveRecord::Tasks::DatabaseTasks.structure_dump(NEW_CONNECTION, tmp_sql_filename) + data = File.read(tmp_sql_filename) + assert data.index("KEY `index_dogs_on_cats_id` (`cats_id`)") + end + + private + + def connection + ActiveRecord::Base.connection + end + + def tmp_sql_filename + File.expand_path("../tmp/tmp.sql", ::File.dirname(__FILE__)) + end + + def setup_database_tasks + FileUtils.rm_f(tmp_sql_filename) + FileUtils.mkdir_p(::File.dirname(tmp_sql_filename)) + drop_db_if_exists + ActiveRecord::Tasks::MySQLDatabaseTasks.new(NEW_CONNECTION).create + rescue ActiveRecord::Tasks::DatabaseAlreadyExists + # ignore + end + + def drop_db_if_exists + ActiveRecord::Tasks::MySQLDatabaseTasks.new(NEW_CONNECTION).drop + rescue ActiveRecord::Tasks::DatabaseAlreadyExists + # ignore + end +end \ No newline at end of file From 3aefb03398d64f5d1000bed3b7a9bbd93e8b3380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Wed, 8 Feb 2017 18:38:33 +0900 Subject: [PATCH 02/11] add test spatial_type --- .../mysql2rgeo/column_methods.rb | 18 ++-- .../mysql2rgeo/schema_statements.rb | 6 -- lib/active_record/type/spatial.rb | 4 - test/spatial_types_test.rb | 89 +++++++++++++++++++ 4 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 test/spatial_types_test.rb diff --git a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb index 8ee3ec1..4a9d039 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb @@ -15,7 +15,7 @@ def geometry(*args, multi: false, **options) multi ? multi_geometry(*args, **options) : args.each { |name| column(name, :geometry, options) } end - def multi_geometry(*args, **options) + def geometrycollection(*args, **options) args.each { |name| column(name, :geometrycollection, options) } end @@ -23,7 +23,7 @@ def point(*args, multi: false, **options) multi ? multi_point(*args, **options) : args.each { |name| column(name, :point, options) } end - def multi_point(*args, **options) + def multipoint(*args, **options) args.each { |name| column(name, :multipoint, options) } end @@ -31,18 +31,22 @@ def linestring(*args, multi: false, **options) multi ? multi_linestring(*args, **options) : args.each { |name| column(name, :linestring, options) } end - def multi_linestring(*args, **options) + def multilinestring(*args, **options) args.each { |name| column(name, :multilinestring, options) } end def polygon(*args, multi: false, **options) - type = multi ? :multipolygon : :polygon - args.each { |name| column(name, type, options) } + multi ? multipolygon(*args, **options) : args.each { |name| column(name, :polygon, options) } end - def multi_polygon(*args, **options) - polygon(args, true, options) + def multipolygon(*args, **options) + args.each { |name| column(name, :multipolygon, options) } end + + alias :multi_point :multipoint + alias :multi_geometry :geometrycollection + alias :multi_linestring :multilinestring + alias :multi_polygon :multipolygon end MySQL::Table.send(:include, ColumnMethods) diff --git a/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb b/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb index db352bf..d5b8459 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb @@ -41,12 +41,6 @@ def create_table_definition(*args) Mysql2Rgeo::TableDefinition.new(*args) end - def type_cast(value, column = nil) - super - rescue TypeError - value.to_s - end - def initialize_type_map(m) super %w( diff --git a/lib/active_record/type/spatial.rb b/lib/active_record/type/spatial.rb index 21f68a6..63b7fdb 100644 --- a/lib/active_record/type/spatial.rb +++ b/lib/active_record/type/spatial.rb @@ -53,10 +53,6 @@ def type :spatial end - def self.type - :spatial - end - def spatial? type == :spatial end diff --git a/test/spatial_types_test.rb b/test/spatial_types_test.rb new file mode 100644 index 0000000..671568f --- /dev/null +++ b/test/spatial_types_test.rb @@ -0,0 +1,89 @@ +require "test_helper" +require "active_record/schema_dumper" + +class Mysql2SpatialTypesTest < ActiveSupport::TestCase # :nodoc: + NEW_CONNECTION = { + "adapter" => "mysql2rgeo", + "host" => "127.0.0.1", + "database" => "mysql2rgeo_tasks_test", + "username" => "root" + } + + def setup + setup_database_tasks + connection.create_table("spatial_types", force: true) do |t| + t.geometry :geometry_field + t.polygon :polygon_field, null: false, index: { type: :spatial } + t.point :point_field + t.linestring :linestring_field + + t.geometry :geometry_multi, multi: true + t.polygon :polygon_multi, multi: true + t.point :point_multi, multi: true + t.linestring :linestring_multi, multi: true + end + end + + def teardown + connection.drop_table "spatial_types", if_exists: true + end + + def test_schema_dump_includes_spatial_types + File.open(tmp_sql_filename, "w:utf-8") do |file| + ActiveRecord::SchemaDumper.dump(connection, file) + end + schema = File.read(tmp_sql_filename) + + # assert_match %r{t.geometry\s+"geometry_field"$}, schema + # assert_match %r{t.polygon\s+"polygon_field",\s+null: false$}, schema + # assert_match %r{t.point\s+"point_field"$}, schema + # assert_match %r{t.linestring\s+"linestring_field"$}, schema + # + # assert_match %r{t.geometry\s+"geometry_multi",\s+multi: true$}, schema + # assert_match %r{t.polygon\s+"polygon_multi",\s+multi: true$}, schema + # assert_match %r{t.point\s+"point_multi",\s+multi: true$}, schema + # assert_match %r{t.linestring\s+"linestring_multi",\s+multi: true$}, schema + end + + def test_schema_dump_can_be_restored + File.open(tmp_sql_filename, "w:utf-8") do |file| + ActiveRecord::SchemaDumper.dump(connection, file) + end + schema = File.read(tmp_sql_filename) + connection.drop_table "spatial_types", if_exists: true + + eval schema + + File.open(tmp_sql_filename, "w:utf-8") do |file| + ActiveRecord::SchemaDumper.dump(connection, file) + end + schema2 = File.read(tmp_sql_filename) + + assert_equal schema, schema2 + end + + private + + def connection + ActiveRecord::Base.connection + end + + def tmp_sql_filename + File.expand_path("../tmp/tmp.sql", ::File.dirname(__FILE__)) + end + + def setup_database_tasks + FileUtils.rm_f(tmp_sql_filename) + FileUtils.mkdir_p(::File.dirname(tmp_sql_filename)) + drop_db_if_exists + ActiveRecord::Tasks::MySQLDatabaseTasks.new(NEW_CONNECTION).create + rescue ActiveRecord::Tasks::DatabaseAlreadyExists + # ignore + end + + def drop_db_if_exists + ActiveRecord::Tasks::MySQLDatabaseTasks.new(NEW_CONNECTION).drop + rescue ActiveRecord::Tasks::DatabaseAlreadyExists + # ignore + end +end \ No newline at end of file From 9ebab51c405f00e338d5cee1a78adc19bc0ccc75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Wed, 8 Feb 2017 18:50:08 +0900 Subject: [PATCH 03/11] change the type of SpatialColumn --- .../connection_adapters/mysql2rgeo/arel_tosql.rb | 2 +- .../connection_adapters/mysql2rgeo/column_methods.rb | 4 ---- lib/active_record/type/spatial.rb | 6 +++--- test/ddl_test.rb | 4 ++-- test/tasks_test.rb | 12 +++++++----- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb b/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb index a102a8a..26f5210 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb @@ -41,7 +41,7 @@ def visit_Arel_Nodes_SelectCore(o, collector) def visit_Arel_Attributes_Attribute(o, collector) join_name = o.relation.table_alias || o.relation.name - collector << if (!column_for(o).nil? && column_for(o).type == :spatial) && !collector.value.include?(" WHERE ") + collector << if (!column_for(o).nil? && column_for(o).type == :geometry) && !collector.value.include?(" WHERE ") "ST_AsText(#{quote_table_name join_name}.#{quote_column_name o.name}) as #{quote_column_name o.name}" else "#{quote_table_name join_name}.#{quote_column_name o.name}" diff --git a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb index 4a9d039..a4cd54d 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb @@ -7,10 +7,6 @@ def spatial(name, options = {}) column(name, options[:limit][:type], options) end - def geography(*args, **options) - args.each { |name| column(name, :geometry, options) } - end - def geometry(*args, multi: false, **options) multi ? multi_geometry(*args, **options) : args.each { |name| column(name, :geometry, options) } end diff --git a/lib/active_record/type/spatial.rb b/lib/active_record/type/spatial.rb index 63b7fdb..96dddd7 100644 --- a/lib/active_record/type/spatial.rb +++ b/lib/active_record/type/spatial.rb @@ -46,15 +46,15 @@ def self.parse_sql_type(sql_type) end def klass - type == :spatial ? RGeo::Feature::Geometry : super + type == :geometry ? RGeo::Feature::Geometry : super end def type - :spatial + :geometry end def spatial? - type == :spatial + true end def spatial_factory diff --git a/test/ddl_test.rb b/test/ddl_test.rb index cfcafc8..78d9f1a 100644 --- a/test/ddl_test.rb +++ b/test/ddl_test.rb @@ -249,12 +249,12 @@ def test_column_types klass.reset_column_information assert_equal :integer, klass.columns[-3].type assert_equal :string, klass.columns[-2].type - assert_equal :spatial, klass.columns[-1].type + assert_equal :geometry, klass.columns[-1].type end def test_reload_dumped_schema klass.connection.create_table(:spatial_models, force: true) do |t| - t.geography "latlon1", limit: { srid: 4326, type: "point", geographic: true } + t.geometry "latlon1", limit: { srid: 4326, type: "point", geographic: true } end klass.reset_column_information col = klass.columns.last diff --git a/test/tasks_test.rb b/test/tasks_test.rb index bf8acf5..74730ba 100644 --- a/test/tasks_test.rb +++ b/test/tasks_test.rb @@ -65,8 +65,8 @@ def test_basic_geometry_schema_dump ActiveRecord::SchemaDumper.dump(connection, file) end data = File.read(tmp_sql_filename) - assert data.index("t.spatial \"object1\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") - assert data.index("t.spatial \"object2\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") + assert data.index("t.geometry \"object1\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") + assert data.index("t.geometry \"object2\", limit: {:type=>\"geometry\", :srid=>#{connection.default_srid}") end def test_basic_geography_schema_dump @@ -79,8 +79,9 @@ def test_basic_geography_schema_dump ActiveRecord::SchemaDumper.dump(connection, file) end data = File.read(tmp_sql_filename) - assert data.index(%(t.spatial "latlon1", limit: {:type=>"point", :srid=>0})) - assert data.index(%(t.spatial "latlon2", limit: {:type=>"point", :srid=>0})) + + assert data.index(%(t.geometry "latlon1", limit: {:type=>"point", :srid=>0})) + assert data.index(%(t.geometry "latlon2", limit: {:type=>"point", :srid=>0})) end def test_index_schema_dump @@ -93,7 +94,8 @@ def test_index_schema_dump ActiveRecord::SchemaDumper.dump(connection, file) end data = File.read(tmp_sql_filename) - assert data.index(%(t.spatial "latlon", limit: {:type=>"point", :srid=>0}, null: false)) + + assert data.index(%(t.geometry "latlon", limit: {:type=>"point", :srid=>0}, null: false)) assert data.index(%(t.index ["latlon"], name: "index_spatial_test_on_latlon", type: :spatial)) end From c0533d120ba2b3745b2098d9d1b3b99a67f83219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Wed, 8 Feb 2017 18:58:24 +0900 Subject: [PATCH 04/11] fix travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 77a0c69..78e4867 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,4 +20,5 @@ addons: before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' + - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' script: bundle exec rake test \ No newline at end of file From 88109dd9ae37077976766580880e40083bb2192c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:13:26 +0900 Subject: [PATCH 05/11] add tmp file by touch in travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 78e4867..8003e52 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,4 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' + - touch tmp/tmp.sql script: bundle exec rake test \ No newline at end of file From b1b4c3263a24b265de0c18a5f18acb7af232a0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:26:24 +0900 Subject: [PATCH 06/11] test dumping --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8003e52..5b98515 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' - - touch tmp/tmp.sql + - mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines script: bundle exec rake test \ No newline at end of file From d08f67e4777351fd0b7712baffa95b09034858fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:32:49 +0900 Subject: [PATCH 07/11] mkdir tmp directory --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5b98515..70726c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' - - mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines + - mkdir tmp && mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines script: bundle exec rake test \ No newline at end of file From 7404fd3f4736bf7e5f6eddeaae6e90a91dfb8bdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:39:25 +0900 Subject: [PATCH 08/11] retry --- .travis.install-mysql-5.7.sh | 2 +- .travis.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.install-mysql-5.7.sh b/.travis.install-mysql-5.7.sh index 8d8870e..94790d8 100644 --- a/.travis.install-mysql-5.7.sh +++ b/.travis.install-mysql-5.7.sh @@ -3,4 +3,4 @@ echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo deb wget https://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.deb sudo dpkg --install mysql-apt-config_0.8.1-1_all.deb sudo apt-get update -q && sudo apt-get install -q -y -o Dpkg::Options::=--force-confnew mysql-server -sudo mysql_upgrade \ No newline at end of file +sudo mysql_upgrade -uroot \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 70726c1..333f624 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' - - mkdir tmp && mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines + - mkdir tmp script: bundle exec rake test \ No newline at end of file From 40f20b601f208bdc1725ca0808af6265379c6490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:45:38 +0900 Subject: [PATCH 09/11] retry --- .travis.install-mysql-5.7.sh | 3 ++- .travis.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.install-mysql-5.7.sh b/.travis.install-mysql-5.7.sh index 94790d8..e7b6dcf 100644 --- a/.travis.install-mysql-5.7.sh +++ b/.travis.install-mysql-5.7.sh @@ -3,4 +3,5 @@ echo mysql-apt-config mysql-apt-config/select-server select mysql-5.7 | sudo deb wget https://dev.mysql.com/get/mysql-apt-config_0.8.1-1_all.deb sudo dpkg --install mysql-apt-config_0.8.1-1_all.deb sudo apt-get update -q && sudo apt-get install -q -y -o Dpkg::Options::=--force-confnew mysql-server -sudo mysql_upgrade -uroot \ No newline at end of file +sudo mysql_upgrade -uroot +sudo service mysql restart \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 333f624..70726c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' - - mkdir tmp + - mkdir tmp && mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines script: bundle exec rake test \ No newline at end of file From 855cade4f86b9cc9000efd17a5692f3070125cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 15:51:21 +0900 Subject: [PATCH 10/11] green light --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 70726c1..aae54d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,5 +21,5 @@ before_install: - bash .travis.install-mysql-5.7.sh - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_adapter_test;' - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS mysql2rgeo_tasks_test;' - - mkdir tmp && mysqldump -uroot --all-databases --result-file tmp/tmp.sql --no-data --routines + - mkdir tmp && touch tmp/tmp.sql script: bundle exec rake test \ No newline at end of file From 2c0758a7a9f15a944d6f250e5f01c341bc76170d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jeff=28=E1=84=92=E1=85=AA=E1=86=BC=E1=84=8B=E1=85=AD?= =?UTF-8?q?=E1=86=BC=E1=84=83=E1=85=A2=29?= Date: Thu, 9 Feb 2017 16:22:09 +0900 Subject: [PATCH 11/11] rubocop --- .rubocop_todo.yml | 3 +++ .../mysql2rgeo/column_methods.rb | 8 +++---- .../mysql2rgeo/spatial_table_definition.rb | 3 +-- .../connection_adapters/mysql2rgeo_adapter.rb | 22 +++++++++---------- test/spatial_types_test.rb | 16 +++++++------- test/tasks_test.rb | 14 ++++++------ 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fec6290..6aec83c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -12,7 +12,9 @@ Bundler/OrderedGems: # Offense count: 3 Lint/HandleExceptions: Exclude: + - 'test/tasks_test.rb' - 'test/test_helper.rb' + - 'test/spatial_types_test.rb' # Offense count: 1 # Cop supports --auto-correct. @@ -166,6 +168,7 @@ Style/ParallelAssignment: Style/PredicateName: Exclude: - 'lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb' + - 'lib/active_record/connection_adapters/mysql2rgeo/spatial_column.rb' # Offense count: 5 # Cop supports --auto-correct. diff --git a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb index a4cd54d..5df189e 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/column_methods.rb @@ -39,10 +39,10 @@ def multipolygon(*args, **options) args.each { |name| column(name, :multipolygon, options) } end - alias :multi_point :multipoint - alias :multi_geometry :geometrycollection - alias :multi_linestring :multilinestring - alias :multi_polygon :multipolygon + alias multi_point multipoint + alias multi_geometry geometrycollection + alias multi_linestring multilinestring + alias multi_polygon multipolygon end MySQL::Table.send(:include, ColumnMethods) diff --git a/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb b/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb index 644b461..7668164 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb @@ -68,8 +68,7 @@ def srid=(value) end end - class SpatialIndexDefinition < Struct.new(*IndexDefinition.members, :spatial) - end + SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial) end end end diff --git a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb index 814ec8b..4357ab4 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb @@ -22,17 +22,17 @@ class Mysql2RgeoAdapter < Mysql2Adapter include Mysql2Rgeo::SchemaStatements SPATIAL_COLUMN_OPTIONS = - { - geometry: {}, - geometrycollection: {}, - linestring: {}, - spatial: { type: "geometry" }.freeze, - point: {}, - polygon: {}, - multilinestring: {}, - multipoint: {}, - multipolygon: {}, - }.freeze + { + geometry: {}, + geometrycollection: {}, + linestring: {}, + spatial: { type: "geometry" }.freeze, + point: {}, + polygon: {}, + multilinestring: {}, + multipoint: {}, + multipolygon: {}, + }.freeze # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html DEFAULT_SRID = 0 diff --git a/test/spatial_types_test.rb b/test/spatial_types_test.rb index 671568f..e7320ff 100644 --- a/test/spatial_types_test.rb +++ b/test/spatial_types_test.rb @@ -1,13 +1,13 @@ require "test_helper" require "active_record/schema_dumper" -class Mysql2SpatialTypesTest < ActiveSupport::TestCase # :nodoc: +class Mysql2SpatialTypesTest < ActiveSupport::TestCase # :nodoc: NEW_CONNECTION = { - "adapter" => "mysql2rgeo", - "host" => "127.0.0.1", - "database" => "mysql2rgeo_tasks_test", - "username" => "root" - } + "adapter" => "mysql2rgeo", + "host" => "127.0.0.1", + "database" => "mysql2rgeo_tasks_test", + "username" => "root" + }.freeze def setup setup_database_tasks @@ -32,7 +32,7 @@ def test_schema_dump_includes_spatial_types File.open(tmp_sql_filename, "w:utf-8") do |file| ActiveRecord::SchemaDumper.dump(connection, file) end - schema = File.read(tmp_sql_filename) + # schema = File.read(tmp_sql_filename) # assert_match %r{t.geometry\s+"geometry_field"$}, schema # assert_match %r{t.polygon\s+"polygon_field",\s+null: false$}, schema @@ -86,4 +86,4 @@ def drop_db_if_exists rescue ActiveRecord::Tasks::DatabaseAlreadyExists # ignore end -end \ No newline at end of file +end diff --git a/test/tasks_test.rb b/test/tasks_test.rb index 74730ba..7dfb02b 100644 --- a/test/tasks_test.rb +++ b/test/tasks_test.rb @@ -3,12 +3,12 @@ class TasksTest < ActiveSupport::TestCase # :nodoc: NEW_CONNECTION = { - "adapter" => "mysql2rgeo", - "host" => "127.0.0.1", - "database" => "mysql2rgeo_tasks_test", - "username" => "root", - "password" => "" - } + "adapter" => "mysql2rgeo", + "host" => "127.0.0.1", + "database" => "mysql2rgeo_tasks_test", + "username" => "root", + "password" => "" + }.freeze def test_empty_sql_dump setup_database_tasks @@ -145,4 +145,4 @@ def drop_db_if_exists rescue ActiveRecord::Tasks::DatabaseAlreadyExists # ignore end -end \ No newline at end of file +end