diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..2d3d5c4 --- /dev/null +++ b/.standard.yml @@ -0,0 +1,3 @@ +plugins: + - standard-performance + - standard-rails diff --git a/Gemfile b/Gemfile index bf8f0b6..fbe679b 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,8 @@ group :development, :test do gem "figaro" gem "rspec-rails" gem "standard" + gem "standard-performance" + gem "standard-rails" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 4863835..9c61091 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,9 +84,9 @@ GEM cssbundling-rails (1.3.3) railties (>= 6.0.0) date (3.3.4) - debug (1.8.0) - irb (>= 1.5.0) - reline (>= 0.3.1) + debug (1.9.1) + irb (~> 1.10) + reline (>= 0.3.8) diff-lcs (1.5.0) erubi (1.12.0) factory_bot (6.4.5) @@ -126,14 +126,14 @@ GEM honeybadger (5.4.1) i18n (1.14.1) concurrent-ruby (~> 1.0) - importmap-rails (1.2.3) + importmap-rails (2.0.1) actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) - io-console (0.6.0) - irb (1.9.0) + io-console (0.7.1) + irb (1.11.1) rdoc - reline (>= 0.3.8) + reline (>= 0.4.2) json (2.7.1) language_server-protocol (3.17.0.3) lint_roller (1.1.0) @@ -157,21 +157,21 @@ GEM minitest (5.20.0) msgpack (1.7.2) multipart-post (2.3.0) - net-imap (0.4.5) + net-imap (0.4.9.1) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.4.0) + net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) nokogiri (1.16.0) mini_portile2 (~> 2.8.2) racc (~> 1.4) parallel (1.24.0) - parser (3.2.2.4) + parser (3.3.0.2) ast (~> 2.4.1) racc particlerb (2.1.0) @@ -183,7 +183,7 @@ GEM activesupport (>= 7.0.0) rack railties (>= 7.0.0) - psych (5.1.1.1) + psych (5.1.2) stringio puma (6.4.2) nio4r (~> 2.0) @@ -221,10 +221,10 @@ GEM zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.1.0) - rdoc (6.6.0) + rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.3) - reline (0.4.0) + regexp_parser (2.9.0) + reline (0.4.2) io-console (~> 0.5) request_store (1.5.1) rack (>= 1.4) @@ -266,9 +266,14 @@ GEM unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.30.0) parser (>= 3.2.1.0) - rubocop-performance (1.20.1) + rubocop-performance (1.20.2) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.23.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) standard (1.33.0) @@ -283,7 +288,10 @@ GEM standard-performance (1.3.0) lint_roller (~> 1.1) rubocop-performance (~> 1.20.1) - stringio (3.0.9) + standard-rails (1.0.2) + lint_roller (~> 1.0) + rubocop-rails (~> 2.23.1) + stringio (3.1.0) tapout (0.4.5) ansi json @@ -315,6 +323,8 @@ DEPENDENCIES rspec-ontap rspec-rails standard + standard-performance + standard-rails websocket-driver! RUBY VERSION diff --git a/app/interactors/parse_circle.rb b/app/interactors/parse_circle.rb index 5f939b0..8794573 100644 --- a/app/interactors/parse_circle.rb +++ b/app/interactors/parse_circle.rb @@ -3,7 +3,7 @@ def self.call(payload) return unless payload["pull_requests"].blank? status = Status.find_or_initialize_by(service: "circle", username: payload["username"], project_name: payload["reponame"]) - status.payload = payload if ENV["DEBUG"] + status.payload = payload if Rails.configuration.x.debug set_colors(status, payload["status"]) status.save! end diff --git a/app/interactors/parse_github.rb b/app/interactors/parse_github.rb index 2a9b8c1..7032950 100644 --- a/app/interactors/parse_github.rb +++ b/app/interactors/parse_github.rb @@ -3,7 +3,7 @@ def self.call(payload) username, project_name = payload["repository"].split("/") workflow = payload["workflow"] status = Status.find_or_initialize_by(service: "github", username: username, project_name: project_name, workflow: workflow) - status.payload = payload if ENV["DEBUG"] + status.payload = payload if Rails.configuration.x.debug set_colors(status, payload["status"]) status.save! end diff --git a/app/interactors/parse_travis.rb b/app/interactors/parse_travis.rb index ca0b61d..ebc6558 100644 --- a/app/interactors/parse_travis.rb +++ b/app/interactors/parse_travis.rb @@ -4,7 +4,7 @@ def self.call(payload) return if json["type"] == "pull_request" status = Status.find_or_initialize_by(service: "travis", project_id: json["repository"]["id"].to_s) - status.payload = payload if ENV["DEBUG"] + status.payload = payload if Rails.configuration.x.debug status.username = json["repository"]["owner_name"] status.project_name = json["repository"]["name"] set_colors(status, json["status_message"]) diff --git a/app/interactors/trigger_webhook.rb b/app/interactors/trigger_webhook.rb index 6ac9894..6f43c9a 100644 --- a/app/interactors/trigger_webhook.rb +++ b/app/interactors/trigger_webhook.rb @@ -5,7 +5,7 @@ def self.call(device) { "Content-Type": "application/json", "x-ryg": device.ryg, - "x-device-url": Rails.application.routes.url_helpers.api_device_url(device, host: ENV["HOST"]) + "x-device-url": Rails.application.routes.url_helpers.api_device_url(device, host: Rails.configuration.x.host) }) end end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 65b6d8d..7a7b47d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,7 +9,7 @@ <%= csrf_meta_tags %> <%= action_cable_meta_tag %> <%= stylesheet_link_tag "application", :media => "all" %> - <%= javascript_importmap_tags shim: !Rails.env.test? %> + <%= javascript_importmap_tags %> > diff --git a/config/application.rb b/config/application.rb index 37b444c..ae8e52a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,5 +18,8 @@ class Application < Rails::Application # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") + + config.x.debug = ENV["DEBUG"].present? + config.x.host = ENV["HOST"] end end diff --git a/config/environments/development.rb b/config/environments/development.rb index df1dc87..8500f45 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -14,6 +14,9 @@ # Show full error reports. config.consider_all_requests_local = true + # Enable server timing + config.server_timing = true + # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join("tmp/caching-dev.txt").exist? diff --git a/config/environments/production.rb b/config/environments/production.rb index 37e5134..05943b1 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -93,24 +93,4 @@ config.action_cable.url = "wss://#{ENV["HOST"]}/cable" config.action_cable.allowed_request_origins = ["https://#{ENV["HOST"]}", "http://#{ENV["HOST"]}"] - # Inserts middleware to perform automatic connection switching. - # The `database_selector` hash is used to pass options to the DatabaseSelector - # middleware. The `delay` is used to determine how long to wait after a write - # to send a subsequent read to the primary. - # - # The `database_resolver` class is used by the middleware to determine which - # database is appropriate to use based on the time delay. - # - # The `database_resolver_context` class is used by the middleware to set - # timestamps for the last write to the primary. The resolver uses the context - # class timestamps to determine how long to wait before reading from the - # replica. - # - # By default Rails will store a last write timestamp in the session. The - # DatabaseSelector middleware is designed as such you can define your own - # strategy for connection switching and pass that into the middleware through - # these configuration options. - # config.active_record.database_selector = { delay: 2.seconds } - # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver - # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session end diff --git a/config/environments/test.rb b/config/environments/test.rb index 3e0973d..9de8427 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -8,13 +8,13 @@ Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. - # Turn false under Spring and add config.action_view.cache_template_loading = true + # Turn false under Spring and add config.action_view.cache_template_loading = true. config.cache_classes = true - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false + # Eager loading loads your whole application. When running a single test locally, + # this probably isn't necessary. It's a good idea to do in a continuous integration + # system, or in some way before deploying your code. + config.eager_load = ENV["CI"].present? # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true diff --git a/config/importmap.rb b/config/importmap.rb index c923f89..bbf1019 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,5 +1,5 @@ # Pin npm packages by running ./bin/importmap -pin "application", preload: true +pin "application" pin "@rails/actioncable", to: "actioncable.esm.js" pin_all_from "app/javascript/channels", under: "channels" diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb index d988237..54f47cf 100644 --- a/config/initializers/content_security_policy.rb +++ b/config/initializers/content_security_policy.rb @@ -1,27 +1,25 @@ # Be sure to restart your server when you modify this file. -# Define an application-wide content security policy -# For further information see the following documentation -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header -# Rails.application.config.content_security_policy do |policy| -# policy.default_src :self, :https -# policy.font_src :self, :https, :data -# policy.img_src :self, :https, :data -# policy.object_src :none -# policy.script_src :self, :https -# policy.style_src :self, :https -# # Specify URI for violation reports -# # policy.report_uri "/csp-violation-report-endpoint" +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap and inline scripts +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true # end - -# If you are using UJS then enable automatic nonce generation -# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) } - -# Set the nonce only to specific directives -# Rails.application.config.content_security_policy_nonce_directives = %w(script-src) - -# Report CSP violations to a specified URI -# For further information see the following documentation: -# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only -# Rails.application.config.content_security_policy_report_only = true diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb index 4a994e1..adc6568 100644 --- a/config/initializers/filter_parameter_logging.rb +++ b/config/initializers/filter_parameter_logging.rb @@ -1,4 +1,8 @@ # Be sure to restart your server when you modify this file. -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] +# Configure parameters to be filtered from the log file. Use this to limit dissemination of +# sensitive information. See the ActiveSupport::ParameterFilter documentation for supported +# notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 5516421..fa9b938 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -4,9 +4,9 @@ # are locale specific, and you may define rules for as many different # locales as you wish. All of these examples are active by default: # ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" # inflect.uncountable %w( fish sheep ) # end diff --git a/db/migrate/20121123195427_split_colors_on_statuses.rb b/db/migrate/20121123195427_split_colors_on_statuses.rb index 7b3e56c..68bbabd 100644 --- a/db/migrate/20121123195427_split_colors_on_statuses.rb +++ b/db/migrate/20121123195427_split_colors_on_statuses.rb @@ -1,14 +1,16 @@ class SplitColorsOnStatuses < ActiveRecord::Migration[4.2] def change - remove_index :statuses, :color - remove_index :statuses, [:project_id, :color] - remove_index :statuses, [:project_id, :color, :created_at] + change_table :statuses, bulk: true do |t| + t.remove_index :color + t.remove_index [:project_id, :color] + t.remove_index [:project_id, :color, :created_at] - add_column :statuses, :red, :boolean - add_column :statuses, :yellow, :boolean - remove_column :statuses, :color + t.boolean :red + t.boolean :yellow + t.remove :color, type: :string - add_index :statuses, :red - add_index :statuses, :yellow + t.index :red + t.index :yellow + end end end diff --git a/db/migrate/20161012193415_add_service_to_status.rb b/db/migrate/20161012193415_add_service_to_status.rb index 281ced9..865c12e 100644 --- a/db/migrate/20161012193415_add_service_to_status.rb +++ b/db/migrate/20161012193415_add_service_to_status.rb @@ -1,5 +1,5 @@ class AddServiceToStatus < ActiveRecord::Migration[5.0] - class Status < ActiveRecord::Base + class Status < ApplicationRecord end def up diff --git a/db/migrate/20230305131208_add_status_to_devices.rb b/db/migrate/20230305131208_add_status_to_devices.rb index a715f3e..a4fd393 100644 --- a/db/migrate/20230305131208_add_status_to_devices.rb +++ b/db/migrate/20230305131208_add_status_to_devices.rb @@ -1,6 +1,8 @@ class AddStatusToDevices < ActiveRecord::Migration[7.0] def change - add_column :devices, :status, :string - add_column :devices, :status_changed_at, :datetime + change_table :devices, bulk: true do |t| + t.string :status + t.datetime :status_changed_at + end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index e8ff0fa..8930327 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -26,7 +26,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = Rails.root.join("spec/fixtures") # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false diff --git a/spec/support/json_helpers.rb b/spec/support/json_helpers.rb index 28fa890..0c37f2d 100644 --- a/spec/support/json_helpers.rb +++ b/spec/support/json_helpers.rb @@ -2,7 +2,7 @@ module JSONHelpers ENV = {"CONTENT_TYPE" => "application/json"}.freeze def json_fixture(filename) - File.read(Rails.root.join("spec", "fixtures", filename)) + Rails.root.join("spec", "fixtures", filename).read end end