Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions FEATURES.md
Comment thread
jaredlt marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Uses [Strong Migrations][] to catch unsafe migrations in development.

[Strong Migrations]: https://github.com/ankane/strong_migrations

### Prosopite

Uses [Prosopite][] to detect N+1 queries in development and test.

[Prosopite]: https://github.com/charkost/prosopite

### Seed Data

Follows [our guidance][seed-data-guide] for managing seed data. Use
Expand Down Expand Up @@ -57,12 +63,8 @@ The following environment variables are available in `production`:

### All Environments

- Enables [strict_loading_by_default][].
- Sets [strict_loading_mode][] to `:n_plus_one`.
- Enables [require_master_key][].

[strict_loading_by_default]: https://guides.rubyonrails.org/configuring.html#config-active-record-strict-loading-by-default
[strict_loading_mode]: https://guides.rubyonrails.org/configuring.html#config-active-record-strict-loading-mode
[require_master_key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key

### Test
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased

* Added: AI harness. Downloads `.claude/CLAUDE.md` and `.claude/rules/` from [thoughtbot/guides](https://github.com/thoughtbot/guides/tree/main/rails/ai-rules).
* Added: [letter_opener](https://github.com/ryanb/letter_opener) for email previews in development
* Added: [prosopite](https://github.com/charkost/prosopite) for N+1 query detection in development and test
* Updated: Run the development seeder from `bin/setup`.
* Updated: Consolidate duplicate gem groups in the generated Gemfile.

Expand Down
7 changes: 7 additions & 0 deletions lib/templates/config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

Sidekiq.configure_server do |config|
config.redis = SIDEKIQ_REDIS_CONFIGURATION

if Rails.env.local?
config.server_middleware do |chain|
require "prosopite/middleware/sidekiq"
chain.add(Prosopite::Middleware::Sidekiq)
end
end
end

Sidekiq.configure_client do |config|
Expand Down
37 changes: 31 additions & 6 deletions lib/templates/web.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def install_gems

gem_group :development, :test do
gem "factory_bot_rails"
gem "pg_query"
gem "prosopite"
gem "rspec-rails", "~> 8.0.0"
end
end
Expand All @@ -54,6 +56,7 @@ def install_gems
configure_sidekiq
configure_action_cable
configure_strong_migrations
configure_prosopite
configure_mailer_interceptor
configure_inline_svg
configure_development_seeder
Expand Down Expand Up @@ -219,6 +222,28 @@ def configure_strong_migrations
rails_command "generate strong_migrations:install"
end

def configure_prosopite
initializer "prosopite.rb", <<~RUBY
unless Rails.env.production?
require "prosopite/middleware/rack"
Rails.configuration.middleware.use(Prosopite::Middleware::Rack)
end
RUBY

environment <<~RUBY, env: "development"
config.after_initialize do
Prosopite.rails_logger = true
end
RUBY

environment <<~RUBY, env: "test"
config.after_initialize do
Prosopite.rails_logger = true
Prosopite.raise = true
end
RUBY
end

def configure_mailer_interceptor
lib "email_interceptor.rb", <<~RUBY
class EmailInterceptor
Expand Down Expand Up @@ -280,8 +305,6 @@ def setup_production_environment
end

def setup_application
environment "config.active_record.strict_loading_by_default = true"
environment "config.active_record.strict_loading_mode = :n_plus_one_only"
environment "config.require_master_key = true"
end

Expand Down Expand Up @@ -358,6 +381,12 @@ def update_readme

[Strong Migrations]: https://github.com/ankane/strong_migrations

### N+1 Query Detection

Uses [Prosopite][] to detect N+1 queries in development and test.

[Prosopite]: https://github.com/charkost/prosopite

### Seed Data

Follows [our guidance][seed-data-guide] for managing seed data.
Expand Down Expand Up @@ -407,12 +436,8 @@ def update_readme

### All Environments

- Enables [strict_loading_by_default][].
- Sets [strict_loading_mode][] to `:n_plus_one`.
- Enables [require_master_key][].

[strict_loading_by_default]: https://guides.rubyonrails.org/configuring.html#config-active-record-strict-loading-by-default
[strict_loading_mode]: https://guides.rubyonrails.org/configuring.html#config-active-record-strict-loading-mode
[require_master_key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key

### Test
Expand Down
Loading