From e3593db838cf5165fa95921f0f39141bad9fc4bc Mon Sep 17 00:00:00 2001 From: Matt Pasquini Date: Tue, 7 May 2024 09:41:17 -0700 Subject: [PATCH 1/5] Move CI to Github Actions and Remove circle CI --- .circleci/config.yml | 62 ------------------- .github/workflows/main.yml | 103 ++++++++++++++++++++++++++++++++ .github/workflows/reviewdog.yml | 22 ------- ros-apartment.gemspec | 6 +- 4 files changed, 106 insertions(+), 87 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/reviewdog.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 70141e0b..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,62 +0,0 @@ -version: 2.1 - -jobs: - build: - docker: - - image: cimg/<< parameters.ruby_version >> - - image: cimg/postgres:12.13 - - image: cimg/mysql:8.0 - environment: - MYSQL_ALLOW_EMPTY_PASSWORD: "yes" - parameters: - ruby_version: - type: string - gemfile: - type: string - environment: - BUNDLE_GEMFILE: << parameters.gemfile >> - steps: - - checkout - - - run: bundle install --path vendor/bundle - - - run: - name: Update apt - command: sudo apt update -y - - - run: - name: Install dependencies - command: sudo apt install -y curl postgresql-client default-mysql-client - - - run: - name: Configure config database.yml - command: bundle exec rake db:copy_credentials - - - run: - name: wait for postgresql - command: dockerize -wait tcp://localhost:5432 -timeout 1m - - - run: - name: wait for mysql - command: dockerize -wait tcp://localhost:3306 -timeout 1m - - - run: - name: Database Setup - command: | - bundle exec rake db:test:prepare - - - run: - name: Run tests - command: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/test-results/rspec/rspec.xml - - - store_test_results: - path: ~/test-results/rspec/ - -workflows: - tests: - jobs: - - build: - matrix: - parameters: - ruby_version: ["ruby:3.1.4", "ruby:3.2.2"] - gemfile: ["gemfiles/rails_6_1.gemfile", "gemfiles/rails_7_0.gemfile", "gemfiles/rails_7_1.gemfile"] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..aad40dd1 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,103 @@ +name: Ruby +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + rubocop: + name: runner / rubocop + runs-on: ubuntu-latest + strategy: + matrix: + rails_version: +# - 6_1 + - 7_0 +# - 7_1 +# - master + steps: + - uses: actions/checkout@v4 + - name: Read .ruby-version file + id: getrubyversion + run: echo "RUBY_VERSION=$(cat .ruby-version)" >> $GITHUB_OUTPUT + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ steps.getrubyversion.outputs.RUBY_VERSION }} + - run: ls -la + - name: Set up Rails ${{ matrix.rails_version }} + run: | + bundle config set --local gemfile "gemfiles/rails_${{ matrix.rails_version }}.gemfile" + bundle config set --local path 'vendor/bundle' + bundle install + - name: Rubocop + run: "bundle exec rubocop" + + test: + runs-on: ubuntu-latest + strategy: + matrix: + ruby_version: + - 3.1 + - 3.2 + rails_version: + - 6_1 + - 7_0 + - 7_1 +# - master + # Service containers to run with `container-job` + services: + # Label used to access the service container + postgres: + # Docker Hub image + image: postgres:14 + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_DB: apartment_postgresql_test + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 5432 on service container to the host + - 5432:5432 + mysql: + # Docker Hub image + image: mysql:8.0 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: true + MYSQL_DATABASE: apartment_mysql_test + options: >- + --health-cmd "mysqladmin ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + # Maps tcp port 3306 on service container to the host + - 3306:3306 + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby_version }} + - name: Set up Rails ${{ matrix.rails_version }} + run: | + bundle config set --local gemfile "gemfiles/rails_${{ matrix.rails_version }}.gemfile" + bundle config set --local path 'vendor/bundle' + bundle install + - name: Configure config database.yml + run: bundle exec rake db:copy_credentials + - name: Database Setup + run: bundle exec rake db:test:prepare + - name: Run tests + run: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/test-results/rspec/rspec.xml +# - store_test_results: +# path: ~/test-results/rspec/ \ No newline at end of file diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml deleted file mode 100644 index 6b1b315a..00000000 --- a/.github/workflows/reviewdog.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: reviewdog -on: [push, pull_request] -jobs: - rubocop: - name: runner / rubocop - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v2 - - name: Read ruby version - run: echo ::set-output name=RUBY_VERSION::$(cat .ruby-version | cut -f 1,2 -d .) - id: rv - - uses: ruby/setup-ruby@v1 - with: - ruby-version: "${{ steps.rv.outputs.RUBY_VERSION }}" - - uses: reviewdog/action-rubocop@v1 - with: - filter_mode: nofilter - reporter: github-check - rubocop_version: 0.93.1 - github_token: ${{ secrets.github_token }} - rubocop_extensions: rubocop-performance:1.10.2 rubocop-rails:2.9.1 rubocop-rspec:1.44.1 diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index e4fbf340..33cb28e2 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -40,9 +40,9 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '~> 3.4' s.add_development_dependency 'rspec_junit_formatter' s.add_development_dependency 'rspec-rails', '~> 6.1' - s.add_development_dependency 'rubocop', '~> 0.93' - s.add_development_dependency 'rubocop-performance', '~> 1.10' - s.add_development_dependency 'rubocop-rails', '~> 2.1' + s.add_development_dependency 'rubocop', '~> 0.93.1' + s.add_development_dependency 'rubocop-performance', '~> 1.10.2' + s.add_development_dependency 'rubocop-rails', '~> 2.9.1' s.add_development_dependency 'rubocop-rspec', '~> 1.44' if defined?(JRUBY_VERSION) From 588a67d11395e959da1fa4212269704023d2b293 Mon Sep 17 00:00:00 2001 From: Matt Pasquini Date: Tue, 7 May 2024 11:49:30 -0700 Subject: [PATCH 2/5] Cache bundle, upgrade Rubocop and move to own workflow --- .github/workflows/main.yml | 50 +--- .github/workflows/rubocop.yml | 23 ++ .rubocop.yml | 4 + .rubocop_todo.yml | 308 +++++++++++++++++++---- ros-apartment.gemspec | 8 +- spec/examples/schema_adapter_examples.rb | 2 - spec/spec_helper.rb | 2 + 7 files changed, 294 insertions(+), 103 deletions(-) create mode 100644 .github/workflows/rubocop.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aad40dd1..761dd2bc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,34 +9,8 @@ on: types: [published] jobs: - rubocop: - name: runner / rubocop - runs-on: ubuntu-latest - strategy: - matrix: - rails_version: -# - 6_1 - - 7_0 -# - 7_1 -# - master - steps: - - uses: actions/checkout@v4 - - name: Read .ruby-version file - id: getrubyversion - run: echo "RUBY_VERSION=$(cat .ruby-version)" >> $GITHUB_OUTPUT - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ steps.getrubyversion.outputs.RUBY_VERSION }} - - run: ls -la - - name: Set up Rails ${{ matrix.rails_version }} - run: | - bundle config set --local gemfile "gemfiles/rails_${{ matrix.rails_version }}.gemfile" - bundle config set --local path 'vendor/bundle' - bundle install - - name: Rubocop - run: "bundle exec rubocop" - test: + name: rails / rspec runs-on: ubuntu-latest strategy: matrix: @@ -47,29 +21,24 @@ jobs: - 6_1 - 7_0 - 7_1 -# - master - # Service containers to run with `container-job` + #- master + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}.gemfile services: - # Label used to access the service container postgres: - # Docker Hub image - image: postgres:14 - # Provide the password for postgres + image: postgres:14 # pg_dump tests currently depend on this version env: POSTGRES_PASSWORD: postgres POSTGRES_HOST_AUTH_METHOD: trust POSTGRES_DB: apartment_postgresql_test - # Set health checks to wait until postgres has started options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - # Maps tcp port 5432 on service container to the host - 5432:5432 mysql: - # Docker Hub image image: mysql:8.0 env: MYSQL_ALLOW_EMPTY_PASSWORD: true @@ -80,7 +49,6 @@ jobs: --health-timeout 5s --health-retries 5 ports: - # Maps tcp port 3306 on service container to the host - 3306:3306 steps: - uses: actions/checkout@v4 @@ -88,16 +56,10 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby_version }} - - name: Set up Rails ${{ matrix.rails_version }} - run: | - bundle config set --local gemfile "gemfiles/rails_${{ matrix.rails_version }}.gemfile" - bundle config set --local path 'vendor/bundle' - bundle install + bundler-cache: true - name: Configure config database.yml run: bundle exec rake db:copy_credentials - name: Database Setup run: bundle exec rake db:test:prepare - name: Run tests run: bundle exec rspec --format progress --format RspecJunitFormatter -o ~/test-results/rspec/rspec.xml -# - store_test_results: -# path: ~/test-results/rspec/ \ No newline at end of file diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 00000000..17c7cc3d --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,23 @@ +name: Ruby +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened] + release: + types: [published] + +jobs: + rubocop: + name: runner / rubocop + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_7_0.gemfile + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - name: Rubocop + run: "bundle exec rubocop" \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 998c5846..96016cce 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,6 +7,7 @@ require: AllCops: Exclude: + - vendor/bundle/**/* - gemfiles/**/*.gemfile - gemfiles/vendor/**/* - spec/dummy_engine/dummy_engine.gemspec @@ -30,3 +31,6 @@ Rails/ApplicationRecord: Rails/Output: Enabled: false + +Style/Documentation: + Enabled: false \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d8338622..1789f10f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,24 +1,92 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-06-26 03:25:28 UTC using RuboCop version 0.93.1. +# on 2024-05-07 18:57:21 UTC using RuboCop version 1.63.4. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/DeprecatedAttributeAssignment: + Exclude: + - 'ros-apartment.gemspec' + +# Offense count: 20 +# Configuration parameters: EnforcedStyle, AllowedGems, Include. +# SupportedStyles: Gemfile, gems.rb, gemspec +# Include: **/*.gemspec, **/Gemfile, **/gems.rb +Gemspec/DevelopmentDependencies: + Exclude: + - 'ros-apartment.gemspec' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'ros-apartment.gemspec' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'spec/dummy/config/initializers/backtrace_silencers.rb' + - 'spec/dummy/config/initializers/inflections.rb' + - 'spec/dummy/config/initializers/mime_types.rb' + - 'spec/dummy_engine/test/dummy/config/initializers/backtrace_silencers.rb' + - 'spec/dummy_engine/test/dummy/config/initializers/inflections.rb' + - 'spec/dummy_engine/test/dummy/config/initializers/mime_types.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowDoxygenCommentStyle, AllowGemfileRubyComment. +Layout/LeadingCommentSpace: + Exclude: + - 'ros-apartment.gemspec' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/LineEndStringConcatenationIndentation: + Exclude: + - 'lib/apartment/custom_console.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +Layout/SpaceBeforeComment: + Exclude: + - 'ros-apartment.gemspec' + # Offense count: 1 Lint/MixedRegexpCaptureTypes: Exclude: - 'lib/apartment/elevators/domain.rb' -# Offense count: 3 -# Configuration parameters: IgnoredMethods. +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'spec/support/config.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/RedundantDirGlobSort: + Exclude: + - 'spec/spec_helper.rb' + +# Offense count: 2 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 28 -# Offense count: 5 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. -# ExcludedMethods: refine +# Offense count: 4 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine Metrics/BlockLength: Max: 83 @@ -28,26 +96,51 @@ Metrics/ClassLength: Max: 151 # Offense count: 6 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 24 + Max: 23 + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, BlockForwardingName. +# SupportedStyles: anonymous, explicit +Naming/BlockForwarding: + Exclude: + - 'lib/apartment/adapters/abstract_adapter.rb' + - 'lib/apartment/log_subscriber.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Performance/RedundantBlockCall: + Exclude: + - 'lib/apartment/tasks/task_helper.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Performance/StringIdentifierArgument: + Exclude: + - 'lib/apartment/railtie.rb' # Offense count: 3 RSpec/AnyInstance: Exclude: - 'spec/unit/migrator_spec.rb' +# Offense count: 4 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/adapters/sqlite3_adapter_spec.rb' + - 'spec/unit/elevators/first_subdomain_spec.rb' + # Offense count: 2 RSpec/BeforeAfterAll: Exclude: - - 'spec/spec_helper.rb' - - 'spec/rails_helper.rb' - - 'spec/support/**/*.rb' - 'spec/adapters/sqlite3_adapter_spec.rb' - 'spec/tasks/apartment_rake_spec.rb' # Offense count: 18 -# Configuration parameters: Prefixes. +# Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without RSpec/ContextWording: Exclude: @@ -58,7 +151,7 @@ RSpec/ContextWording: - 'spec/tasks/apartment_rake_spec.rb' - 'spec/tenant_spec.rb' -# Offense count: 4 +# Offense count: 5 # Configuration parameters: IgnoredMetadata. RSpec/DescribeClass: Exclude: @@ -68,9 +161,9 @@ RSpec/DescribeClass: - 'spec/integration/use_within_an_engine_spec.rb' - 'spec/tasks/apartment_rake_spec.rb' -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: SkipBlocks, EnforcedStyle. +# Offense count: 6 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants. # SupportedStyles: described_class, explicit RSpec/DescribedClass: Exclude: @@ -80,25 +173,21 @@ RSpec/DescribedClass: - 'spec/unit/migrator_spec.rb' # Offense count: 5 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). RSpec/EmptyLineAfterFinalLet: Exclude: - 'spec/adapters/sqlite3_adapter_spec.rb' - 'spec/examples/schema_adapter_examples.rb' # Offense count: 14 -# Configuration parameters: Max. +# Configuration parameters: CountAsOne. RSpec/ExampleLength: - Exclude: - - 'spec/examples/generic_adapter_custom_configuration_example.rb' - - 'spec/examples/generic_adapter_examples.rb' - - 'spec/examples/schema_adapter_examples.rb' - - 'spec/integration/query_caching_spec.rb' - - 'spec/tenant_spec.rb' + Max: 12 -# Offense count: 60 -# Cop supports --auto-correct. -# Configuration parameters: CustomTransform, IgnoredWords. +# Offense count: 58 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: CustomTransform, IgnoredWords, DisallowedExamples. +# DisallowedExamples: works RSpec/ExampleWording: Exclude: - 'spec/adapters/sqlite3_adapter_spec.rb' @@ -112,8 +201,9 @@ RSpec/ExampleWording: - 'spec/tasks/apartment_rake_spec.rb' - 'spec/tenant_spec.rb' -# Offense count: 13 -# Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Offense count: 12 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* RSpec/FilePath: Exclude: - 'spec/adapters/mysql2_adapter_spec.rb' @@ -130,7 +220,7 @@ RSpec/FilePath: - 'spec/unit/migrator_spec.rb' # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. # SupportedStyles: implicit, each, example RSpec/HookArgument: @@ -138,13 +228,20 @@ RSpec/HookArgument: - 'spec/support/setup.rb' # Offense count: 4 -# Cop supports --auto-correct. +# This cop supports safe autocorrection (--autocorrect). RSpec/HooksBeforeExamples: Exclude: - 'spec/adapters/sqlite3_adapter_spec.rb' - 'spec/examples/schema_adapter_examples.rb' -# Offense count: 18 +# Offense count: 4 +# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns. +RSpec/IndexedLet: + Exclude: + - 'spec/examples/schema_adapter_examples.rb' + - 'spec/support/contexts.rb' + +# Offense count: 16 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: @@ -154,18 +251,13 @@ RSpec/InstanceVariable: - 'spec/integration/use_within_an_engine_spec.rb' - 'spec/tasks/apartment_rake_spec.rb' -# Offense count: 1 -# Cop supports --auto-correct. -RSpec/LeadingSubject: - Exclude: - # Offense count: 2 RSpec/LeakyConstantDeclaration: Exclude: - 'spec/examples/generic_adapters_callbacks_examples.rb' - 'spec/unit/elevators/generic_spec.rb' -# Offense count: 35 +# Offense count: 27 # Configuration parameters: EnforcedStyle. # SupportedStyles: have_received, receive RSpec/MessageSpies: @@ -181,12 +273,22 @@ RSpec/MessageSpies: - 'spec/unit/elevators/subdomain_spec.rb' - 'spec/unit/migrator_spec.rb' -# Offense count: 29 +# Offense count: 11 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: hash, symbol +RSpec/MetadataStyle: + Exclude: + - 'spec/examples/schema_adapter_examples.rb' + - 'spec/support/contexts.rb' + +# Offense count: 27 RSpec/MultipleExpectations: - Max: 4 + Max: 6 -# Offense count: 47 -# Configuration parameters: IgnoreSharedExamples. +# Offense count: 46 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only RSpec/NamedSubject: Exclude: - 'spec/adapters/mysql2_adapter_spec.rb' @@ -195,31 +297,69 @@ RSpec/NamedSubject: - 'spec/support/requirements.rb' - 'spec/tenant_spec.rb' -# Offense count: 24 +# Offense count: 22 +# Configuration parameters: AllowedGroups. RSpec/NestedGroups: Max: 5 -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: and_return, block -RSpec/ReturnFromStub: +# Offense count: 1 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: Exclude: - - 'spec/integration/apartment_rake_integration_spec.rb' + - 'spec/tenant_spec.rb' + +# Offense count: 12 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata. +# Include: **/*_spec.rb +RSpec/SpecFilePathFormat: + Exclude: + - 'spec/adapters/mysql2_adapter_spec.rb' + - 'spec/adapters/postgresql_adapter_spec.rb' + - 'spec/adapters/sqlite3_adapter_spec.rb' + - 'spec/tenant_spec.rb' + - 'spec/unit/config_spec.rb' + - 'spec/unit/elevators/domain_spec.rb' + - 'spec/unit/elevators/first_subdomain_spec.rb' + - 'spec/unit/elevators/generic_spec.rb' + - 'spec/unit/elevators/host_hash_spec.rb' + - 'spec/unit/elevators/host_spec.rb' + - 'spec/unit/elevators/subdomain_spec.rb' - 'spec/unit/migrator_spec.rb' -# Offense count: 4 +# Offense count: 2 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/integration/apartment_rake_integration_spec.rb' - 'spec/unit/elevators/first_subdomain_spec.rb' -# Offense count: 17 +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Rails/IndexWith: + Exclude: + - 'lib/apartment.rb' + - 'spec/unit/config_spec.rb' + +# Offense count: 7 +# This cop supports unsafe autocorrection (--autocorrect-all). +Rails/Pluck: + Exclude: + - 'spec/adapters/jdbc_mysql_adapter_spec.rb' + - 'spec/adapters/jdbc_postgresql_adapter_spec.rb' + - 'spec/adapters/mysql2_adapter_spec.rb' + - 'spec/adapters/postgresql_adapter_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Security/IoMethods: + Exclude: + - 'spec/support/config.rb' + +# Offense count: 16 +# Configuration parameters: AllowedConstants. Style/Documentation: Exclude: - - 'spec/**/*' - - 'test/**/*' - 'lib/apartment/adapters/jdbc_mysql_adapter.rb' - 'lib/apartment/adapters/postgis_adapter.rb' - 'lib/apartment/adapters/postgresql_adapter.rb' @@ -232,3 +372,65 @@ Style/Documentation: - 'lib/apartment/tasks/enhancements.rb' - 'lib/apartment/tasks/task_helper.rb' - 'lib/generators/apartment/install/install_generator.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'lib/apartment/adapters/postgresql_adapter.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# SupportedShorthandSyntax: always, never, either, consistent +Style/HashSyntax: + Exclude: + - 'lib/apartment/active_record/connection_handling.rb' + - 'spec/integration/connection_handling_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self, forbidden +Style/ModuleFunction: + Exclude: + - 'lib/apartment/migrator.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantConstantBase: + Exclude: + - 'spec/apartment_spec.rb' + - 'spec/dummy/config.ru' + - 'spec/dummy_engine/test/dummy/config.ru' + - 'spec/dummy_engine/test/dummy/config/environments/production.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantParentheses: + Exclude: + - 'lib/apartment.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpArgument: + Exclude: + - 'lib/apartment/tasks/enhancements.rb' + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'lib/apartment/migrator.rb' + - 'lib/tasks/apartment.rake' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/SuperWithArgsParentheses: + Exclude: + - 'lib/apartment/adapters/sqlite3_adapter.rb' + - 'lib/apartment/elevators/host_hash.rb' diff --git a/ros-apartment.gemspec b/ros-apartment.gemspec index 33cb28e2..41ede576 100644 --- a/ros-apartment.gemspec +++ b/ros-apartment.gemspec @@ -40,10 +40,10 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '~> 3.4' s.add_development_dependency 'rspec_junit_formatter' s.add_development_dependency 'rspec-rails', '~> 6.1' - s.add_development_dependency 'rubocop', '~> 0.93.1' - s.add_development_dependency 'rubocop-performance', '~> 1.10.2' - s.add_development_dependency 'rubocop-rails', '~> 2.9.1' - s.add_development_dependency 'rubocop-rspec', '~> 1.44' + s.add_development_dependency 'rubocop', '~> 1.63' + s.add_development_dependency 'rubocop-performance', '~> 1.21' + s.add_development_dependency 'rubocop-rails', '~> 2.24' + s.add_development_dependency 'rubocop-rspec', '~> 2.29' if defined?(JRUBY_VERSION) s.add_development_dependency 'activerecord-jdbc-adapter' diff --git a/spec/examples/schema_adapter_examples.rb b/spec/examples/schema_adapter_examples.rb index 34a1d2f4..aa1a1340 100644 --- a/spec/examples/schema_adapter_examples.rb +++ b/spec/examples/schema_adapter_examples.rb @@ -128,7 +128,6 @@ end end - # rubocop:disable RSpec/MultipleExpectations it 'connects and resets' do subject.switch(schema1) do expect(connection.schema_search_path).to start_with %("#{schema1}") @@ -140,7 +139,6 @@ expect(User.sequence_name).to eq "#{User.table_name}_id_seq" expect(Company.sequence_name).to eq "#{public_schema}.#{Company.table_name}_id_seq" end - # rubocop:enable RSpec/MultipleExpectations it 'allows a list of schemas' do subject.switch([schema1, schema2]) do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index caf2222c..ef957d40 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,9 +42,11 @@ config.include Apartment::Spec::Setup # Somewhat brutal hack so that rails 4 postgres extensions don't modify this file + # rubocop:disable RSpec/BeforeAfterAll config.after(:all) do `git checkout -- spec/dummy/db/schema.rb` end + # rubocop:enable RSpec/BeforeAfterAll # rspec-rails 3 will no longer automatically infer an example group's spec type # from the file location. You can explicitly opt-in to the feature using this From ce445e0d9e8c6dd935f6cda06e963d623e0de3a2 Mon Sep 17 00:00:00 2001 From: Matt Pasquini Date: Fri, 10 May 2024 11:46:08 -0700 Subject: [PATCH 3/5] Full test matrix with jruby Silence jdbc mysql driver warning --- .github/workflows/main.yml | 10 +++++++++- spec/config/database.yml.sample | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 761dd2bc..35197fcf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,17 +13,25 @@ jobs: name: rails / rspec runs-on: ubuntu-latest strategy: + fail-fast: false matrix: ruby_version: + - 3.0 - 3.1 - 3.2 + - 3.3 + - jruby rails_version: - 6_1 - 7_0 - 7_1 - #- master + # - master # versions failing + exclude: + - ruby_version: jruby + rails_version: 7_1 env: BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails_version }}.gemfile + CI: true services: postgres: image: postgres:14 # pg_dump tests currently depend on this version diff --git a/spec/config/database.yml.sample b/spec/config/database.yml.sample index e59c63a4..3455e9bc 100644 --- a/spec/config/database.yml.sample +++ b/spec/config/database.yml.sample @@ -17,7 +17,7 @@ connections: database: apartment_mysql_test username: root min_messages: WARNING - driver: com.mysql.jdbc.Driver + driver: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/apartment_mysql_test timeout: 5000 pool: 5 From 7fed11020f878d80bbd6378e8c39237f20ff6919 Mon Sep 17 00:00:00 2001 From: Matt Pasquini Date: Mon, 13 May 2024 14:38:25 -0700 Subject: [PATCH 4/5] Fix Failing jruby mysql test --- spec/adapters/jdbc_mysql_adapter_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/adapters/jdbc_mysql_adapter_spec.rb b/spec/adapters/jdbc_mysql_adapter_spec.rb index de9c3860..ece19886 100644 --- a/spec/adapters/jdbc_mysql_adapter_spec.rb +++ b/spec/adapters/jdbc_mysql_adapter_spec.rb @@ -9,8 +9,8 @@ subject(:adapter) { Apartment::Tenant.adapter } def tenant_names - ActiveRecord::Base.connection.execute('SELECT schema_name FROM information_schema.schemata').collect do |row| - row['schema_name'] + ActiveRecord::Base.connection.execute('SELECT SCHEMA_NAME FROM information_schema.schemata').collect do |row| + row['SCHEMA_NAME'] end end From e5bc39630b03fbc2d78828aac6186a243161f8ce Mon Sep 17 00:00:00 2001 From: Matt Pasquini Date: Mon, 13 May 2024 16:14:34 -0700 Subject: [PATCH 5/5] Possible jruby postgres fix strip leading and trailing quotes from default_sequence_name override for Postgre adapter. --- lib/apartment/active_record/postgresql_adapter.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/apartment/active_record/postgresql_adapter.rb b/lib/apartment/active_record/postgresql_adapter.rb index ef878111..5426840f 100644 --- a/lib/apartment/active_record/postgresql_adapter.rb +++ b/lib/apartment/active_record/postgresql_adapter.rb @@ -8,6 +8,8 @@ module Apartment::PostgreSqlAdapterPatch def default_sequence_name(table, _column) res = super + res.delete!('"') # if rescued in super_method, trim leading and trailing quotes + schema_prefix = "#{Apartment::Tenant.current}." default_tenant_prefix = "#{Apartment::Tenant.default_tenant}."