From 8528cf7e841c0d873c3599958997af52ca80c182 Mon Sep 17 00:00:00 2001 From: Dania02525 Date: Fri, 17 Nov 2023 12:41:54 -0500 Subject: [PATCH] support postGIS adapter for postgreSQL remove puts rename changelog change wording in changelog update pr number Update lib/rubocop/cop/rails/bulk_change_table.rb Co-authored-by: Koichi ITO Update changelog/new_support_postgis_adapter_for_postgresql.md Co-authored-by: Koichi ITO --- ..._support_postgis_adapter_for_postgresql.md | 1 + docs/modules/ROOT/pages/cops_rails.adoc | 2 +- .../cop/mixin/database_type_resolvable.rb | 2 +- lib/rubocop/cop/rails/bulk_change_table.rb | 2 +- .../cop/rails/bulk_change_table_spec.rb | 40 +++++++++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 changelog/new_support_postgis_adapter_for_postgresql.md diff --git a/changelog/new_support_postgis_adapter_for_postgresql.md b/changelog/new_support_postgis_adapter_for_postgresql.md new file mode 100644 index 0000000000..f03580602b --- /dev/null +++ b/changelog/new_support_postgis_adapter_for_postgresql.md @@ -0,0 +1 @@ +* [#1183](https://github.com/rubocop/rubocop-rails/pull/1183): Support PostGIS adapter for PostgreSQL. ([@Dania02525][]) diff --git a/docs/modules/ROOT/pages/cops_rails.adoc b/docs/modules/ROOT/pages/cops_rails.adoc index 73d6e0a1b1..99d3fdcab4 100644 --- a/docs/modules/ROOT/pages/cops_rails.adoc +++ b/docs/modules/ROOT/pages/cops_rails.adoc @@ -977,7 +977,7 @@ the PostgreSQL (5.2 later) adapter; thus it will automatically detect an adapter from `development` environment in `config/database.yml` or the environment variable `DATABASE_URL` when the `Database` option is not set. -If the adapter is not `mysql2`, `trilogy`, or `postgresql`, +If the adapter is not `mysql2`, `trilogy`, `postgresql`, or `postgis`, this Cop ignores offenses. === Examples diff --git a/lib/rubocop/cop/mixin/database_type_resolvable.rb b/lib/rubocop/cop/mixin/database_type_resolvable.rb index 5557f99f34..3743514492 100644 --- a/lib/rubocop/cop/mixin/database_type_resolvable.rb +++ b/lib/rubocop/cop/mixin/database_type_resolvable.rb @@ -23,7 +23,7 @@ def database_from_yaml case database_adapter when 'mysql2', 'trilogy' MYSQL - when 'postgresql' + when 'postgresql', 'postgis' POSTGRESQL end end diff --git a/lib/rubocop/cop/rails/bulk_change_table.rb b/lib/rubocop/cop/rails/bulk_change_table.rb index ad77628047..2d5a503d6f 100644 --- a/lib/rubocop/cop/rails/bulk_change_table.rb +++ b/lib/rubocop/cop/rails/bulk_change_table.rb @@ -14,7 +14,7 @@ module Rails # automatically detect an adapter from `development` environment # in `config/database.yml` or the environment variable `DATABASE_URL` # when the `Database` option is not set. - # If the adapter is not `mysql2`, `trilogy`, or `postgresql`, + # If the adapter is not `mysql2`, `trilogy`, `postgresql`, or `postgis`, # this Cop ignores offenses. # # @example diff --git a/spec/rubocop/cop/rails/bulk_change_table_spec.rb b/spec/rubocop/cop/rails/bulk_change_table_spec.rb index 9f3952add9..8beeec92c0 100644 --- a/spec/rubocop/cop/rails/bulk_change_table_spec.rb +++ b/spec/rubocop/cop/rails/bulk_change_table_spec.rb @@ -547,6 +547,46 @@ def change end end + context 'postgis' do + context 'with top-level adapter configuration' do + let(:yaml) do + { + 'development' => { + 'adapter' => 'postgis' + } + } + end + + context 'with Rails 5.2', :rails52 do + it_behaves_like 'offense for postgresql' + end + + context 'with Rails 5.1', :rails51 do + it_behaves_like 'no offense for postgresql' + end + end + + context 'with nested adapter configuration' do + let(:yaml) do + { + 'development' => { + 'primary' => { + 'adapter' => 'postgis' + } + } + } + end + + context 'with Rails 5.2', :rails52 do + it_behaves_like 'offense for postgresql' + end + + context 'with Rails 5.1', :rails51 do + it_behaves_like 'no offense for postgresql' + end + end + end + context 'invalid (e.g. ERB)' do before do allow(YAML).to receive(:load_file).with('config/database.yml') do