Make application work without tmp directory

The tmp directory is added to version control in the newly created
application. This was added in Rails 5.0.0(f06ce4c12a).

However, applications created before that are not guaranteed to have the
tmp directory. If the tmp directory does not exist, writing to the key file
raise error.

This is a bit incompatible. So I fixed that create the directory before
writing a key.
This commit is contained in:
yuuji.yaginuma 2019-03-14 15:39:23 +09:00
parent 25620f91ca
commit 0187053109
2 changed files with 4 additions and 0 deletions

@ -587,6 +587,7 @@ def generate_development_secret
if !File.exist?(key_file)
random_key = SecureRandom.hex(64)
FileUtils.mkdir_p(key_file.dirname)
File.binwrite(key_file, random_key)
end

@ -601,6 +601,9 @@ def index
Rails.application.credentials.secret_key_base = nil
RUBY
# For test that works even if tmp dir does not exist.
Dir.chdir(app_path) { FileUtils.remove_dir("tmp") }
app "development"
assert_not_nil app.secrets.secret_key_base