-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce
suspenders:development:environment
generator
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
1 parent
f6c6f45
commit 1711f5b
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/generators/suspenders/development/environment_generator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
65 changes: 65 additions & 0 deletions
65
test/generators/suspenders/development/environment_generator_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |