-
-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
f6c6f45
commit 9bef3a6
Showing
4 changed files
with
69 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
19 changes: 19 additions & 0 deletions
19
lib/generators/suspenders/production/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,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 |
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,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 |