File tree 5 files changed +93
-0
lines changed
lib/generators/suspenders/production
fixtures/files/environments
generators/suspenders/production
5 files changed +93
-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:production:environment ` 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,20 @@ Creates CI files for GitHub Actions.
197
197
bin/rails g suspenders:ci
198
198
```
199
199
200
+ ### Environments
201
+
202
+ #### Production
203
+
204
+ Configures the production environment.
205
+
206
+ - Enables [ require_master_key] [ ]
207
+
208
+ [ require_master_key ] : https://guides.rubyonrails.org/configuring.html#config-require-master-key
209
+
210
+ ```
211
+ bin/rails g suspenders:production:environment
212
+ ```
213
+
200
214
## Contributing
201
215
202
216
See the [ CONTRIBUTING] document.
Original file line number Diff line number Diff line change
1
+ module Suspenders
2
+ module Generators
3
+ module Production
4
+ class EnvironmentGenerator < Rails ::Generators ::Base
5
+ desc <<~MARKDOWN
6
+ Configures the production environment.
7
+
8
+ - Enables [require_master_key][]
9
+
10
+ [require_master_key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key
11
+ MARKDOWN
12
+
13
+ def require_master_key
14
+ if production_config . match? ( /^\s *#\s *config\. require_master_key\s *=\s *true/ )
15
+ uncomment_lines "config/environments/production.rb" , /config\. require_master_key\s *=\s *true/
16
+ else
17
+ environment %(config.require_master_key = true) , env : "production"
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def production_config
24
+ File . read ( Rails . root . join ( "config/environments/production.rb" ) )
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
Original file line number Diff line number Diff line change
1
+ Rails . application . configure do
2
+ end
Original file line number Diff line number Diff line change
1
+ require "test_helper"
2
+ require "generators/suspenders/production/environment_generator"
3
+
4
+ module Suspenders
5
+ module Generators
6
+ module Production
7
+ class EnvironmentGeneratorTest < Rails ::Generators ::TestCase
8
+ include Suspenders ::TestHelpers
9
+
10
+ tests Suspenders ::Generators ::Production ::EnvironmentGenerator
11
+ destination Rails . root
12
+ setup :prepare_destination
13
+ teardown :restore_destination
14
+
15
+ test "requires master key" do
16
+ run_generator
17
+
18
+ assert_file app_root ( "config/environments/production.rb" ) do |file |
19
+ assert_match ( /^\s *config\. require_master_key\s *=\s *true/ , file )
20
+ end
21
+ end
22
+
23
+ test "requires master key (when config is not commented out)" do
24
+ content = file_fixture ( "environments/production.rb" ) . read
25
+ remove_file_if_exists "config/environments/production.rb"
26
+ touch "config/environments/production.rb" , content : content
27
+
28
+ run_generator
29
+
30
+ assert_file app_root ( "config/environments/production.rb" ) do |file |
31
+ assert_match ( /^\s *config\. require_master_key\s *=\s *true/ , file )
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def prepare_destination
38
+ backup_file "config/environments/production.rb"
39
+ end
40
+
41
+ def restore_destination
42
+ restore_file "config/environments/production.rb"
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
You can’t perform that action at this time.
0 commit comments