Skip to content

Commit c22a177

Browse files
crackofduskstevepolitodesign
authored andcommitted
Introduce suspenders:production:environment generator
Creates generator to configuration the production environment. For now, this means [requiring a master key][master key]. Drops configuration for [asset_host][], since that should be an infrastructure decision. In an effort to distinguish between the development environment configuration in #1149, we use the `production` namespace. [master key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key [asset_host]: https://guides.rubyonrails.org/configuring.html#config-asset-host
1 parent f6c6f45 commit c22a177

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Unreleased
1818
* Introduce `suspenders:prerequisites` generator
1919
* Introduce `suspenders:ci` generator
2020
* Introduce `suspenders:cleanup:organize_gemfile` task
21+
* Introduce `suspenders:production:environment` generator
2122

2223
20230113.0 (January, 13, 2023)
2324

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ Creates CI files for GitHub Actions.
197197
bin/rails g suspenders:ci
198198
```
199199

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+
200214
## Contributing
201215

202216
See the [CONTRIBUTING] document.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
uncomment_lines "config/environments/production.rb", /config\.require_master_key\s*=\s*true/
15+
end
16+
end
17+
end
18+
end
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
private
24+
25+
def prepare_destination
26+
backup_file "config/environments/production.rb"
27+
end
28+
29+
def restore_destination
30+
restore_file "config/environments/production.rb"
31+
end
32+
end
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)