diff --git a/.travis.yml b/.travis.yml index aae54d8..a2ba4b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,12 +2,12 @@ dist: trusty language: ruby sudo: required rvm: - - 2.4.0 - - 2.3.3 - - 2.2.6 + - 2.4.1 + - 2.3.4 + - 2.2.7 - jruby-9.0.5.0 gemfile: - - gemfiles/ar50.gemfile + - gemfiles/ar51.gemfile matrix: allow_failures: - rvm: jruby-9.0.5.0 diff --git a/Appraisals b/Appraisals index 477b6be..595bc2e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,3 +1,3 @@ -appraise "ar50" do - gem "activerecord", "~> 5.0.0" +appraise "ar51" do + gem "activerecord", "~> 5.1.0" end diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fc7b85c..dad3fd4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,18 +20,15 @@ bundle install Make sure the tests pass: -`rake` +`bundle exec rake` -Run tests against both ActiveRecord 4.0 and 4.1 test gemfiles: +Run tests against the test gemfiles: run `rake appraisal` or run the tests manually: ``` -BUNDLE_GEMFILE=./gemfiles/ar40.gemfile bundle -BUNDLE_GEMFILE=./gemfiles/ar40.gemfile rake - -BUNDLE_GEMFILE=./gemfiles/ar41.gemfile bundle -BUNDLE_GEMFILE=./gemfiles/ar41.gemfile rake +BUNDLE_GEMFILE=./gemfiles/ar51.gemfile bundle +BUNDLE_GEMFILE=./gemfiles/ar51.gemfile rake ``` Make your changes and submit a pull request. diff --git a/History.md b/History.md index ef86e3c..e069644 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,8 @@ +### 2.0.1 / 2017-05-01 + +* Support ActiveRecord 5.1 +* Fix activerecord gem dependency + ### 1.0.0 / 2017-02-09 * Release diff --git a/README.md b/README.md index e2d39c2..d44cce6 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,16 @@ gem 'ffi-geos' _JRuby support for Rails 4.0 and 4.1 was added in version 2.2.0_ +#### Version 5.x supports ActiveRecord 5.1+ + +Requirements: + +``` +ActiveRecord 5.1+ +Ruby 2.2.2+ (no JRuby support yet) +PostGIS 2.0+ +``` + #### Version 4.x supports ActiveRecord 5.0+ Requirements: diff --git a/activerecord-postgis-adapter.gemspec b/activerecord-mysql2rgeo-adapter.gemspec similarity index 91% rename from activerecord-postgis-adapter.gemspec rename to activerecord-mysql2rgeo-adapter.gemspec index 9a84486..9fb7519 100644 --- a/activerecord-postgis-adapter.gemspec +++ b/activerecord-mysql2rgeo-adapter.gemspec @@ -19,8 +19,8 @@ Gem::Specification.new do |spec| spec.required_ruby_version = ">= 2.2.2" - spec.add_dependency "activerecord", "~> 5.0.0" - spec.add_dependency "rgeo-activerecord", "~> 5.0.0" + spec.add_dependency "activerecord", "~> 5.1" + spec.add_dependency "rgeo-activerecord", "~> 5.1" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "minitest", "~> 5.4" diff --git a/gemfiles/ar42.gemfile b/gemfiles/ar42.gemfile deleted file mode 100644 index a574e0c..0000000 --- a/gemfiles/ar42.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "mysql2", "~> 0.4.4", platform: :ruby -gem 'jdbc-mysql', platform: :jruby -gem 'activerecord-jdbc-adapter', platform: :jruby -gem "ffi-geos", platform: :jruby -gem "byebug", platform: :mri_22 -gem "activerecord", "~> 4.2.0" - -gemspec :path => "../" diff --git a/gemfiles/ar50.gemfile b/gemfiles/ar50.gemfile deleted file mode 100644 index 1a36bc4..0000000 --- a/gemfiles/ar50.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "mysql2", "~> 0.4.4", platform: :ruby -gem "jdbc-mysql", platform: :jruby -gem "activerecord-jdbc-adapter", '~> 5.0.pre1', platform: :jruby -gem "ffi-geos", platform: :jruby -gem "byebug", platform: :mri_23 -gem "activerecord", "~> 5.0.0" - -gemspec :path => "../" diff --git a/gemfiles/ar51.gemfile b/gemfiles/ar51.gemfile new file mode 100644 index 0000000..97d077a --- /dev/null +++ b/gemfiles/ar51.gemfile @@ -0,0 +1,11 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "mysql2", "~> 0.4", platform: :ruby +gem "activerecord-jdbcmysql-adapter", '~> 1.3', platform: :jruby +gem "ffi-geos", platform: :jruby +gem "byebug", platform: :mri_23 +gem "activerecord", "~> 5.1.0" + +gemspec :path => "../" diff --git a/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb b/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb index d5b8459..d130338 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/schema_statements.rb @@ -7,13 +7,13 @@ def new_column(*args) SpatialColumn.new(*args) end - def type_to_sql(type, limit = nil, precision = nil, scale = nil, array = nil) + def type_to_sql(type, limit: nil, precision: nil, scale: nil, unsigned: nil, **) # :nodoc: if (info = spatial_column_constructor(type.to_sym)) type = limit[:type] || type if limit.is_a?(::Hash) - type = "geometry" if type.to_s == "spatial" + type = 'geometry' if type.to_s.eql? 'spatial' type = type.to_s.delete("_").upcase end - super(type, limit, precision, scale, array) + super end def spatial_column_constructor(name) 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 7668164..e01be64 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/spatial_table_definition.rb @@ -11,64 +11,34 @@ def new_column_definition(name, type, options) options.merge!(limit) if limit.is_a?(::Hash) end - geo_type = ColumnDefinition.geo_type(options[:type] || type || info[:type]) + geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type]) base_type = info[:type] || :geometry # puts name.dup << " - " << type.to_s << " - " << options.to_s << " :: " << geo_type.to_s << " - " << base_type.to_s + options[:spatial_type] = geo_type column = super(name, geo_type.downcase.to_sym, options) - column.spatial_type = geo_type - column.srid = options[:srid] else column = super(name, type, options) end column end - - private - - def create_column_definition(name, type) - if Mysql2RgeoAdapter.spatial_column_options(type.to_sym) - Mysql2Rgeo::ColumnDefinition.new(name, type) - else - super - end - end end - class ColumnDefinition < MySQL::ColumnDefinition - # needs to accept the spatial type? or figure out from limit ? - - def self.geo_type(type = "GEOMETRY") - g_type = type.to_s.delete("_").upcase - return "POINT" if g_type == "POINT" - return "POLYGON" if g_type == "POLYGON" - g_type - end - - def spatial_type - @spatial_type - end - - def spatial_type=(value) - @spatial_type = value.to_s - end + SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial) - def srid - if @srid - @srid.to_i - else - Mysql2RgeoAdapter::DEFAULT_SRID + module ColumnDefinitionUtils + class << self + def geo_type(type = "GEOMETRY") + type.to_s.delete('_').upcase end - end - def srid=(value) - @srid = value + def default_srid(options) + options[:geographic] ? 4326 : Mysql2RgeoAdapter::DEFAULT_SRID + end end end - - SpatialIndexDefinition = Struct.new(*IndexDefinition.members, :spatial) end end end diff --git a/lib/active_record/connection_adapters/mysql2rgeo/version.rb b/lib/active_record/connection_adapters/mysql2rgeo/version.rb index 9121dc2..222a250 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo/version.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo/version.rb @@ -1,7 +1,7 @@ module ActiveRecord module ConnectionAdapters module Mysql2Rgeo - VERSION = "1.0.4".freeze + VERSION = "2.0.1".freeze end end end diff --git a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb index 020357d..1a0441d 100644 --- a/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb +++ b/lib/active_record/connection_adapters/mysql2rgeo_adapter.rb @@ -28,13 +28,13 @@ class Mysql2RgeoAdapter < Mysql2Adapter geometry: {}, geometrycollection: {}, linestring: {}, - spatial: { type: "geometry" }.freeze, - point: {}, - polygon: {}, multilinestring: {}, multipoint: {}, multipolygon: {}, - }.freeze + spatial: { type: "geometry" }, + point: {}, + polygon: {} + } # http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html DEFAULT_SRID = 0 @@ -61,7 +61,13 @@ def supports_spatial? end # Returns an array of indexes for the given table. - def indexes(table_name, _name = nil) #:nodoc: + def indexes(table_name, name = nil) #:nodoc: + if name + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing name to #indexes is deprecated without replacement. + MSG + end + indexes = [] current_index = nil execute_and_free("SHOW KEYS FROM #{quote_table_name(table_name)}", "SCHEMA") do |result| @@ -78,7 +84,7 @@ def indexes(table_name, _name = nil) #:nodoc: options.push(true) Mysql2Rgeo::SpatialIndexDefinition.new(*options) else - IndexDefinition.new(*options) + IndexDefinition.new(row[:Table], row[:Key_name], row[:Non_unique].to_i == 0, [], {}, nil, nil, index_type, index_using, row[:Index_comment].presence) end end @@ -90,7 +96,7 @@ def indexes(table_name, _name = nil) #:nodoc: indexes end - def quote(value, column = nil) + def quote(value) if RGeo::Feature::Geometry.check_type(value) "ST_GeomFromWKB(0x#{RGeo::WKRep::WKBGenerator.new(hex_format: true, little_endian: true).generate(value)},#{value.srid})" else diff --git a/test/ddl_test.rb b/test/ddl_test.rb index 78d9f1a..b80ff3e 100644 --- a/test/ddl_test.rb +++ b/test/ddl_test.rb @@ -18,7 +18,7 @@ def test_spatial_column_options def test_type_to_sql adapter = SpatialModel.connection - assert_equal "GEOMETRY", adapter.type_to_sql(:geometry, "point,4326") + assert_equal "GEOMETRY", adapter.type_to_sql(:geometry, limit: "point,4326") end def test_create_simple_geometry @@ -270,21 +270,6 @@ def test_non_spatial_column_limits assert_equal 123, col.limit end - def test_includes_spatial_types - klass.connection.create_table("spatial_types", force: true, options: "ENGINE=MyISAM") 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 - klass.reset_column_information - end - private def klass diff --git a/test/spatial_queries_test.rb b/test/spatial_queries_test.rb index 3dc202c..b117d45 100644 --- a/test/spatial_queries_test.rb +++ b/test/spatial_queries_test.rb @@ -21,7 +21,6 @@ def test_query_point_wkt obj.save! id = obj.id obj2 = SpatialModel.where(latlon: "POINT(1 2)").first - puts obj2 refute_nil(obj2) assert_equal(id, obj2.id) obj3 = SpatialModel.where(latlon: "POINT(2 2)").first diff --git a/test/tasks_test.rb b/test/tasks_test.rb index 7dfb02b..1b78995 100644 --- a/test/tasks_test.rb +++ b/test/tasks_test.rb @@ -3,7 +3,7 @@ class TasksTest < ActiveSupport::TestCase # :nodoc: NEW_CONNECTION = { - "adapter" => "mysql2rgeo", + "adapter" => "mysql2rgeo", "host" => "127.0.0.1", "database" => "mysql2rgeo_tasks_test", "username" => "root", @@ -79,7 +79,6 @@ def test_basic_geography_schema_dump ActiveRecord::SchemaDumper.dump(connection, file) end data = File.read(tmp_sql_filename) - assert data.index(%(t.geometry "latlon1", limit: {:type=>"point", :srid=>0})) assert data.index(%(t.geometry "latlon2", limit: {:type=>"point", :srid=>0})) end @@ -94,7 +93,6 @@ def test_index_schema_dump ActiveRecord::SchemaDumper.dump(connection, file) end data = File.read(tmp_sql_filename) - 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