diff --git a/Gemfile b/Gemfile index 3a81224e..a4f15bf9 100644 --- a/Gemfile +++ b/Gemfile @@ -56,6 +56,8 @@ end group :development do gem "hotwire-spark" + gem "bullet" + gem "letter_opener" # Use console on exceptions pages [https://github.com/rails/web-console] gem "web-console" end diff --git a/Gemfile.lock b/Gemfile.lock index 22660e83..7b421232 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,6 +88,9 @@ GEM brakeman (7.0.0) racc builder (3.3.0) + bullet (8.0.0) + activesupport (>= 3.0.0) + uniform_notifier (~> 1.11) capybara (3.40.0) addressable matrix @@ -97,6 +100,8 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + childprocess (5.1.0) + logger (~> 1.5) concurrent-ruby (1.3.5) connection_pool (2.5.0) crass (1.0.6) @@ -160,6 +165,12 @@ GEM thor (~> 1.3) zeitwerk (>= 2.6.18, < 3.0) language_server-protocol (3.17.0.4) + launchy (3.1.0) + addressable (~> 2.8) + childprocess (~> 5.0) + logger (~> 1.6) + letter_opener (1.10.0) + launchy (>= 2.2, < 4) listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -373,6 +384,7 @@ GEM unicode-display_width (3.1.4) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) + uniform_notifier (1.16.0) uri (1.0.2) useragent (0.16.11) web-console (4.2.1) @@ -406,6 +418,7 @@ DEPENDENCIES bcrypt (~> 3.1.7) bootsnap brakeman + bullet capybara debug factory_bot_rails @@ -413,6 +426,7 @@ DEPENDENCIES importmap-rails jbuilder kamal + letter_opener pg (~> 1.1) propshaft puma (>= 5.0) diff --git a/README.md b/README.md index 791eb588..806e3c04 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,10 @@ SkillRX is one of many projects initiated and run by Ruby for Good. You can find # Welcome Contributors! Thank you for checking out our work. We are in the process of setting up the repository, roadmap, values, and contribution guidelines for the project. We will be adding issues and putting out a call for contributions soon. +# Setup + +Clone this repo and run `bin/setup`. Run `bin/dev` or `bin/server` (if you like Overmind) to start working with app. + # Testing This project uses: @@ -18,7 +22,4 @@ This project uses: * `shoulda-matchers` for expectations * `factory_bot` for making records -To run tests execute -``` -bin/rspec -``` +To run tests simply use `bin/rspec`. You can also you `bin/quality` to check for code style issues. diff --git a/bin/quality b/bin/quality new file mode 100755 index 00000000..1f62ea1d --- /dev/null +++ b/bin/quality @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby + +require 'pathname' +require 'fileutils' +include FileUtils + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +# rubocop +chdir APP_ROOT do + system! 'bin/rubocop --config .rubocop.yml' +end + +# brakeman +chdir APP_ROOT do + system! 'bin/brakeman --no-pager --no-progress' +end + +# js +chdir APP_ROOT do + system! 'bin/importmap audit' +end diff --git a/config/environments/development.rb b/config/environments/development.rb index 4cc21c4e..49cef754 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,6 +1,17 @@ require "active_support/core_ext/integer/time" Rails.application.configure do + if defined?(Bullet) + config.after_initialize do + Bullet.enable = true + Bullet.alert = true + Bullet.bullet_logger = true + Bullet.console = true + Bullet.rails_logger = true + Bullet.add_footer = true + end + end + # Settings specified here will take precedence over those in config/application.rb. # Make code changes take effect immediately without server restart. @@ -31,6 +42,9 @@ # Store uploaded files on the local file system (see config/storage.yml for options). config.active_storage.service = :local + config.action_mailer.delivery_method = :letter_opener + config.action_mailer.perform_deliveries = true + # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = false diff --git a/config/environments/test.rb b/config/environments/test.rb index c2095b11..9d320a93 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -4,6 +4,14 @@ # and recreated between test runs. Don't rely on the data there! Rails.application.configure do + if defined?(Bullet) + config.after_initialize do + Bullet.enable = true + Bullet.bullet_logger = true + Bullet.raise = true # raise an error if n+1 query occurs + end + end + # Settings specified here will take precedence over those in config/application.rb. # While tests run files are not watched, reloading is not necessary. diff --git a/config/initializers/letter_opener.rb b/config/initializers/letter_opener.rb new file mode 100644 index 00000000..00949130 --- /dev/null +++ b/config/initializers/letter_opener.rb @@ -0,0 +1,17 @@ +if defined?(LetterOpener) + LetterOpener.configure do |config| + # To overrider the location for message storage. + # Default value is `tmp/letter_opener` + config.location = Rails.root.join("tmp", "my_mails") + + # To render only the message body, without any metadata or extra containers or styling. + # Default value is `:default` that renders styled message with showing useful metadata. + config.message_template = :light + + # To change default file URI scheme you can provide `file_uri_scheme` config. + # It might be useful when you use WSL (Windows Subsystem for Linux) and default + # scheme doesn't work for you. + # Default value is blank + config.file_uri_scheme = "file://///wsl$/Ubuntu-18.04" + end +end diff --git a/spec/requests/regions_spec.rb b/spec/requests/regions_spec.rb index 4ebdd11b..06c66c52 100644 --- a/spec/requests/regions_spec.rb +++ b/spec/requests/regions_spec.rb @@ -1,4 +1,4 @@ -require 'rails_helper' +require "rails_helper" # This spec was generated by rspec-rails when you ran the scaffold generator. # It demonstrates how one might use RSpec to test the controller code that @@ -15,8 +15,6 @@ RSpec.describe "/regions", type: :request do let(:user) { create(:user) } - include AuthHelper - before do sign_in(user) end diff --git a/spec/support/authentication_helper.rb b/spec/support/authentication_helper.rb deleted file mode 100644 index 3e77d93d..00000000 --- a/spec/support/authentication_helper.rb +++ /dev/null @@ -1,5 +0,0 @@ -module AuthHelper - def sign_in(user) - post session_path, params: { email: user.email, password: user.password } - end -end diff --git a/spec/support/authentication_helpers.rb b/spec/support/authentication_helpers.rb new file mode 100644 index 00000000..b25dbe5f --- /dev/null +++ b/spec/support/authentication_helpers.rb @@ -0,0 +1,9 @@ +module AuthenticationHelpers + def sign_in(user) + post session_url, params: { email: user.email, password: user.password } + end +end + +RSpec.configure do |config| + config.include AuthenticationHelpers, type: :request +end