diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 0000000..7b82b2c --- /dev/null +++ b/.devcontainer.json @@ -0,0 +1,17 @@ +{ + "name": "activerecord-pg-extensions", + "dockerComposeFile": [], + "service": "app", + "workspaceFolder": "/app", + "postCreateCommand": "bundle install && ~/.local/bin/pre-commit install", + "customizations": { + "vscode": { + "extensions": [ + "GitHub.vscode-github-actions", + "GitHub.vscode-pull-request-github", + "Shopify.ruby-lsp", + "ms-azuretools.vscode-docker" + ] + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 26981ae..c666a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /.bundle/ -/.byebug_history /log/ /pkg/ /workflow/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..9587143 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: +- repo: https://github.com/mattlqx/pre-commit-ruby + rev: v1.3.5 + hooks: + - id: rubocop diff --git a/.rubocop.yml b/.rubocop.yml index 13c1865..ffe8157 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,5 +26,7 @@ RSpec/ContextWording: Enabled: false RSpec/FilePath: Enabled: false +RSpec/SpecFilePathFormat: + Enabled: false RSpec/VerifiedDoubles: Enabled: false \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4faa84b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "ruby_lsp", + "request": "launch", + "name": "Run Specs", + "program": "rspec" + }, + { + "type": "ruby_lsp", + "request": "launch", + "name": "Run Current Spec File", + "program": "rspec ${file}" + } + ] +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..93e7b9e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM ruby:3.1 + +RUN apt update && \ + apt install -y --no-install-recommends \ + pipx \ + postgresql-client && \ + rm -rf /var/lib/apt/lists/* && \ + pipx install pre-commit && \ + gem update --system + +WORKDIR /app +ENV PATH="/app/bin:${PATH}" diff --git a/Gemfile b/Gemfile index 29d1299..d9704aa 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" -plugin "bundler-multilock", "1.0.6" +plugin "bundler-multilock", "1.0.11" return unless Plugin.installed?("bundler-multilock") Plugin.send(:load_plugin, "bundler-multilock") diff --git a/Gemfile.lock b/Gemfile.lock index 94a2284..dca4ddb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,25 +8,25 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (7.0.7.2) - actionview (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.7.2) - activesupport (= 7.0.7.2) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activesupport (7.0.7.2) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -38,13 +38,19 @@ GEM ast (2.4.2) base64 (0.1.1) builder (3.2.4) - byebug (11.1.3) concurrent-ruby (1.2.2) crass (1.0.6) + debug (1.8.0) + irb (>= 1.5.0) + reline (>= 0.3.1) diff-lcs (1.5.0) erubi (1.12.0) i18n (1.14.1) concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.8.1) + rdoc + reline (>= 0.3.8) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.3) @@ -67,6 +73,8 @@ GEM ast (~> 2.4.1) racc pg (1.5.4) + psych (5.1.0) + stringio racc (1.7.1) rack (2.2.8) rack-test (2.1.0) @@ -78,16 +86,20 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) + rdoc (6.5.0) + psych (>= 4.0.0) regexp_parser (2.8.1) + reline (0.3.9) + io-console (~> 0.5) rexml (3.2.6) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -102,7 +114,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) - rubocop (1.56.2) + rubocop (1.56.4) base64 (~> 0.1.1) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -116,28 +128,29 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.29.0) parser (>= 3.2.1.0) - rubocop-capybara (2.18.0) + rubocop-capybara (2.19.0) rubocop (~> 1.41) - rubocop-factory_bot (2.23.1) + rubocop-factory_bot (2.24.0) rubocop (~> 1.33) rubocop-inst (1.0.2) rubocop (~> 1.50) rubocop-performance (~> 1.17) - rubocop-performance (1.19.0) + rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.23.2) + rubocop-rspec (2.24.1) rubocop (~> 1.33) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + stringio (3.0.8) thor (1.2.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) - zeitwerk (2.6.11) + unicode-display_width (2.5.0) + zeitwerk (2.6.12) PLATFORMS arm64-darwin @@ -148,7 +161,7 @@ PLATFORMS DEPENDENCIES activerecord-pg-extensions! appraisal (~> 2.4) - byebug (~> 11.1) + debug (~> 1.8) pg (~> 1.2) rake (~> 13.0) rspec (~> 3.0) @@ -157,4 +170,4 @@ DEPENDENCIES rubocop-rspec (~> 2.3) BUNDLED WITH - 2.4.19 + 2.4.20 diff --git a/Gemfile.rails-7.0.lock b/Gemfile.rails-7.0.lock index 7215919..8018a1f 100644 --- a/Gemfile.rails-7.0.lock +++ b/Gemfile.rails-7.0.lock @@ -8,25 +8,25 @@ PATH GEM remote: https://rubygems.org/ specs: - actionpack (7.0.7.2) - actionview (= 7.0.7.2) - activesupport (= 7.0.7.2) + actionpack (7.0.8) + actionview (= 7.0.8) + activesupport (= 7.0.8) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.7.2) - activesupport (= 7.0.7.2) + actionview (7.0.8) + activesupport (= 7.0.8) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activesupport (7.0.7.2) + activemodel (7.0.8) + activesupport (= 7.0.8) + activerecord (7.0.8) + activemodel (= 7.0.8) + activesupport (= 7.0.8) + activesupport (7.0.8) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -38,13 +38,19 @@ GEM ast (2.4.2) base64 (0.1.1) builder (3.2.4) - byebug (11.1.3) concurrent-ruby (1.2.2) crass (1.0.6) + debug (1.8.0) + irb (>= 1.5.0) + reline (>= 0.3.1) diff-lcs (1.5.0) erubi (1.12.0) i18n (1.14.1) concurrent-ruby (~> 1.0) + io-console (0.6.0) + irb (1.8.1) + rdoc + reline (>= 0.3.8) json (2.6.3) language_server-protocol (3.17.0.3) loofah (2.21.3) @@ -67,6 +73,8 @@ GEM ast (~> 2.4.1) racc pg (1.5.4) + psych (5.1.0) + stringio racc (1.7.1) rack (2.2.8) rack-test (2.1.0) @@ -78,16 +86,20 @@ GEM rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.7.2) - actionpack (= 7.0.7.2) - activesupport (= 7.0.7.2) + railties (7.0.8) + actionpack (= 7.0.8) + activesupport (= 7.0.8) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) + rdoc (6.5.0) + psych (>= 4.0.0) regexp_parser (2.8.1) + reline (0.3.9) + io-console (~> 0.5) rexml (3.2.6) rspec (3.12.0) rspec-core (~> 3.12.0) @@ -102,7 +114,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-support (3.12.1) - rubocop (1.56.2) + rubocop (1.56.4) base64 (~> 0.1.1) json (~> 2.3) language_server-protocol (>= 3.17.0) @@ -116,28 +128,29 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.29.0) parser (>= 3.2.1.0) - rubocop-capybara (2.18.0) + rubocop-capybara (2.19.0) rubocop (~> 1.41) - rubocop-factory_bot (2.23.1) + rubocop-factory_bot (2.24.0) rubocop (~> 1.33) rubocop-inst (1.0.2) rubocop (~> 1.50) rubocop-performance (~> 1.17) - rubocop-performance (1.19.0) + rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) rubocop-rake (0.6.0) rubocop (~> 1.0) - rubocop-rspec (2.23.2) + rubocop-rspec (2.24.1) rubocop (~> 1.33) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) ruby-progressbar (1.13.0) + stringio (3.0.8) thor (1.2.2) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.4.2) - zeitwerk (2.6.11) + unicode-display_width (2.5.0) + zeitwerk (2.6.12) PLATFORMS arm64-darwin @@ -149,7 +162,7 @@ DEPENDENCIES activerecord (~> 7.0.0) activerecord-pg-extensions! appraisal (~> 2.4) - byebug (~> 11.1) + debug (~> 1.8) pg (~> 1.2) rake (~> 13.0) rspec (~> 3.0) @@ -158,4 +171,4 @@ DEPENDENCIES rubocop-rspec (~> 2.3) BUNDLED WITH - 2.4.19 + 2.4.20 diff --git a/LICENSE.txt b/LICENSE.txt index 1c7739a..81bf08c 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021 Instructure, Inc. +Copyright (c) 2021-2023 Instructure, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ede4f0b..b361760 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,13 @@ See individual classes for available methods. ## Development -You will need Postgres locally to test. As long as `psql` can connect with no arguments, you're fine. Otherwise use environment variables -as described at https://www.postgresql.org/docs/current/libpq-envars.html to configure it. The database will be created automatically. +Development requires Docker. After checking out the repo, run `docker compose build` to install dependencies. -`rake` will run both tests and Rubocop. +`docker compose run --rm app rake` will run both tests and Rubocop. -After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +If using Visual Studio Code, simply click "Reopen in Container" when it pops up. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To release a new version, update the version number in `version.rb`, and then run `rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing diff --git a/Rakefile b/Rakefile index 156fd6e..3f4cf41 100644 --- a/Rakefile +++ b/Rakefile @@ -1,12 +1,11 @@ # frozen_string_literal: true require "bundler/gem_tasks" -require "rspec/core/rake_task" +require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) require "rubocop/rake_task" - RuboCop::RakeTask.new -task default: %i[spec] +task default: %i[spec rubocop] diff --git a/activerecord-pg-extensions.gemspec b/activerecord-pg-extensions.gemspec index 5d27699..b280201 100644 --- a/activerecord-pg-extensions.gemspec +++ b/activerecord-pg-extensions.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.add_dependency "railties", "~> 7.0.0" spec.add_development_dependency "appraisal", "~> 2.4" - spec.add_development_dependency "byebug", "~> 11.1" + spec.add_development_dependency "debug", "~> 1.8" spec.add_development_dependency "pg", "~> 1.2" spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rspec", "~> 3.0" diff --git a/bin/rdbg b/bin/rdbg new file mode 100755 index 0000000..5e3b279 --- /dev/null +++ b/bin/rdbg @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rdbg' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("debug", "rdbg") diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f2f54d8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3' + +services: + app: + build: . + volumes: + - .:/app:cached + - gem-home:/usr/local/bundle + links: + - postgres + command: sleep infinity + environment: + PGHOST: postgres + PGUSER: postgres + + postgres: + image: postgres:16 + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_HOST_AUTH_METHOD: trust + +volumes: + postgres-data: + gem-home: diff --git a/spec/postgresql_adapter_spec.rb b/spec/postgresql_adapter_spec.rb index 5c44bc1..f1952ba 100644 --- a/spec/postgresql_adapter_spec.rb +++ b/spec/postgresql_adapter_spec.rb @@ -15,8 +15,8 @@ end it "allows string arguments" do - expect { connection.set_constraints("deferred") }.not_to raise_error(ArgumentError) - expect { connection.set_constraints("immediate") }.not_to raise_error(ArgumentError) + connection.set_constraints("deferred") + connection.set_constraints("immediate") end it "defaults to all" do @@ -200,6 +200,13 @@ end describe "#vacuum" do + around do |block| + old_proc = connection.raw_connection.set_notice_processor { nil } + block.call + ensure + connection.raw_connection.set_notice_processor(&old_proc) + end + it "does a straight vacuum of everything" do connection.vacuum expect(connection.executed_statements).to eq ["VACUUM"] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9552845..cbd413c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "activerecord-pg-extensions" -require "byebug" +require "debug" require "active_record/railtie" require "active_record/pg_extensions/all" @@ -10,6 +10,7 @@ class Application < Rails::Application config.eager_load = false + config.active_record.legacy_connection_handling = false end Application.initialize!