Skip to content

Commit

Permalink
Introduce suspenders:development:environment generator
Browse files Browse the repository at this point in the history
Creates generator to configure the development environment. Keeps parity
with Rails as much as possible in an effort to avoid drift with Rails
standards.

It's possible a future release of Rails will alleviate us from having to
do the following:

- enable `active_model.i18n_customize_full_message` which is being
  addressed in [#50406][]
- enable `active_record.query_log_tags_enabled` which is being addressed
  in [#51342][]

[#50406]: rails/rails#50406
[#51342]: rails/rails#51342
  • Loading branch information
crackofdusk authored and stevepolitodesign committed Apr 5, 2024
1 parent f6c6f45 commit 1711f5b
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Unreleased
* Introduce `suspenders:prerequisites` generator
* Introduce `suspenders:ci` generator
* Introduce `suspenders:cleanup:organize_gemfile` task
* Introduce `suspenders:development` generator

20230113.0 (January, 13, 2023)

Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ Creates CI files for GitHub Actions.
bin/rails g suspenders:ci
```

### Environments

#### Development

Configures the development environment.

```
bin/rails g suspenders:development:evironment
```

- Enables [raise_on_missing_translations][]
- Enables [annotate_rendered_view_with_filenames][]
- Enables [i18n_customize_full_message][]
- Enables [query_log_tags_enabled][]

[raise_on_missing_translations]: https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
[annotate_rendered_view_with_filenames]: https://guides.rubyonrails.org/configuring.html#config-action-view-annotate-rendered-view-with-filenames
[i18n_customize_full_message]: https://guides.rubyonrails.org/configuring.html#config-active-model-i18n-customize-full-message
[query_log_tags_enabled]: https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled

## Contributing

See the [CONTRIBUTING] document.
Expand Down
38 changes: 38 additions & 0 deletions lib/generators/suspenders/development/environment_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Suspenders
module Generators
module Development
class EnvironmentGenerator < Rails::Generators::Base
desc <<~MARKDOWN
Configures the development environment.
- Enables [raise_on_missing_translations][]
- Enables [annotate_rendered_view_with_filenames][]
- Enables [i18n_customize_full_message][]
- Enables [query_log_tags_enabled][]
[raise_on_missing_translations]: https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
[annotate_rendered_view_with_filenames]: https://guides.rubyonrails.org/configuring.html#config-action-view-annotate-rendered-view-with-filenames
[i18n_customize_full_message]: https://guides.rubyonrails.org/configuring.html#config-active-model-i18n-customize-full-message
[query_log_tags_enabled]: https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled
MARKDOWN

def raise_on_missing_translations
uncomment_lines "config/environments/development.rb", "config.i18n.raise_on_missing_translations = true"
end

def annotate_render_view_with_filename
uncomment_lines "config/environments/development.rb",
"config.action_view.annotate_rendered_view_with_filenames = true"
end

def enable_i18n_customize_full_message
environment %(config.active_model.i18n_customize_full_message = true), env: "development"
end

def enable_query_log_tags_enabled
environment %(config.active_record.query_log_tags_enabled = true), env: "development"
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
require "test_helper"
require "generators/suspenders/development/environment_generator"

module Suspenders
module Generators
module Development
class EnvironmentGenerator::DefaultTest < Rails::Generators::TestCase
include Suspenders::TestHelpers

tests Suspenders::Generators::Development::EnvironmentGenerator
destination Rails.root
setup :prepare_destination
teardown :restore_destination

test "raise on missing translations" do
run_generator

assert_file app_root("config/environments/development.rb") do |file|
assert_match(
/^ +config.i18n.raise_on_missing_translations = true$/,
file
)
end
end

test "annotate rendered view with file names" do
run_generator

assert_file app_root("config/environments/development.rb") do |file|
assert_match(
/^ +config.action_view.annotate_rendered_view_with_filenames = true$/,
file
)
end
end

test "enable active_model.i18n_customize_full_message" do
run_generator

assert_file app_root("config/environments/development.rb") do |file|
assert_match(/^\s*config\.active_model\.i18n_customize_full_message\s*=\s*true/, file)
end
end

test "enable active_record.query_log_tags_enabled" do
run_generator

assert_file app_root("config/environments/development.rb") do |file|
assert_match(/^\s*config\.active_record\.query_log_tags_enabled\s*=\s*true/, file)
end
end

private

def prepare_destination
backup_file "config/environments/development.rb"
end

def restore_destination
restore_file "config/environments/development.rb"
end
end
end
end
end

0 comments on commit 1711f5b

Please sign in to comment.