File tree 4 files changed +124
-0
lines changed
lib/generators/suspenders/development
test/generators/suspenders/development
4 files changed +124
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Unreleased
18
18
* Introduce ` suspenders:prerequisites ` generator
19
19
* Introduce ` suspenders:ci ` generator
20
20
* Introduce ` suspenders:cleanup:organize_gemfile ` task
21
+ * Introduce ` suspenders:development ` generator
21
22
22
23
20230113.0 (January, 13, 2023)
23
24
Original file line number Diff line number Diff line change @@ -197,6 +197,26 @@ Creates CI files for GitHub Actions.
197
197
bin/rails g suspenders:ci
198
198
```
199
199
200
+ ### Environments
201
+
202
+ #### Development
203
+
204
+ Configures the development environment.
205
+
206
+ ```
207
+ bin/rails g suspenders:development:evironment
208
+ ```
209
+
210
+ - Enables [ raise_on_missing_translations] [ ]
211
+ - Enables [ annotate_rendered_view_with_filenames] [ ]
212
+ - Enables [ i18n_customize_full_message] [ ]
213
+ - Enables [ query_log_tags_enabled] [ ]
214
+
215
+ [ raise_on_missing_translations ] : https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
216
+ [ annotate_rendered_view_with_filenames ] : https://guides.rubyonrails.org/configuring.html#config-action-view-annotate-rendered-view-with-filenames
217
+ [ i18n_customize_full_message ] : https://guides.rubyonrails.org/configuring.html#config-active-model-i18n-customize-full-message
218
+ [ query_log_tags_enabled ] : https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled
219
+
200
220
## Contributing
201
221
202
222
See the [ CONTRIBUTING] document.
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ module Generators
3
+ module Development
4
+ class EnvironmentGenerator < Rails ::Generators ::Base
5
+ desc <<~MARKDOWN
6
+ Configures the development environment.
7
+
8
+ - Enables [raise_on_missing_translations][]
9
+ - Enables [annotate_rendered_view_with_filenames][]
10
+ - Enables [i18n_customize_full_message][]
11
+ - Enables [query_log_tags_enabled][]
12
+
13
+ [raise_on_missing_translations]: https://guides.rubyonrails.org/configuring.html#config-i18n-raise-on-missing-translations
14
+ [annotate_rendered_view_with_filenames]: https://guides.rubyonrails.org/configuring.html#config-action-view-annotate-rendered-view-with-filenames
15
+ [i18n_customize_full_message]: https://guides.rubyonrails.org/configuring.html#config-active-model-i18n-customize-full-message
16
+ [query_log_tags_enabled]: https://guides.rubyonrails.org/configuring.html#config-active-record-query-log-tags-enabled
17
+ MARKDOWN
18
+
19
+ def raise_on_missing_translations
20
+ uncomment_lines "config/environments/development.rb" , "config.i18n.raise_on_missing_translations = true"
21
+ end
22
+
23
+ def annotate_render_view_with_filename
24
+ uncomment_lines "config/environments/development.rb" ,
25
+ "config.action_view.annotate_rendered_view_with_filenames = true"
26
+ end
27
+
28
+ def enable_i18n_customize_full_message
29
+ environment %(config.active_model.i18n_customize_full_message = true) , env : "development"
30
+ end
31
+
32
+ def enable_query_log_tags_enabled
33
+ environment %(config.active_record.query_log_tags_enabled = true) , env : "development"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "generators/suspenders/development/environment_generator"
3
+
4
+ module Suspenders
5
+ module Generators
6
+ module Development
7
+ class EnvironmentGenerator ::DefaultTest < Rails ::Generators ::TestCase
8
+ include Suspenders ::TestHelpers
9
+
10
+ tests Suspenders ::Generators ::Development ::EnvironmentGenerator
11
+ destination Rails . root
12
+ setup :prepare_destination
13
+ teardown :restore_destination
14
+
15
+ test "raise on missing translations" do
16
+ run_generator
17
+
18
+ assert_file app_root ( "config/environments/development.rb" ) do |file |
19
+ assert_match (
20
+ /^ +config.i18n.raise_on_missing_translations = true$/ ,
21
+ file
22
+ )
23
+ end
24
+ end
25
+
26
+ test "annotate rendered view with file names" do
27
+ run_generator
28
+
29
+ assert_file app_root ( "config/environments/development.rb" ) do |file |
30
+ assert_match (
31
+ /^ +config.action_view.annotate_rendered_view_with_filenames = true$/ ,
32
+ file
33
+ )
34
+ end
35
+ end
36
+
37
+ test "enable active_model.i18n_customize_full_message" do
38
+ run_generator
39
+
40
+ assert_file app_root ( "config/environments/development.rb" ) do |file |
41
+ assert_match ( /^\s *config\. active_model\. i18n_customize_full_message\s *=\s *true/ , file )
42
+ end
43
+ end
44
+
45
+ test "enable active_record.query_log_tags_enabled" do
46
+ run_generator
47
+
48
+ assert_file app_root ( "config/environments/development.rb" ) do |file |
49
+ assert_match ( /^\s *config\. active_record\. query_log_tags_enabled\s *=\s *true/ , file )
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def prepare_destination
56
+ backup_file "config/environments/development.rb"
57
+ end
58
+
59
+ def restore_destination
60
+ restore_file "config/environments/development.rb"
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
You can’t perform that action at this time.
0 commit comments