From b81365443f9957e72be295c5edc2f429f2ef30cd Mon Sep 17 00:00:00 2001 From: Ulysse Buonomo Date: Wed, 4 Sep 2024 15:08:26 +0200 Subject: [PATCH] fix: use lease_connection in tests --- activerecord-postgis-adapter.gemspec | 2 +- test/cases/attributes_test.rb | 6 +- test/cases/basic_test.rb | 22 +++---- test/cases/ddl_test.rb | 84 +++++++++++++------------- test/cases/nested_class_test.rb | 4 +- test/cases/spatial_queries_test.rb | 2 +- test/schema/postgis_specific_schema.rb | 4 +- test/test_helper.rb | 6 +- 8 files changed, 65 insertions(+), 65 deletions(-) diff --git a/activerecord-postgis-adapter.gemspec b/activerecord-postgis-adapter.gemspec index 9c16f34f..4e58a310 100644 --- a/activerecord-postgis-adapter.gemspec +++ b/activerecord-postgis-adapter.gemspec @@ -10,7 +10,7 @@ Gem::Specification.new do |spec| spec.version = ActiveRecord::ConnectionAdapters::PostGIS::VERSION spec.authors = ["Daniel Azuma", "Tee Parham"] - spec.email = ["kfdoggett@gmail.com", "buonomo.ulysse@gmail.com"] + spec.email = ["kfdoggett@gmail.com", "buonomo.ulysse@gmail.com", "terminale@gmail.com"] spec.homepage = "http://github.com/rgeo/activerecord-postgis-adapter" spec.license = "BSD-3-Clause" diff --git a/test/cases/attributes_test.rb b/test/cases/attributes_test.rb index 31cc7f2c..d1642e95 100644 --- a/test/cases/attributes_test.rb +++ b/test/cases/attributes_test.rb @@ -99,12 +99,12 @@ def test_joined_spatial_attribute private def create_foo - Foo.connection.create_table :foos, force: true do |t| + Foo.lease_connection.create_table :foos, force: true do |t| end end def create_spatial_foo - SpatialFoo.connection.create_table :spatial_foos, force: true do |t| + SpatialFoo.lease_connection.create_table :spatial_foos, force: true do |t| t.references :foo t.st_point :geo_point, geographic: true, srid: 4326 t.st_point :cart_point, srid: 3509 @@ -112,7 +112,7 @@ def create_spatial_foo end def create_invalid_attributes - InvalidAttribute.connection.create_table :invalid_attributes, force: true do |t| + InvalidAttribute.lease_connection.create_table :invalid_attributes, force: true do |t| end end end diff --git a/test/cases/basic_test.rb b/test/cases/basic_test.rb index 352ed6f0..f6aa9c24 100644 --- a/test/cases/basic_test.rb +++ b/test/cases/basic_test.rb @@ -13,14 +13,14 @@ def test_version end def test_postgis_available - assert_equal "PostGIS", SpatialModel.connection.adapter_name - assert_equal postgis_version, SpatialModel.connection.postgis_lib_version - valid_version = ["2.", "3."].any? { |major_ver| SpatialModel.connection.postgis_lib_version.start_with? major_ver } + assert_equal "PostGIS", SpatialModel.lease_connection.adapter_name + assert_equal postgis_version, SpatialModel.lease_connection.postgis_lib_version + valid_version = ["2.", "3."].any? { |major_ver| SpatialModel.lease_connection.postgis_lib_version.start_with? major_ver } assert valid_version end def test_arel_visitor - visitor = Arel::Visitors::PostGIS.new(SpatialModel.connection) + visitor = Arel::Visitors::PostGIS.new(SpatialModel.lease_connection) node = RGeo::ActiveRecord::SpatialConstantNode.new("POINT (1.0 2.0)") collector = Arel::Collectors::PlainString.new visitor.accept(node, collector) @@ -28,7 +28,7 @@ def test_arel_visitor end def test_arel_visitor_will_not_visit_string - visitor = Arel::Visitors::PostGIS.new(SpatialModel.connection) + visitor = Arel::Visitors::PostGIS.new(SpatialModel.lease_connection) node = "POINT (1 2)" collector = Arel::Collectors::PlainString.new @@ -111,7 +111,7 @@ def test_default_value def test_custom_factory klass = SpatialModel - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.st_polygon(:area, srid: 4326) end klass.reset_column_information @@ -127,7 +127,7 @@ def test_custom_factory def test_spatial_factory_attrs_parsing klass = SpatialModel - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.multi_polygon(:areas, srid: 4326) end klass.reset_column_information @@ -152,14 +152,14 @@ def test_readme_example spatial_factory_store.register(geo_factory, geo_type: "point", sql_type: "geography") klass = SpatialModel - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column(:shape, :geometry) t.line_string(:path, srid: 3785) t.st_point(:latlon, geographic: true) end klass.reset_column_information assert_includes klass.columns.map(&:name), "shape" - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.index(:latlon, using: :gist) end @@ -192,7 +192,7 @@ def test_custom_column end def test_multi_polygon_column - SpatialModel.connection.create_table(:spatial_models, force: true) do |t| + SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "m_poly", :multi_polygon end SpatialModel.reset_column_information @@ -212,7 +212,7 @@ def test_multi_polygon_column private def create_model - SpatialModel.connection.create_table(:spatial_models, force: true) do |t| + SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :st_point, srid: 3785 t.column "latlon_geo", :st_point, srid: 4326, geographic: true t.column "default_latlon", :st_point, srid: 0, default: "POINT(0.0 0.0)" diff --git a/test/cases/ddl_test.rb b/test/cases/ddl_test.rb index dc501af5..94890555 100644 --- a/test/cases/ddl_test.rb +++ b/test/cases/ddl_test.rb @@ -21,12 +21,12 @@ def test_spatial_column_options end def test_type_to_sql - adapter = SpatialModel.connection + adapter = SpatialModel.lease_connection assert_equal "geometry(point,4326)", adapter.type_to_sql(:geometry, limit: "point,4326") end def test_create_simple_geometry - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :geometry end klass.reset_column_information @@ -36,12 +36,12 @@ def test_create_simple_geometry assert_equal true, col.spatial? assert_equal false, col.geographic? assert_equal 0, col.srid - klass.connection.drop_table(:spatial_models) + klass.lease_connection.drop_table(:spatial_models) assert_equal 0, count_geometry_columns end def test_create_simple_geography - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :geometry, geographic: true end klass.reset_column_information @@ -54,7 +54,7 @@ def test_create_simple_geography end def test_create_point_geometry - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :st_point end klass.reset_column_information @@ -62,21 +62,21 @@ def test_create_point_geometry end def test_create_geometry_with_index - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :geometry end - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.index([:latlon], using: :gist) end klass.reset_column_information - assert_equal :gist, klass.connection.indexes(:spatial_models).last.using + assert_equal :gist, klass.lease_connection.indexes(:spatial_models).last.using end def test_add_geometry_column - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column("latlon", :geometry) end - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.column("geom2", :st_point, srid: 4326) t.column("name", :string) end @@ -95,7 +95,7 @@ def test_add_geometry_column end def test_add_geometry_column_null_false - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column("latlon_null", :geometry, null: false) t.column("latlon", :geometry) end @@ -108,10 +108,10 @@ def test_add_geometry_column_null_false end def test_add_geography_column - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column("latlon", :geometry) end - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.st_point("geom3", srid: 4326, geographic: true) t.column("geom2", :st_point, srid: 4326, geographic: true) t.column("name", :string) @@ -139,11 +139,11 @@ def test_add_geography_column end def test_drop_geometry_column - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column("latlon", :geometry) t.column("geom2", :st_point, srid: 4326) end - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.remove("geom2") end klass.reset_column_information @@ -156,12 +156,12 @@ def test_drop_geometry_column end def test_drop_geography_column - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column("latlon", :geometry) t.column("geom2", :st_point, srid: 4326, geographic: true) t.column("geom3", :st_point, srid: 4326) end - klass.connection.change_table(:spatial_models) do |t| + klass.lease_connection.change_table(:spatial_models) do |t| t.remove("geom2") end klass.reset_column_information @@ -176,7 +176,7 @@ def test_drop_geography_column end def test_create_simple_geometry_using_shortcut - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.geometry "latlon" end klass.reset_column_information @@ -185,12 +185,12 @@ def test_create_simple_geometry_using_shortcut assert_equal RGeo::Feature::Geometry, col.geometric_type assert_equal false, col.geographic? assert_equal 0, col.srid - klass.connection.drop_table(:spatial_models) + klass.lease_connection.drop_table(:spatial_models) assert_equal 0, count_geometry_columns end def test_create_simple_geography_using_shortcut - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.geometry "latlon", geographic: true end klass.reset_column_information @@ -202,7 +202,7 @@ def test_create_simple_geography_using_shortcut end def test_create_point_geometry_using_shortcut - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.st_point "latlon" end klass.reset_column_information @@ -210,7 +210,7 @@ def test_create_point_geometry_using_shortcut end def test_create_geometry_using_shortcut_with_srid - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.geometry "latlon", srid: 4326 end klass.reset_column_information @@ -220,7 +220,7 @@ def test_create_geometry_using_shortcut_with_srid end def test_create_polygon_with_options - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "region", :st_polygon, has_m: true, srid: 3785 end klass.reset_column_information @@ -232,12 +232,12 @@ def test_create_polygon_with_options assert_equal true, col.has_m? assert_equal 3785, col.srid assert_equal({ has_m: true, type: "st_polygon", srid: 3785 }, col.limit) - klass.connection.drop_table(:spatial_models) + klass.lease_connection.drop_table(:spatial_models) assert_equal 0, count_geometry_columns end def test_create_spatial_column_default_value_geometric - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "coordinates", :st_point, srid: 3875, default: "POINT(0.0 0.0)" end klass.reset_column_information @@ -251,12 +251,12 @@ def test_create_spatial_column_default_value_geometric assert_equal 3875, col.srid assert_equal "010100000000000000000000000000000000000000", col.default assert_equal({ type: "st_point", srid: 3875 }, col.limit) - klass.connection.drop_table(:spatial_models) + klass.lease_connection.drop_table(:spatial_models) assert_equal 0, count_geometry_columns end def test_create_spatial_column_default_value_geographic - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.geography "coordinates", limit: { srid: 4326, type: "st_point", geographic: true }, default: "POINT(0.0 0.0)" end klass.reset_column_information @@ -270,12 +270,12 @@ def test_create_spatial_column_default_value_geographic assert_equal 4326, col.srid assert_equal "0101000020E610000000000000000000000000000000000000", col.default assert_equal({ type: "st_point", srid: 4326, geographic: true }, col.limit) - klass.connection.drop_table(:spatial_models) + klass.lease_connection.drop_table(:spatial_models) assert_equal 0, count_geography_columns end def test_no_query_spatial_column_info - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.string "name" end klass.reset_column_information @@ -289,7 +289,7 @@ def test_no_query_spatial_column_info # Ensure that null contraints info is getting captured like the # normal adapter. def test_null_constraints - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "nulls_allowed", :string, null: true t.column "nulls_disallowed", :string, null: false end @@ -300,7 +300,7 @@ def test_null_constraints # Ensure column default value works like the Postgres adapter. def test_column_defaults - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "sample_integer", :integer, default: -1 end klass.reset_column_information @@ -309,8 +309,8 @@ def test_column_defaults # Ensure virtual column default function works like the Postgres adapter. def test_virtual_column_default_function - skip "Virtual Columns are not supported in this version of PostGIS" unless SpatialModel.connection.supports_virtual_columns? - klass.connection.create_table(:spatial_models, force: true) do |t| + skip "Virtual Columns are not supported in this version of PostGIS" unless SpatialModel.lease_connection.supports_virtual_columns? + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.integer :column1 t.virtual :column2, type: :integer, as: "(column1 + 1)", stored: true end @@ -322,7 +322,7 @@ def test_virtual_column_default_function end def test_column_types - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "sample_integer", :integer t.column "sample_string", :string t.column "latlon", :st_point @@ -334,7 +334,7 @@ def test_column_types end def test_array_columns - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "sample_array", :string, array: true t.column "sample_non_array", :string end @@ -344,7 +344,7 @@ def test_array_columns end def test_reload_dumped_schema - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.geography "latlon1", limit: { srid: 4326, type: "point", geographic: true } end klass.reset_column_information @@ -353,7 +353,7 @@ def test_reload_dumped_schema end def test_non_spatial_column_limits - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.string :foo, limit: 123 end klass.reset_column_information @@ -362,7 +362,7 @@ def test_non_spatial_column_limits end def test_column_comments - klass.connection.create_table(:spatial_models, force: true) do |t| + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.string :sample_comment, comment: "Comment test" end klass.reset_column_information @@ -371,8 +371,8 @@ def test_column_comments end def test_generated_geometry_column - skip "Virtual Columns are not supported in this version of PostGIS" unless SpatialModel.connection.supports_virtual_columns? - klass.connection.create_table(:spatial_models, force: true) do |t| + skip "Virtual Columns are not supported in this version of PostGIS" unless SpatialModel.lease_connection.supports_virtual_columns? + klass.lease_connection.create_table(:spatial_models, force: true) do |t| t.st_point :coordinates, limit: { srid: 4326 } t.virtual :generated_buffer, type: :st_polygon, limit: { srid: 4326 }, as: "ST_Buffer(coordinates, 10)", stored: true end @@ -390,11 +390,11 @@ def klass end def count_geometry_columns - klass.connection.select_value(geo_column_sql("geometry_columns", klass.table_name)).to_i + klass.lease_connection.select_value(geo_column_sql("geometry_columns", klass.table_name)).to_i end def count_geography_columns - klass.connection.select_value(geo_column_sql("geography_columns", klass.table_name)).to_i + klass.lease_connection.select_value(geo_column_sql("geography_columns", klass.table_name)).to_i end def geo_column_sql(postgis_view, table_name) diff --git a/test/cases/nested_class_test.rb b/test/cases/nested_class_test.rb index a1c57e8e..ce54200a 100644 --- a/test/cases/nested_class_test.rb +++ b/test/cases/nested_class_test.rb @@ -14,11 +14,11 @@ class Bar < ActiveRecord::Base end def test_nested_model - Foo::Bar.connection.create_table(:foo_bars, force: true) do |t| + Foo::Bar.lease_connection.create_table(:foo_bars, force: true) do |t| t.column "latlon", :st_point, srid: 3785 end assert_empty Foo::Bar.all - Foo::Bar.connection.drop_table(:foo_bars) + Foo::Bar.lease_connection.drop_table(:foo_bars) end end end diff --git a/test/cases/spatial_queries_test.rb b/test/cases/spatial_queries_test.rb index 137e6928..c0e6a77a 100644 --- a/test/cases/spatial_queries_test.rb +++ b/test/cases/spatial_queries_test.rb @@ -118,7 +118,7 @@ def test_ewkt_parser_query private def create_model - SpatialModel.connection.create_table(:spatial_models, force: true) do |t| + SpatialModel.lease_connection.create_table(:spatial_models, force: true) do |t| t.column "latlon", :st_point, srid: 3785 t.column "points", :multi_point, srid: 3785 t.column "path", :line_string, srid: 3785 diff --git a/test/schema/postgis_specific_schema.rb b/test/schema/postgis_specific_schema.rb index 535b2153..446aeb1d 100644 --- a/test/schema/postgis_specific_schema.rb +++ b/test/schema/postgis_specific_schema.rb @@ -4,8 +4,8 @@ # suite. ActiveRecord::Schema.define do - ActiveRecord::TestCase.enable_extension!("uuid-ossp", ActiveRecord::Base.connection) - ActiveRecord::TestCase.enable_extension!("pgcrypto", ActiveRecord::Base.connection) if ActiveRecord::Base.connection.supports_pgcrypto_uuid? + ActiveRecord::TestCase.enable_extension!("uuid-ossp", ActiveRecord::Base.lease_connection) + ActiveRecord::TestCase.enable_extension!("pgcrypto", ActiveRecord::Base.lease_connection) if ActiveRecord::Base.lease_connection.supports_pgcrypto_uuid? uuid_default = connection.supports_pgcrypto_uuid? ? {} : { default: "uuid_generate_v4()" } diff --git a/test/test_helper.rb b/test/test_helper.rb index 18bfdfec..be45271f 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,7 +17,7 @@ def load_postgis_specific_schema original_stdout = $stdout $stdout = StringIO.new - load "schema/postgis_specific_schema.rb" + load SCHEMA_ROOT + "/postgresql_specific_schema.rb" ActiveRecord::FixtureSet.reset_cache ensure @@ -69,11 +69,11 @@ class TestCase self.test_order = :sorted def database_version - @database_version ||= SpatialModel.connection.select_value("SELECT version()") + @database_version ||= SpatialModel.lease_connection.select_value("SELECT version()") end def postgis_version - @postgis_version ||= SpatialModel.connection.select_value("SELECT postgis_lib_version()") + @postgis_version ||= SpatialModel.lease_connection.select_value("SELECT postgis_lib_version()") end def factory(srid: 3785)