diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0b59fb1 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,79 @@ +# .github/workflows/ci.yml +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + env: + NOKOGIRI_USE_SYSTEM_LIBRARIES: true + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + strategy: + fail-fast: false + matrix: + include: + - gemfile: 6.0.gemfile + ruby: 2.7 + + - gemfile: 6.0.gemfile + ruby: 3.0 + + - gemfile: 6.0.gemfile + ruby: 3.1 + + - gemfile: 6.1.gemfile + ruby: 2.7 + + - gemfile: 6.1.gemfile + ruby: 3.0 + + - gemfile: 6.1.gemfile + ruby: 3.1 + + - gemfile: 7.0.gemfile + ruby: 2.7 + + - gemfile: 7.0.gemfile + ruby: 3.0 + + - gemfile: 7.0.gemfile + ruby: 3.1 + + name: ${{ matrix.gemfile }}, ruby ${{ matrix.ruby }} + + steps: + - uses: actions/checkout@v2 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - name: Bundle install + run: | + bundle config set gemfile "${GITHUB_WORKSPACE}/gemfiles/${{ matrix.gemfile }}" + bundle install --jobs 4 --retry 3 + + - name: Run tests + run: bundle exec rspec + env: + DB_HOST: localhost + DB_USERNAME: postgres + DB_PORT: 5432 + DB_PASSWORD: postgres + + - name: Rubocop + run: bundle exec rubocop diff --git a/.gitignore b/.gitignore index 5615ba4..34f1ec3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ spec/internal/log/ /test/tmp/ /test/version_tmp/ /tmp/ -Gemfile.lock +*.lock # Used by dotenv library to load environment variables. # .env @@ -50,3 +50,7 @@ build-iPhoneSimulator/ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: .rvmrc + +.idea +.rspec_status +gemfiles/.bundle/ diff --git a/.rubocop.yml b/.rubocop.yml index 9a73842..6e0c1bd 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ require: rubocop-rspec AllCops: - TargetRubyVersion: 2.5 + TargetRubyVersion: 2.7 TargetRailsVersion: 4.0 Exclude: - 'activerecord-data_integrity.gemspec' @@ -9,6 +9,7 @@ AllCops: - 'tmp/**/*' - 'gemfiles/*' - 'spec/internal/**/*' + - 'vendor/**/*' Metrics/LineLength: Max: 110 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f709866..0000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -sudo: require -services: -- docker -install: -- gem install dip -before_script: -- unset BUNDLE_GEMFILE -- dip provision -script: -- dip rspec -- dip rubocop -deploy: - provider: rubygems - api_key: - secure: Q3gyExePLXgWljK9mibX9A2AJR0GMjDJVMLYzJ4hu0vdc6+QwOTFcsDgqdhpqoOfrIBAVT5Hp+ry7slmwB8YzLMvRvM8tft7NjB2kpZE03uitDE9uYoYM9cKnguLDf3B5djLHcEy3T1ujD4wziEeU+SvVyyk/1jb1kSBRu2o4foDdveo8IB5m/DLBkz3YUYUVPd+SlyJPiVTitTRYIO5T2esENhNQHCEro1DVbXUC3e3KHuE38Nwpl6rcm54KCwp8Ji3f6135/XETxhPFRF9L5K6pLwAh6lqxEibspI9bYVOpVfNhqKvjqOY/zn+FHCgSAFIDKU1UQjAsBbYQMpIizL9gow0jQU4z87wM47wvFdZHOPtNEOivqIyiOccFxDT+X5qmqRmUY4FDi3wAqze3WXJkUadpoNPzZ78Xcl2ZVnPKbFMY2Omp7d0ghHkI31WGePKVT37S47vZZeCNPYgfMEWthNJK0Rch6nAGZBnolQoQKB/3n0ue0b3ik0pYgQkrZv/aG/3Dy5Od3aAzI84lRI78AzitiChxNZX+3c8hKtWZteBwHncdxTSeAXf9cZY9c9s7ssJGFoe7DOAWeAU84DhhbCsJ1UL87wOvserpVpaTXVs8tdsP5WSVNUucwl4CE7ewJBwFJMhELVAhzanyCmjFhjc8F2Za9Kpm/xQ7EM= - gem: activerecord-data_integrity - on: - tags: true - repo: dsalahutdinov/activerecord-data_integrity diff --git a/Appraisals b/Appraisals index 5894052..208053f 100644 --- a/Appraisals +++ b/Appraisals @@ -1,13 +1,13 @@ # frozen_string_literal: true -appraise '5.0' do - gem 'activerecord', '~> 5.0' +appraise '6.0' do + gem 'activerecord', '~> 6.0' end -appraise '5.1' do - gem 'activerecord', '~> 5.1' +appraise '6.1' do + gem 'activerecord', '~> 6.1' end -appraise '5.2' do - gem 'activerecord', '~> 5.2' +appraise '7.0' do + gem 'activerecord', '~> 7.0' end diff --git a/README.md b/README.md index 1036cf3..5447ed6 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Gem Version](https://badge.fury.io/rb/activerecord-data_integrity.svg)](https://badge.fury.io/rb/activerecord-data_integrity) -[![Build Status](https://travis-ci.org/dsalahutdinov/activerecord-data_integrity.svg?branch=master)](https://travis-ci.org/dsalahutdinov/activerecord-data_integrity.svg?branch=master) +[![CI Status](https://github.com/dsalahutdinov/activerecord-data_integrity/workflows/CI/badge.svg?branch=master)](https://github.com/dsalahutdinov/activerecord-data_integrity/actions?query=workflow%3ACI+branch%3Amaster) # ActiveRecord::DataIntegrity @@ -80,8 +80,8 @@ Otherwise (without Docker) set up environment manually: git checkout git@github.com:dsalahutdinov/activerecord-data_integrity.git cd activerecord-data_integrity bundle install -bundle appraisal -DB_HOST=localhost DB_NAME=testdb DB_USERNAME=postgres bundle appraisal rspec +bundle exec appraisal +DB_HOST=localhost DB_NAME=testdb DB_USERNAME=postgres bundle exec appraisal rspec ``` ## License diff --git a/activerecord-data_integrity.gemspec b/activerecord-data_integrity.gemspec index 99a402c..fc4af54 100644 --- a/activerecord-data_integrity.gemspec +++ b/activerecord-data_integrity.gemspec @@ -32,14 +32,14 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_runtime_dependency 'pg' - spec.add_runtime_dependency 'rails' + spec.add_runtime_dependency 'activerecord' spec.add_runtime_dependency 'rainbow' - spec.add_development_dependency 'appraisal', '~> 2.2' - spec.add_development_dependency 'bundler', '~> 1.16' - spec.add_development_dependency 'combustion', '~> 1.0' - spec.add_development_dependency 'rake', '~> 10.0' - spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'appraisal', '~> 2.4' + spec.add_development_dependency 'bundler', '~> 2.2' + spec.add_development_dependency 'combustion', '~> 1.3' + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.11' spec.add_development_dependency 'rubocop' spec.add_development_dependency 'rubocop-rspec' diff --git a/gemfiles/6.0.gemfile b/gemfiles/6.0.gemfile new file mode 100644 index 0000000..5b48be1 --- /dev/null +++ b/gemfiles/6.0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 6.0" + +gemspec path: "../" diff --git a/gemfiles/6.1.gemfile b/gemfiles/6.1.gemfile new file mode 100644 index 0000000..ed3beb6 --- /dev/null +++ b/gemfiles/6.1.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 6.1" + +gemspec path: "../" diff --git a/gemfiles/7.0.gemfile b/gemfiles/7.0.gemfile new file mode 100644 index 0000000..9e840e5 --- /dev/null +++ b/gemfiles/7.0.gemfile @@ -0,0 +1,7 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "activerecord", "~> 7.0" + +gemspec path: "../" diff --git a/lib/active_record/data_integrity.rb b/lib/active_record/data_integrity.rb index 3eb91cd..1eef8b4 100644 --- a/lib/active_record/data_integrity.rb +++ b/lib/active_record/data_integrity.rb @@ -2,7 +2,7 @@ require 'active_record/data_integrity/version' -require 'rails/all' +require 'active_record' require 'active_record/data_integrity/cli' require 'rainbow' diff --git a/lib/active_record/data_integrity/config.rb b/lib/active_record/data_integrity/config.rb index 74bdff6..fbc0937 100644 --- a/lib/active_record/data_integrity/config.rb +++ b/lib/active_record/data_integrity/config.rb @@ -14,18 +14,14 @@ def initialize(options) end def cops - @cops ||= begin - ActiveRecord::DataIntegrity::Cop.descendants.select do |cop| - only.empty? || cop.cop_name.in?(only) - end + @cops ||= ActiveRecord::DataIntegrity::Cop.descendants.select do |cop| + only.empty? || cop.cop_name.in?(only) end end def models - @models ||= begin - ActiveRecord::Base.descendants.select do |model| - model_names.empty? || model.name.in?(model_names) - end + @models ||= ActiveRecord::Base.descendants.select do |model| + model_names.empty? || model.name.in?(model_names) end end end diff --git a/lib/active_record/data_integrity/cop/cop.rb b/lib/active_record/data_integrity/cop/cop.rb index 7af3f00..c06955a 100644 --- a/lib/active_record/data_integrity/cop/cop.rb +++ b/lib/active_record/data_integrity/cop/cop.rb @@ -5,6 +5,7 @@ module DataIntegrity # Checking cop base class class Cop attr_reader :model + delegate :connection, to: :model def initialize(model) diff --git a/spec/internal/config/database.yml b/spec/internal/config/database.yml index be24105..cf179c2 100644 --- a/spec/internal/config/database.yml +++ b/spec/internal/config/database.yml @@ -1,5 +1,7 @@ test: adapter: postgresql - host: <%= ENV.fetch("DB_HOST") %> - database: <%= ENV.fetch("DB_NAME") %> - username: <%= ENV.fetch("DB_USERNAME") %> + host: <%= ENV.fetch("DB_HOST", "localhost") %> + database: <%= ENV.fetch("DB_NAME", "ar_di_test") %> + username: <%= ENV.fetch("DB_USERNAME", "postgres") %> + port: <%= ENV.fetch("DB_PORT", 5432) %> + password: <%= ENV.fetch("DB_PASSWORD", "") %> diff --git a/spec/internal/db/migrate/20180102000000_create_belongs_to_tables.rb b/spec/internal/db/migrate/20180102000000_create_belongs_to_tables.rb index 1c70783..f616e00 100644 --- a/spec/internal/db/migrate/20180102000000_create_belongs_to_tables.rb +++ b/spec/internal/db/migrate/20180102000000_create_belongs_to_tables.rb @@ -5,7 +5,6 @@ def change create_table :belongs_to_users, &:timestamps create_table :belongs_to_user_settings do |t| - t.integer :user_id t.references :user, foreign_key: { to_table: :belongs_to_users } t.text :data diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3d26c25..53e1248 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,8 +5,12 @@ require 'byebug' require 'combustion' -Combustion.initialize! :all, - database_reset: true, database_migrate: true, load_schema: false +Combustion.initialize!( + :active_record, + database_reset: true, + database_migrate: true, + load_schema: false +) RSpec.configure do |config| # Enable flags like --only-failures and --next-failure