Skip to content

Commit

Permalink
Merge pull request #1183 from Dania02525/feature/support_postgis_adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
koic authored Nov 20, 2023
2 parents 8015fc2 + 8528cf7 commit 0a80ba9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/new_support_postgis_adapter_for_postgresql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1183](https://github.com/rubocop/rubocop-rails/pull/1183): Support PostGIS adapter for PostgreSQL. ([@Dania02525][])
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/database_type_resolvable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def database_from_yaml
case database_adapter
when 'mysql2', 'trilogy'
MYSQL
when 'postgresql'
when 'postgresql', 'postgis'
POSTGRESQL
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/bulk_change_table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions spec/rubocop/cop/rails/bulk_change_table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a80ba9

Please sign in to comment.