From 282399f4529b4947006a74ec0f455029f0bfcf54 Mon Sep 17 00:00:00 2001 From: Martin Zamuner Date: Wed, 25 Oct 2023 12:18:56 +0200 Subject: [PATCH] Improve dev environment --- .github/workflows/ci.yml | 13 +- .gitignore | 2 + .rubocop.yml | 122 ++++++++++++++++++ Gemfile | 20 ++- Gemfile.lock | 199 ------------------------------ README.md | 2 +- bin/rails | 12 +- lib/cache_keeper/configuration.rb | 2 +- lib/cache_keeper/engine.rb | 4 +- test/jobs/refresh_job_test.rb | 5 +- 10 files changed, 164 insertions(+), 217 deletions(-) create mode 100644 .rubocop.yml delete mode 100644 Gemfile.lock diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 416f4e7..3dfa920 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,13 +4,20 @@ jobs: tests: strategy: matrix: - ruby-version: - - "2.7" - - "3.0" rails-version: - "6.1" - "7.0" + - "7.1" - "main" + include: + - rails-version: "6.1" + ruby-version: "2.5" + - rails-version: "7.0" + ruby-version: "2.7" + - rails-version: "7.1" + ruby-version: "2.7" + - rails-version: "main" + ruby-version: "3.2" env: RAILS_VERSION: "${{ matrix.rails-version }}" diff --git a/.gitignore b/.gitignore index 7bae84e..98be874 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ *.gem +Gemfile.lock .byebug_history +TAGS test/dummy/db/*.sqlite3 test/dummy/db/*.sqlite3* diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..e63c288 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,122 @@ +require: + - rubocop-rails + - rubocop-performance + +AllCops: + Exclude: + - '**/db/**/*' + - '**/config/**/*' + - '**/tmp/**/*' + - '**/templates/**/*' + - '**/vendor/**/*' + - '**/node_modules/**/*' + TargetRubyVersion: 3.2.2 + +# Relaxed Ruby Style +Style/Alias: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylealias + +Style/AsciiComments: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#styleasciicomments + +Style/BeginBlock: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylebeginblock + +Style/BlockDelimiters: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters + +Style/Documentation: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#styledocumentation + +Style/EndBlock: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#styleendblock + +Style/GuardClause: + Enabled: false + +Style/IfUnlessModifier: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier + +Style/ModuleFunction: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylemodulefunction + +Style/MultilineBlockChain: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain + +Style/NegatedIf: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylenegatedif + +Style/NegatedWhile: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile + +Style/NumericPredicate: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylenumericpredicate + +Style/PercentLiteralDelimiters: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters + +Style/WhileUntilModifier: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier + +Style/WordArray: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#stylewordarray + +Lint/AmbiguousRegexpLiteral: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral + +Lint/AssignmentInCondition: + Enabled: false + StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition + +Layout/LineLength: + Enabled: false + +Metrics: + Enabled: false + +# Custom +Performance: + Exclude: + - '**/spec/**/*' + +Style/FrozenStringLiteralComment: + Enabled: false + +Style/AndOr: + Enabled: true + EnforcedStyle: conditionals + +Style/ClassAndModuleChildren: + Enabled: false + +Style/HashSyntax: + Enabled: false + +Style/MixinGrouping: + Enabled: false + +Style/RegexpLiteral: + Enabled: false + +Style/StringConcatenation: + Enabled: false + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes diff --git a/Gemfile b/Gemfile index bf28e1e..3290280 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,22 @@ source "https://rubygems.org" gemspec -gem "rake" -gem "byebug" +rails_version = ENV.fetch("RAILS_VERSION", "7.1") -gem "rails", ">= 6.1" +rails_constraint = + if rails_version == "main" + { github: "rails/rails" } + else + "~> #{rails_version}.0" + end + +gem "rails", rails_constraint gem "sqlite3" + +group :debug do + gem "byebug" + + gem "rubocop" + gem "rubocop-performance" + gem "rubocop-rails" +end diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 8fd37cb..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,199 +0,0 @@ -PATH - remote: . - specs: - cache_keeper (0.3.0) - rails (>= 6.1.0) - -GEM - remote: https://rubygems.org/ - specs: - actioncable (7.1.1) - actionpack (= 7.1.1) - activesupport (= 7.1.1) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - zeitwerk (~> 2.6) - actionmailbox (7.1.1) - actionpack (= 7.1.1) - activejob (= 7.1.1) - activerecord (= 7.1.1) - activestorage (= 7.1.1) - activesupport (= 7.1.1) - mail (>= 2.7.1) - net-imap - net-pop - net-smtp - actionmailer (7.1.1) - actionpack (= 7.1.1) - actionview (= 7.1.1) - activejob (= 7.1.1) - activesupport (= 7.1.1) - mail (~> 2.5, >= 2.5.4) - net-imap - net-pop - net-smtp - rails-dom-testing (~> 2.2) - actionpack (7.1.1) - actionview (= 7.1.1) - activesupport (= 7.1.1) - nokogiri (>= 1.8.5) - rack (>= 2.2.4) - rack-session (>= 1.0.1) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - actiontext (7.1.1) - actionpack (= 7.1.1) - activerecord (= 7.1.1) - activestorage (= 7.1.1) - activesupport (= 7.1.1) - globalid (>= 0.6.0) - nokogiri (>= 1.8.5) - actionview (7.1.1) - activesupport (= 7.1.1) - builder (~> 3.1) - erubi (~> 1.11) - rails-dom-testing (~> 2.2) - rails-html-sanitizer (~> 1.6) - activejob (7.1.1) - activesupport (= 7.1.1) - globalid (>= 0.3.6) - activemodel (7.1.1) - activesupport (= 7.1.1) - activerecord (7.1.1) - activemodel (= 7.1.1) - activesupport (= 7.1.1) - timeout (>= 0.4.0) - activestorage (7.1.1) - actionpack (= 7.1.1) - activejob (= 7.1.1) - activerecord (= 7.1.1) - activesupport (= 7.1.1) - marcel (~> 1.0) - activesupport (7.1.1) - base64 - bigdecimal - concurrent-ruby (~> 1.0, >= 1.0.2) - connection_pool (>= 2.2.5) - drb - i18n (>= 1.6, < 2) - minitest (>= 5.1) - mutex_m - tzinfo (~> 2.0) - base64 (0.1.1) - bigdecimal (3.1.4) - builder (3.2.4) - byebug (11.1.3) - concurrent-ruby (1.2.2) - connection_pool (2.4.1) - crass (1.0.6) - date (3.3.3) - drb (2.1.1) - ruby2_keywords - erubi (1.12.0) - globalid (1.2.1) - activesupport (>= 6.1) - i18n (1.14.1) - concurrent-ruby (~> 1.0) - io-console (0.6.0) - irb (1.8.3) - rdoc - reline (>= 0.3.8) - loofah (2.21.4) - crass (~> 1.0.2) - nokogiri (>= 1.12.0) - mail (2.8.1) - mini_mime (>= 0.1.1) - net-imap - net-pop - net-smtp - marcel (1.0.2) - mini_mime (1.1.5) - minitest (5.20.0) - mutex_m (0.1.2) - net-imap (0.4.2) - date - net-protocol - net-pop (0.1.2) - net-protocol - net-protocol (0.2.1) - timeout - net-smtp (0.4.0) - net-protocol - nio4r (2.5.9) - nokogiri (1.15.4-arm64-darwin) - racc (~> 1.4) - nokogiri (1.15.4-x86_64-linux) - racc (~> 1.4) - psych (5.1.1.1) - stringio - racc (1.7.1) - rack (3.0.8) - rack-session (2.0.0) - rack (>= 3.0.0) - rack-test (2.1.0) - rack (>= 1.3) - rackup (2.1.0) - rack (>= 3) - webrick (~> 1.8) - rails (7.1.1) - actioncable (= 7.1.1) - actionmailbox (= 7.1.1) - actionmailer (= 7.1.1) - actionpack (= 7.1.1) - actiontext (= 7.1.1) - actionview (= 7.1.1) - activejob (= 7.1.1) - activemodel (= 7.1.1) - activerecord (= 7.1.1) - activestorage (= 7.1.1) - activesupport (= 7.1.1) - bundler (>= 1.15.0) - railties (= 7.1.1) - rails-dom-testing (2.2.0) - activesupport (>= 5.0.0) - minitest - nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) - loofah (~> 2.21) - nokogiri (~> 1.14) - railties (7.1.1) - actionpack (= 7.1.1) - activesupport (= 7.1.1) - irb - rackup (>= 1.0.0) - rake (>= 12.2) - thor (~> 1.0, >= 1.2.2) - zeitwerk (~> 2.6) - rake (13.0.6) - rdoc (6.5.0) - psych (>= 4.0.0) - reline (0.3.9) - io-console (~> 0.5) - ruby2_keywords (0.0.5) - sqlite3 (1.6.7-arm64-darwin) - sqlite3 (1.6.7-x86_64-linux) - stringio (3.0.8) - thor (1.3.0) - timeout (0.4.0) - tzinfo (2.0.6) - concurrent-ruby (~> 1.0) - webrick (1.8.1) - websocket-driver (0.7.6) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - zeitwerk (2.6.12) - -PLATFORMS - arm64-darwin-22 - x86_64-linux - -DEPENDENCIES - byebug - cache_keeper! - rails (>= 6.1) - rake - sqlite3 - -BUNDLED WITH - 2.4.19 diff --git a/README.md b/README.md index d3a3d3d..be48bb9 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ class Example end ``` -If those options don't work for you, you can always [write custom serializer](https://guides.rubyonrails.org/active_job_basics.html#serializers) for your classes. +If those options don't work for you, you can always [write custom serializers](https://guides.rubyonrails.org/active_job_basics.html#serializers) for your classes. ## Configuration diff --git a/bin/rails b/bin/rails index de173dd..38401bb 100755 --- a/bin/rails +++ b/bin/rails @@ -2,12 +2,12 @@ # This command will automatically be run when you run "rails" with Rails gems # installed from the root of your application. -ENGINE_ROOT = File.expand_path('..', __dir__) -APP_PATH = File.expand_path('../test/dummy/config/application', __dir__) +ENGINE_ROOT = File.expand_path("..", __dir__) +APP_PATH = File.expand_path("../test/dummy/config/application", __dir__) # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"]) -require 'rails/all' -require 'rails/engine/commands' +require "rails/all" +require "rails/engine/commands" diff --git a/lib/cache_keeper/configuration.rb b/lib/cache_keeper/configuration.rb index c7c8e04..f1e1d3e 100644 --- a/lib/cache_keeper/configuration.rb +++ b/lib/cache_keeper/configuration.rb @@ -1,7 +1,7 @@ module CacheKeeper class Configuration DEFAULT_MUST_REVALIDATE = false - DEFAULT_QUEUES = {} + DEFAULT_QUEUES = {}.freeze def must_revalidate return rails_config.must_revalidate unless rails_config.must_revalidate.nil? diff --git a/lib/cache_keeper/engine.rb b/lib/cache_keeper/engine.rb index 26d9a2c..231412f 100644 --- a/lib/cache_keeper/engine.rb +++ b/lib/cache_keeper/engine.rb @@ -7,13 +7,13 @@ class Engine < ::Rails::Engine config.cache_keeper = ActiveSupport::OrderedOptions.new config.cache_keeper.queues = ActiveSupport::OrderedOptions.new - initializer "cache_keeper.active_job_serializer" do |app| + initializer "cache_keeper.active_job_serializer" do config.to_prepare do Rails.application.config.active_job.custom_serializers << CacheKeeper::CachedMethodSerializer end end - initializer "cache_keeper.caching_methods" do |app| + initializer "cache_keeper.caching_methods" do ActiveSupport.on_load :action_controller do ActionController::Base.send :include, CacheKeeper::Caching end diff --git a/test/jobs/refresh_job_test.rb b/test/jobs/refresh_job_test.rb index 557a19c..1605ae6 100644 --- a/test/jobs/refresh_job_test.rb +++ b/test/jobs/refresh_job_test.rb @@ -3,11 +3,12 @@ class CacheKeeper::RefreshJobTest < ActiveSupport::TestCase include ActiveJob::TestHelper - test "calls #refresh" do + test "uses the correct queue" do + CacheKeeper.configuration.queues[:refresh] = "refresh" recording = Recording.create(number: 5) cached_method = CacheKeeper.manager.cached_methods.first - assert_performed_with(queue: :default) do + assert_performed_with(queue: "refresh") do CacheKeeper::RefreshJob.perform_later cached_method, recording end end