diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 7946c44..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -engines: - bundler-audit: - enabled: true - duplication: - enabled: true - config: - languages: - - ruby - fixme: - enabled: true - rubocop: - enabled: true -ratings: - paths: - - "**.rb" -exclude_paths: -- spec/ diff --git a/.github/gemfiles/rails_4.2.gemfile b/.github/gemfiles/rails_4.2.gemfile new file mode 100644 index 0000000..837b970 --- /dev/null +++ b/.github/gemfiles/rails_4.2.gemfile @@ -0,0 +1,16 @@ +source "https://rubygems.org" + +gemspec path: '../..' + +group :test do + gem "database_cleaner", ">= 1.5" +end + +group :test, :development do + gem "pry" + gem "pry-byebug", "3.7.0" + gem "rails", "4.2.0" + gem "rake", ">= 10" + gem "rubocop", "0.81.0" + gem "sqlite3", "~> 1.3.6" +end diff --git a/.github/gemfiles/rails_6.0.gemfile b/.github/gemfiles/rails_6.0.gemfile new file mode 100644 index 0000000..73bcdab --- /dev/null +++ b/.github/gemfiles/rails_6.0.gemfile @@ -0,0 +1,16 @@ +source "https://rubygems.org" + +gemspec path: '../..' + +group :test do + gem "database_cleaner", ">= 1.5" +end + +group :test, :development do + gem "pry" + gem "pry-byebug" + gem "rails", "~> 6.0" + gem "rake", ">= 10" + gem "rubocop" + gem "sqlite3", "~> 1.4.0" +end diff --git a/.github/gemfiles/rails_7.1.gemfile b/.github/gemfiles/rails_7.1.gemfile new file mode 100644 index 0000000..4a67055 --- /dev/null +++ b/.github/gemfiles/rails_7.1.gemfile @@ -0,0 +1,16 @@ +source "https://rubygems.org" + +gemspec path: '../..' + +group :test do + gem "database_cleaner", ">= 1.5" +end + +group :test, :development do + gem "pry" + gem "pry-byebug" + gem "rails", "~> 7.1.0" + gem "rake", ">= 10" + gem "rubocop" + gem "sqlite3", "~> 1.6" +end diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..67ecfd9 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,64 @@ +name: Check the code +on: + push: + branches: + - master + pull_request: + branches: + - master +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +defaults: + run: + shell: bash +jobs: + lint: + name: lint (ruby 3.2, rails 7.1) + runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/.github/gemfiles/rails_7.1.gemfile + BUNDLE_RETRY: 1 + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + - run: bundle exec rubocop + + test-legacy: + name: test (ruby 2.3, rails 4.2) + runs-on: ubuntu-latest + env: + BUNDLER_VERSION: '1.17.3' + BUNDLE_GEMFILE: ${{ github.workspace }}/.github/gemfiles/rails_4.2.gemfile + BUNDLE_RETRY: 1 + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.3 + rubygems: 3.2.3 + bundler: 1 + bundler-cache: true + - run: bundle exec rake + + test: + name: test (ruby ${{ matrix.ruby }}, rails ${{ matrix.rails }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.2'] + rails: ['6.0', '7.1'] + env: + BUNDLE_GEMFILE: ${{ github.workspace }}/.github/gemfiles/rails_${{ matrix.rails }}.gemfile + BUNDLE_RETRY: 1 + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e9b33b3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,15 @@ +name: Release a new version +on: + release: + types: [created] +jobs: + release: + name: Publish new version on RubyGems + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: cadwallion/publish-rubygems-action@master + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + RUBYGEMS_API_KEY: ${{secrets.PUSH_RSPEC_SQLIMIT}} + RELEASE_COMMAND: rake release diff --git a/.gitignore b/.gitignore index b014a3c..eda67a4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,10 @@ /pkg/ /spec/reports/ /tmp/ -/spec/dummy/db/*.sqlite3 +/log/ +/spec/dummy/log/ +/spec/dummy/tmp/ +/spec/dummy/storage/ *.gem .rspec_status .idea/ diff --git a/.rubocop.yml b/.rubocop.yml index 78e3c8a..3f9e9d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,23 +1,25 @@ --- AllCops: - DisplayCopNames: true - DisplayStyleGuide: true + DisplayCopNames: true + DisplayStyleGuide: true + NewCops: enable StyleGuideCopsOnly: true - TargetRubyVersion: 2.6 + TargetRubyVersion: 2.3 Exclude: - spec/dummy/db/schema.rb - vendor/bundle/**/* - gemfiles/vendor/**/* + Metrics/ParameterLists: Max: 5 -Style/Alias: +Naming/FileName: Enabled: false -Style/ClassAndModuleChildren: +Style/Alias: Enabled: false -Style/FileName: +Style/ClassAndModuleChildren: Enabled: false Style/FrozenStringLiteralComment: @@ -26,6 +28,9 @@ Style/FrozenStringLiteralComment: Style/ModuleFunction: Enabled: false +Style/OptionalBooleanParameter: + Enabled: false + Style/StringLiterals: EnforcedStyle: double_quotes diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e5500d7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -sudo: false -language: ruby -cache: bundler -before_install: - - gem update --system - - gem uninstall -v '>= 1' -i $(rvm gemdir)@global -ax bundler || true - - gem install bundler -v 1.3.0 - - gem update --system -script: - - bundle exec rake -rvm: - - 2.3 - - 2.6 - - 2.7 - - 3.0 - - ruby-head -gemfile: - - gemfiles/rails_4.2.gemfile - - gemfiles/rails_5.0.gemfile - - gemfiles/rails_5.1.gemfile - - gemfiles/rails_6.0.gemfile - - gemfiles/rails_7.0.gemfile -matrix: - exclude: - - rvm: 2.3 - gemfile: gemfiles/rails_7.0.gemfile - - rvm: 2.3 - gemfile: gemfiles/rails_6.0.gemfile - - rvm: 3.0 - gemfile: gemfiles/rails_4.2.gemfile - - rvm: 2.7 - gemfile: gemfiles/rails_4.2.gemfile - - rvm: ruby-head - gemfile: gemfiles/rails_4.2.gemfile - allow_failures: - - rvm: ruby-head diff --git a/Appraisals b/Appraisals deleted file mode 100644 index 4ade057..0000000 --- a/Appraisals +++ /dev/null @@ -1,24 +0,0 @@ -appraise "rails-4.2" do - gem "rails", "~> 4.2.0" - gem "sqlite3", "~> 1.3.0" -end - -appraise "rails-5.0" do - gem "rails", "~> 5.0.0" - gem "sqlite3", "~> 1.3.0" -end - -appraise "rails-5.1" do - gem "rails", "~> 5.1.0" - gem "sqlite3", "~> 1.3.0" -end - -appraise "rails-6.0" do - gem "rails", "~> 6.0.0" - gem "sqlite3", "~> 1.4" -end - -appraise "rails-7.0" do - gem "rails", "~> 7.0.0" - gem "sqlite3", "~> 1.4" -end diff --git a/CHANGELOG.md b/CHANGELOG.md index c7a3598..f57ec9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [0.0.6] - [2023-10-06] -- Support of Rails 7.2+ (@terracatta) +- Support of Rails 7+ (@terracatta) ## [0.0.5] - [2022-02-13] - Support of Rails 7 (@kivanio) diff --git a/Gemfile b/Gemfile index cfd5a31..65f219e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,12 +1,16 @@ source "https://rubygems.org" -# Specify your gem's dependencies in tram-form.gemspec gemspec -gem "rails" -gem "sqlite3" +group :test do + gem "database_cleaner", ">= 1.5" +end group :test, :development do gem "pry" gem "pry-byebug" + gem "rails" + gem "rake", ">= 10" + gem "rubocop" + gem "sqlite3", ">= 1.3" end diff --git a/README.md b/README.md index f0b4a46..1d2b021 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,6 @@ It wraps [the answer at Stack Overflow][stack-answer] by [Ryan Bigg][ryan-bigg], For motivation and details see my [blog post "Fighting the Hydra of N+1 queries" in the Martian Chronicles][hydra]. [![Gem Version][gem-badger]][gem] -[![Build Status][travis-badger]][travis] -[![Dependency Status][gemnasium-badger]][gemnasium] -[![Code Climate][codeclimate-badger]][codeclimate] Sponsored by Evil Martians @@ -89,14 +86,8 @@ In the last example you can see that binded values are shown after the query fol The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). -[codeclimate-badger]: https://img.shields.io/codeclimate/github/nepalez/rspec-sqlimit.svg?style=flat -[codeclimate]: https://codeclimate.com/github/nepalez/rspec-sqlimit [gem-badger]: https://img.shields.io/gem/v/rspec-sqlimit.svg?style=flat [gem]: https://rubygems.org/gems/rspec-sqlimit -[gemnasium-badger]: https://img.shields.io/gemnasium/nepalez/rspec-sqlimit.svg?style=flat -[gemnasium]: https://gemnasium.com/nepalez/rspec-sqlimit -[travis-badger]: https://img.shields.io/travis/nepalez/rspec-sqlimit/master.svg?style=flat -[travis]: https://travis-ci.org/nepalez/rspec-sqlimit [stack-answer]: http://stackoverflow.com/a/5492207/1869912 [ryan-bigg]: http://ryanbigg.com/ [notification]: http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html diff --git a/Rakefile b/Rakefile index c507ff2..f8eea84 100644 --- a/Rakefile +++ b/Rakefile @@ -6,24 +6,7 @@ require "rspec/core/rake_task" # Adds dummy:db tasks. load "spec/dummy/Rakefile" -# Declares gem's own tasks. -desc "Runs test suite over all rails versions." -task :default do - if ENV["BUNDLE_GEMFILE"] =~ /gemfiles/ - Rake::Task["dummy:db:create"].reenable - Rake::Task["dummy:db:migrate"].reenable - Rake::Task[:spec].invoke - else - Rake::Task[:appraise].invoke - end -end - desc "Runs test suite." -task default: %w[dummy:db:create dummy:db:migrate] do +task default: %w[db:reset db:schema:load] do exec "bundle exec rspec spec" - exec "bundle exec rubocop" -end - -task :appraise do - exec "appraisal install && appraisal rake" end diff --git a/gemfiles/.bundle/config b/gemfiles/.bundle/config deleted file mode 100644 index c127f80..0000000 --- a/gemfiles/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_RETRY: "1" diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile deleted file mode 100644 index 38b6ff4..0000000 --- a/gemfiles/rails_4.2.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 4.2.0" -gem "sqlite3", "~> 1.3.0" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile deleted file mode 100644 index deaf249..0000000 --- a/gemfiles/rails_5.0.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 5.0.0" -gem "sqlite3", "~> 1.3.0" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_5.1.gemfile deleted file mode 100644 index 2ae2aa0..0000000 --- a/gemfiles/rails_5.1.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 5.1.0" -gem "sqlite3", "~> 1.3.0" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile deleted file mode 100644 index 23de545..0000000 --- a/gemfiles/rails_6.0.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 6.0.0" -gem "sqlite3", "~> 1.4" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile deleted file mode 100644 index d45325c..0000000 --- a/gemfiles/rails_7.0.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 7.0.0" -gem "sqlite3", "~> 1.4" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/gemfiles/rails_7.1.gemfile b/gemfiles/rails_7.1.gemfile deleted file mode 100644 index 1b6529f..0000000 --- a/gemfiles/rails_7.1.gemfile +++ /dev/null @@ -1,13 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 7.1.0" -gem "sqlite3", "~> 1.4" - -group :test, :development do - gem "pry" - gem "pry-byebug" -end - -gemspec path: "../" diff --git a/rspec-sqlimit.gemspec b/rspec-sqlimit.gemspec index 99833cd..0e818aa 100644 --- a/rspec-sqlimit.gemspec +++ b/rspec-sqlimit.gemspec @@ -13,13 +13,6 @@ Gem::Specification.new do |gem| gem.required_ruby_version = ">= 2.3" - gem.add_runtime_dependency "activerecord", "> 4.2", "< 7.2" + gem.add_runtime_dependency "activerecord", ">= 4.2.0", "< 8" gem.add_runtime_dependency "rspec", "~> 3.0" - - gem.add_development_dependency "appraisal", "~> 2.2" - gem.add_development_dependency "rspec", "~> 3.0" - gem.add_development_dependency "rake", "> 10.0" - gem.add_development_dependency "sqlite3", "~> 1.3" - gem.add_development_dependency "database_cleaner", "~> 1.5" - gem.add_development_dependency "rubocop", "~> 0.49" end diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile index 3b9a8cb..9a5ea73 100644 --- a/spec/dummy/Rakefile +++ b/spec/dummy/Rakefile @@ -1,14 +1,6 @@ -require "active_record" -require "bundler/setup" +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -namespace :dummy do - task :environment do - require_relative "lib/dummy" - end +require_relative "config/application" - namespace :db do - task load_config: :environment - end - - load "active_record/railties/databases.rake" -end +Rails.application.load_tasks diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb new file mode 100644 index 0000000..fa76233 --- /dev/null +++ b/spec/dummy/config/application.rb @@ -0,0 +1,10 @@ +require "active_record/railtie" + +module Dummy + class Application < Rails::Application + config.api_only = true + config.eager_load = false + config.enable_reloading = false + config.cache_store = :null_store + end +end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 5c2dda4..99d806c 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -1,6 +1,12 @@ ---- +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: storage/development.sqlite3 + test: - adapter: :sqlite3 - database: spec/dummy/db/test.sqlite3 - pool: 5 - timeout: 5000 + <<: *default + database: storage/test.sqlite3 diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb index 5a3ae0d..cac5315 100644 --- a/spec/dummy/config/environment.rb +++ b/spec/dummy/config/environment.rb @@ -1,10 +1,5 @@ -Dummy::Application.configure do |config| - dummy = File.expand_path "../..", __FILE__ - database_yml = File.join(dummy, "config/database.yml") +# Load the Rails application. +require_relative "application" - config.database_configuration = YAML.load File.read(database_yml) - config.db_dir = File.join(dummy, "db") - config.env = :test - config.migrations_paths = [File.join(dummy, "db/migrate")] - config.root = dummy -end +# Initialize the Rails application. +Rails.application.initialize! diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb index c10f262..7f4f7d7 100644 --- a/spec/dummy/db/schema.rb +++ b/spec/dummy/db/schema.rb @@ -1,18 +1,4 @@ -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20170211104800) do - +ActiveRecord::Schema.define(version: 2017_02_11_104800) do create_table "users", force: :cascade do |t| end - end diff --git a/spec/dummy/lib/dummy.rb b/spec/dummy/lib/dummy.rb deleted file mode 100644 index afc84aa..0000000 --- a/spec/dummy/lib/dummy.rb +++ /dev/null @@ -1,9 +0,0 @@ -require "active_record" -require "bundler/setup" - -module Dummy - require_relative "dummy/compatibility" - require_relative "dummy/application" - require_relative "../config/environment" - require_relative "../app/models/user.rb" -end diff --git a/spec/dummy/lib/dummy/application.rb b/spec/dummy/lib/dummy/application.rb deleted file mode 100644 index cea568b..0000000 --- a/spec/dummy/lib/dummy/application.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Dummy - class Application - class << self - # Configuration settings wrapper for the - # ActiveRecord::Tasks::DatabaseTasks. - # - # Establishes AR connection after configuration. - # - def configure - yield tasks - base.configurations = tasks.database_configuration - base.establish_connection(tasks.env) - end - - private - - def base - @base ||= ActiveRecord::Base - end - - def tasks - @tasks ||= ActiveRecord::Tasks::DatabaseTasks - end - end - end -end diff --git a/spec/dummy/lib/dummy/compatibility.rb b/spec/dummy/lib/dummy/compatibility.rb deleted file mode 100644 index 6e961f5..0000000 --- a/spec/dummy/lib/dummy/compatibility.rb +++ /dev/null @@ -1,11 +0,0 @@ -# ActiveRecord::Migration['5.0'] syntax is not supported prior to Rails 5.0 -# This snippet supports it on Rails 4.2 -unless ActiveRecord::Migration.respond_to?(:[]) - class ActiveRecord::Migration - class << self - def [](_version) - self - end - end - end -end diff --git a/spec/rspec/sqlimit/reporter_spec.rb b/spec/rspec/sqlimit/reporter_spec.rb index 84ddbb1..53096c6 100644 --- a/spec/rspec/sqlimit/reporter_spec.rb +++ b/spec/rspec/sqlimit/reporter_spec.rb @@ -31,7 +31,8 @@ it "prints param as an array with one element" do # INSERT INTO "users" ("id") VALUES (?); [1] (0.234 ms) - expect(subject.call).to include("VALUES (?); [1]") + # INSERT INTO "users" ("id") VALUES (?) RETURNING "id"; [1] (1.12 ms) + expect(subject.call).to match(/VALUES \(\?\).*; \[1\]/) end end @@ -43,11 +44,10 @@ end it "prints all params" do - # rubocop: disable Metrics/LineLength # SELECT "users".* FROM "users" WHERE "users"."id" IN (1, 2, 3) (0.17 ms)) # Rails >= 6: # SELECT "users".* FROM "users" WHERE "users"."id" IN (?, ?, ?); [1, 2, 3] (0.121 ms) - # rubocop: enable Metrics/LineLength + # rubocop: enable Layout/LineLength expect(subject.call).to include("1, 2, 3") end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8626533..3d96fc3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,7 @@ require "rspec-sqlimit" require "database_cleaner" -require_relative "dummy/lib/dummy" +require_relative "dummy/config/environment" DatabaseCleaner.strategy = :truncation