diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2cb439..10640a8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,14 +7,12 @@ on: push: branches: - master + jobs: sqlite: runs-on: ubuntu-latest - env: - BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile BUNDLE_PATH_RELATIVE_TO_CWD: true - steps: - name: SQLite3 version run: sqlite3 --version @@ -30,8 +28,7 @@ jobs: run: bundle exec standardrb - name: Run tests env: - DATABASE_URL: "sqlite3:pay_test" - STRIPE_PRIVATE_KEY: ${{ secrets.STRIPE_PRIVATE_KEY }} + DATABASE_URL: "sqlite3:signalman_test" run: | bin/rails db:test:prepare bin/rails test:all diff --git a/Gemfile b/Gemfile index 24a952e..b8de5eb 100644 --- a/Gemfile +++ b/Gemfile @@ -16,3 +16,5 @@ gem "web-console", group: :development # Start debugger with binding.b [https://github.com/ruby/debug] # gem "debug", ">= 1.0.0" + +gem "standardrb", "~> 1.0" diff --git a/Gemfile.lock b/Gemfile.lock index deee956..c107815 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,6 +74,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.5) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) bindex (0.8.1) builder (3.2.4) capybara (3.39.2) @@ -97,6 +98,9 @@ GEM importmap-rails (1.2.1) actionpack (>= 6.0.0) railties (>= 6.0.0) + json (2.6.3) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) loofah (2.21.3) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -128,11 +132,15 @@ GEM racc (~> 1.4) nokogiri (1.15.3-x86_64-linux) racc (~> 1.4) + parallel (1.23.0) + parser (3.2.2.3) + ast (~> 2.4.1) + racc public_suffix (5.0.3) puma (6.3.0) nio4r (~> 2.0) racc (1.7.1) - rack (2.2.7) + rack (2.2.8) rack-test (2.1.0) rack (>= 1.3) rails (7.0.6) @@ -149,7 +157,7 @@ GEM activesupport (= 7.0.6) bundler (>= 1.15.0) railties (= 7.0.6) - rails-dom-testing (2.1.1) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) @@ -163,13 +171,30 @@ GEM rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) + rainbow (3.1.1) rake (13.0.6) redis (5.0.6) redis-client (>= 0.9.0) - redis-client (0.14.1) + redis-client (0.15.0) connection_pool regexp_parser (2.8.1) rexml (3.2.6) + rubocop (1.52.1) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.2.3) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) + rubocop-performance (1.18.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.13.0) rubyzip (2.3.2) selenium-webdriver (4.11.0) rexml (~> 3.2, >= 3.2.5) @@ -186,6 +211,20 @@ GEM sqlite3 (1.6.3-arm64-darwin) sqlite3 (1.6.3-x86_64-darwin) sqlite3 (1.6.3-x86_64-linux) + standard (1.30.1) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.52.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.1.0) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.1.2) + lint_roller (~> 1.1) + rubocop-performance (~> 1.18.0) + standardrb (1.0.1) + standard thor (1.2.2) timeout (0.4.0) turbo-rails (1.4.0) @@ -194,6 +233,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (2.4.2) web-console (4.2.0) actionview (>= 6.0.0) activemodel (>= 6.0.0) @@ -205,7 +245,7 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.9) + zeitwerk (2.6.11) PLATFORMS aarch64-linux @@ -222,6 +262,7 @@ DEPENDENCIES signalman! sprockets-rails sqlite3 + standardrb (~> 1.0) turbo-rails web-console diff --git a/README.md b/README.md index d93baf6..e85a79f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Signalman A debug tool for Ruby on Rails application. +[![Tests](https://github.com/excid3/signalman/actions/workflows/ci.yml/badge.svg)](https://github.com/excid3/signalman/actions/workflows/ci.yml) + ## Usage How to use my plugin. diff --git a/Rakefile b/Rakefile index e7793b5..1fc8c92 100644 --- a/Rakefile +++ b/Rakefile @@ -6,3 +6,12 @@ load "rails/tasks/engine.rake" load "rails/tasks/statistics.rake" require "bundler/gem_tasks" +require "rake/testtask" + +Rake::TestTask.new("test:all") do |t| + t.libs << "test" + t.pattern = "test/**/*_test.rb" + t.verbose = false +end + +task default: "test:all" diff --git a/app/controllers/signalman/generators/models_controller.rb b/app/controllers/signalman/generators/models_controller.rb index 2f9f2bb..1c3a102 100644 --- a/app/controllers/signalman/generators/models_controller.rb +++ b/app/controllers/signalman/generators/models_controller.rb @@ -6,7 +6,7 @@ def show end def create - @fields = params[:fields].map{ |field| [field[:name], field[:type]].join(":") } + @fields = params[:fields].map { |field| [field[:name], field[:type]].join(":") } Bundler.with_original_env do @stdout, @stderr, @status = Open3.capture3("rails", "generate", "model", params[:model_name], *@fields) end diff --git a/app/controllers/signalman/generators/scaffolds_controller.rb b/app/controllers/signalman/generators/scaffolds_controller.rb index d85d0f5..931c4c3 100644 --- a/app/controllers/signalman/generators/scaffolds_controller.rb +++ b/app/controllers/signalman/generators/scaffolds_controller.rb @@ -6,7 +6,7 @@ def show end def create - @fields = params[:fields].map{ |field| [field[:name], field[:type]].join(":") } + @fields = params[:fields].map { |field| [field[:name], field[:type]].join(":") } Bundler.with_original_env do @stdout, @stderr, @status = Open3.capture3("rails", "generate", "scaffold", params[:model_name], *@fields) end diff --git a/app/helpers/signalman/events_helper.rb b/app/helpers/signalman/events_helper.rb index dbb5e72..f2007ea 100644 --- a/app/helpers/signalman/events_helper.rb +++ b/app/helpers/signalman/events_helper.rb @@ -1,7 +1,7 @@ module Signalman module EventsHelper def signalman_path_for(event) - block = Signalman.events.find{ |key, _| key.match? event.name }.last[:path] + block = Signalman.events.find { |key, _| key.match? event.name }.last[:path] instance_exec event, &block end diff --git a/app/models/signalman/event.rb b/app/models/signalman/event.rb index 6c02474..07ea0e6 100644 --- a/app/models/signalman/event.rb +++ b/app/models/signalman/event.rb @@ -1,13 +1,13 @@ class Signalman::Event < ApplicationRecord - scope :requests, ->{ where(name: "process_action.action_controller") } - scope :mails, ->{ where(name: "deliver.action_mailer") } - scope :queries, ->{ where(name: "sql.active_record") } - scope :views, ->{ + scope :requests, -> { where(name: "process_action.action_controller") } + scope :mails, -> { where(name: "deliver.action_mailer") } + scope :queries, -> { where(name: "sql.active_record") } + scope :views, -> { where(name: [ "render_template.action_view", "render_partial.action_view", "render_collection.action_view", - "render_layout.action_view", + "render_layout.action_view" ]) } scope :jobs, -> { @@ -16,10 +16,9 @@ class Signalman::Event < ApplicationRecord "enqueue.active_job", "perform.active_job", "perform_start.active_job", - "discard.active_job", + "discard.active_job" ]) } - - scope :recent_first, ->{ order(created_at: :desc) } + scope :recent_first, -> { order(created_at: :desc) } end diff --git a/lib/signalman.rb b/lib/signalman.rb index 323804d..aed6068 100644 --- a/lib/signalman.rb +++ b/lib/signalman.rb @@ -66,16 +66,16 @@ def process end create_event event.payload.slice( - :method, - :path, - :controller, - :action, - :params, - :format, - :status, - :db_runtime, - :view_runtime - ).merge(headers: headers) + :method, + :path, + :controller, + :action, + :params, + :format, + :status, + :db_runtime, + :view_runtime + ).merge(headers: headers) end def skip? @@ -101,7 +101,7 @@ class QueryHandler < BaseHandler # CREATE_TABLE queries have nil for `name` def skip? return if event.payload[:name].blank? - IGNORED_QUERIES.any?{ |q| q.match? event.payload[:name] } + IGNORED_QUERIES.any? { |q| q.match? event.payload[:name] } end def process @@ -147,7 +147,11 @@ def format(arg) when Array arg.map { |value| format(value) } when GlobalID::Identification - arg.to_global_id rescue arg + begin + arg.to_global_id + rescue + arg + end else arg end diff --git a/lib/signalman/engine.rb b/lib/signalman/engine.rb index 20b54a4..663f758 100644 --- a/lib/signalman/engine.rb +++ b/lib/signalman/engine.rb @@ -7,7 +7,7 @@ class Engine < ::Rails::Engine end # helpers must be accessible anywhere for Turbo broadcasts - initializer 'signalman.helpers' do + initializer "signalman.helpers" do ActiveSupport.on_load :action_controller do helper Signalman::EventsHelper end diff --git a/signalman.gemspec b/signalman.gemspec index 7bf2909..6953642 100644 --- a/signalman.gemspec +++ b/signalman.gemspec @@ -1,14 +1,14 @@ require_relative "lib/signalman/version" Gem::Specification.new do |spec| - spec.name = "signalman" - spec.version = Signalman::VERSION - spec.authors = ["Chris Oliver"] - spec.email = ["excid3@gmail.com"] - spec.homepage = "https://github.com/excid3/signalman" - spec.summary = "Development tools for Ruby on Rails" + spec.name = "signalman" + spec.version = Signalman::VERSION + spec.authors = ["Chris Oliver"] + spec.email = ["excid3@gmail.com"] + spec.homepage = "https://github.com/excid3/signalman" + spec.summary = "Development tools for Ruby on Rails" spec.description = "Development tools for Ruby on Rails" - spec.license = "MIT" + spec.license = "MIT" spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/excid3/signalman" diff --git a/test/dummy/app/mailers/user_mailer.rb b/test/dummy/app/mailers/user_mailer.rb index 80d31e2..6e4ddae 100644 --- a/test/dummy/app/mailers/user_mailer.rb +++ b/test/dummy/app/mailers/user_mailer.rb @@ -1,5 +1,4 @@ class UserMailer < ApplicationMailer - # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb index 8e989b5..6ab1e39 100644 --- a/test/dummy/config/environments/production.rb +++ b/test/dummy/config/environments/production.rb @@ -13,7 +13,7 @@ config.eager_load = true # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false + config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] @@ -53,7 +53,7 @@ config.log_level = :info # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -83,9 +83,9 @@ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name") if ENV["RAILS_LOG_TO_STDOUT"].present? - logger = ActiveSupport::Logger.new(STDOUT) + logger = ActiveSupport::Logger.new($stdout) logger.formatter = config.log_formatter - config.logger = ActiveSupport::TaggedLogging.new(logger) + config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 6ea4d1e..9de8427 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -23,7 +23,7 @@ } # Show full error reports and disable caching. - config.consider_all_requests_local = true + config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 9798af0..e573b09 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -27,5 +27,4 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false end - end diff --git a/test/dummy/test/mailers/previews/user_mailer_preview.rb b/test/dummy/test/mailers/previews/user_mailer_preview.rb index 355431b..725ac3d 100644 --- a/test/dummy/test/mailers/previews/user_mailer_preview.rb +++ b/test/dummy/test/mailers/previews/user_mailer_preview.rb @@ -1,9 +1,7 @@ # Preview all emails at http://localhost:3000/rails/mailers/user_mailer class UserMailerPreview < ActionMailer::Preview - # Preview this email at http://localhost:3000/rails/mailers/user_mailer/notification def notification UserMailer.notification end - end diff --git a/test/dummy/test/mailers/user_mailer_test.rb b/test/dummy/test/mailers/user_mailer_test.rb index 713d1ff..17fd872 100644 --- a/test/dummy/test/mailers/user_mailer_test.rb +++ b/test/dummy/test/mailers/user_mailer_test.rb @@ -8,5 +8,4 @@ class UserMailerTest < ActionMailer::TestCase assert_equal ["from@example.com"], mail.from assert_match "Hi", mail.body.encoded end - end