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

Rails 7.2 support #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ jobs:
BUNDLE_GEMFILE: ${{matrix.gemfile}}
strategy:
matrix:
ruby: ['3.0', '2.7']
ruby: ['3.1', '2.7']
gemfile:
- gemfiles/ar71.gemfile
- gemfiles/ar72.gemfile
mysql: ['5.7', '8.0']
steps:
- name: Set Up Actions
Expand Down
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Bundler/OrderedGems:
Exclude:
- 'Gemfile'
- 'gemfiles/ar71.gemfile'
- 'gemfiles/ar72.gemfile'

# Offense count: 2
# Cop supports --auto-correct.
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rvm:
- jruby-9.2.6.0
- 3.0
gemfile:
- gemfiles/ar71.gemfile
- gemfiles/ar72.gemfile
matrix:
allow_failures:
- rvm: jruby-9.2.6.0
Expand Down
4 changes: 2 additions & 2 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
appraise "ar71" do
gem "activerecord", "~> 7.1.0"
appraise "ar72" do
gem "activerecord", "~> 7.2.0"
end
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Run tests against the test gemfiles:
run `rake appraisal` or run the tests manually:

```
BUNDLE_GEMFILE=./gemfiles/ar71.gemfile bundle
BUNDLE_GEMFILE=./gemfiles/ar71.gemfile rake
BUNDLE_GEMFILE=./gemfiles/ar72.gemfile bundle
BUNDLE_GEMFILE=./gemfiles/ar72.gemfile rake
```

Make your changes and submit a pull request.
Expand Down
2 changes: 1 addition & 1 deletion activerecord-mysql2rgeo-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.7.0"

spec.add_dependency "activerecord", "~> 7.1.0"
spec.add_dependency "activerecord", "~> 7.2.0"
spec.add_dependency "rgeo-activerecord", "~> 7.0.0"
spec.add_dependency "rgeo", "~> 2.0"

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/ar71.gemfile → gemfiles/ar72.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ gem "mysql2", "~> 0.5.2", platform: :ruby
gem "jdbc-mysql", platform: :jruby
gem "activerecord-jdbc-adapter", "~> 5.0", platform: :jruby
gem "ffi-geos", platform: :jruby
gem "activerecord", "~> 7.1.0"
gem "activerecord", "~> 7.2.0"

gemspec path: "../"
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def new_column_definition(name, type, **options)

column
end

def valid_column_definition_options
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super + %i[geographic has_m spatial_type srid]
end
end

module ColumnDefinitionUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ActiveRecord
module ConnectionAdapters
module Mysql2Rgeo
VERSION = "7.1.0"
VERSION = "7.2.0"
end
end
end
6 changes: 5 additions & 1 deletion lib/active_record/connection_adapters/mysql2rgeo_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Mysql2RgeoAdapter < Mysql2Adapter
# http://postgis.17.x6.nabble.com/Default-SRID-td5001115.html
DEFAULT_SRID = 0

def initialize(connection, logger, connection_options, config)
def initialize(...)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super

@visitor = Arel::Visitors::Mysql2Rgeo.new(self)
Expand Down Expand Up @@ -137,6 +137,10 @@ def quote(value)
end
end

def with_connection
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required by this change to ActiveRecord: https://github.com/rails/rails/pull/51162/files#diff-22750093c2231cef8c58e7e94a0a9266267d33bd990c607475e55fe285fccb8aR45

I only saw this with_connection method getting called by tests in this gem that were dumping the schema. I'm sure something more sophisticated could be created for this, however it fixed the failing tests.

yield self
end

private
def type_map
emulate_booleans ? TYPE_MAP_WITH_BOOLEAN : TYPE_MAP
Expand Down
2 changes: 2 additions & 0 deletions lib/activerecord-mysql2rgeo-adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "active_record/connection_adapters/mysql2rgeo_adapter"

ActiveRecord::ConnectionAdapters.register('mysql2rgeo', 'ActiveRecord::ConnectionAdapters::Mysql2RgeoAdapter', 'active_record/connection_adapters/mysql2rgeo_adapter')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the following error when running rake test

DEPRECATION WARNING: Database configuration specifies 'mysql2rgeo' adapter but that adapter has not been registered. Rails 7.2 has changed the way Active Record database adapters are loaded. The adapter needs to be updated to register itself rather than being loaded by convention. Ensure that the adapter in the Gemfile is at the latest version. If it is, then the adapter may need to be modified. See: https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters.html#method-c-register (called from establish_test_connection at /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/test_helper.rb:22)
/Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/connection_adapters.rb:85:in `resolve': Database configuration specifies 'mysql2rgeo' adapter but that adapter has not been registered. Ensure that the adapter in the Gemfile is at the latest version. If it is, then the adapter may need to be modified. (ActiveRecord::AdapterNotFound)
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/database_configurations/database_config.rb:18:in `adapter_class'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/database_configurations/database_config.rb:30:in `validate!'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/connection_handler.rb:268:in `resolve_pool_config'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/connection_adapters/abstract/connection_handler.rb:116:in `establish_connection'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/activerecord-7.2.1/lib/active_record/connection_handling.rb:53:in `establish_connection'
	from /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/test_helper.rb:22:in `establish_test_connection'
	from /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/test_helper.rb:28:in `<class:SpatialModel>'
	from /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/test_helper.rb:27:in `<top (required)>'
	from /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/basic_test.rb:3:in `require'
	from /Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/basic_test.rb:3:in `<top (required)>'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:12:in `require'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:12:in `block (2 levels) in <main>'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:11:in `each'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:11:in `block in <main>'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:5:in `select'
	from /Users/denisahearn/.rvm/gems/ruby-3.3.4/gems/rake-12.3.3/lib/rake/rake_test_loader.rb:5:in `<main>'

2 changes: 1 addition & 1 deletion test/basic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_point_to_json
obj = SpatialModel.new
assert_match(/"latlon":null/, obj.to_json)
obj.latlon = factory.point(1.0, 2.0)
assert_match(/"latlon":"POINT\s\(1\.0\s2\.0\)"/, obj.to_json)
assert_match(/"latlon":"POINT\s\(1(\.0)?\s2(\.0)?\)"/, obj.to_json)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes this test failure:

1) Failure:
BasicTest#test_point_to_json [/Users/denisahearn/development/sentera/activerecord-mysql2rgeo-adapter/test/basic_test.rb:137]:
Expected /"latlon":"POINT\s\(1\.0\s2\.0\)"/ to match "{\"id\":null,\"latlon\":\"POINT (1 2)\",\"latlon_geo\":null}".

I didn't research what caused the change with this decimal formatting

end

def test_custom_column
Expand Down
Loading