Skip to content

Commit

Permalink
Introduce suspenders:production:environment generator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
crackofdusk authored and stevepolitodesign committed Apr 5, 2024
1 parent f6c6f45 commit 9bef3a6
Show file tree
Hide file tree
Showing 4 changed files with 69 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:production:environment` generator

20230113.0 (January, 13, 2023)

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

### Environments

#### Production

Configures the production environment.

- Enables [require_master_key][]

[require_master_key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key

```
bin/rails g suspenders:production:environment
```

## Contributing

See the [CONTRIBUTING] document.
Expand Down
19 changes: 19 additions & 0 deletions lib/generators/suspenders/production/environment_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Suspenders
module Generators
module Production
class EnvironmentGenerator < Rails::Generators::Base
desc <<~MARKDOWN
Configures the production environment.
- Enables [require_master_key][]
[require_master_key]: https://guides.rubyonrails.org/configuring.html#config-require-master-key
MARKDOWN

def require_master_key
uncomment_lines "config/environments/production.rb", /config\.require_master_key\s*=\s*true/
end
end
end
end
end
35 changes: 35 additions & 0 deletions test/generators/suspenders/production/environment_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require "test_helper"
require "generators/suspenders/production/environment_generator"

module Suspenders
module Generators
module Production
class EnvironmentGeneratorTest < Rails::Generators::TestCase
include Suspenders::TestHelpers

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

test "requires master key" do
run_generator

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

private

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

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

0 comments on commit 9bef3a6

Please sign in to comment.