1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #43072 from jmromer/cli-template-from-env-var-path

Enable passing env var paths to cli -m option
This commit is contained in:
Rafael França 2021-09-20 16:21:40 -04:00 committed by GitHub
commit 03add891e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View file

@ -148,7 +148,7 @@ module Rails
when /^https?:\/\// when /^https?:\/\//
options[:template] options[:template]
when String when String
File.expand_path(options[:template], Dir.pwd) File.expand_path(`echo #{options[:template]}`.strip)
else else
options[:template] options[:template]
end end

View file

@ -580,6 +580,25 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"])) assert_match(/It works from file!/, run_generator([destination_root, "-m", "lib/template.rb"]))
end end
def test_template_from_url
url = "https://raw.githubusercontent.com/rails/rails/f95c0b7e96/railties/test/fixtures/lib/template.rb"
FileUtils.cd(Rails.root)
assert_match(/It works from file!/, run_generator([destination_root, "-m", url]))
end
def test_template_from_abs_path
absolute_path = File.expand_path(Rails.root, "fixtures")
FileUtils.cd(Rails.root)
assert_match(/It works from file!/, run_generator([destination_root, "-m", "#{absolute_path}/lib/template.rb"]))
end
def test_template_from_env_var_path
ENV["FIXTURES_HOME"] = File.expand_path(Rails.root, "fixtures")
FileUtils.cd(Rails.root)
assert_match(/It works from file!/, run_generator([destination_root, "-m", "$FIXTURES_HOME/lib/template.rb"]))
ENV.delete("FIXTURES_HOME")
end
def test_usage_read_from_file def test_usage_read_from_file
assert_called(File, :read, returns: "USAGE FROM FILE") do assert_called(File, :read, returns: "USAGE FROM FILE") do
assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc assert_equal "USAGE FROM FILE", Rails::Generators::AppGenerator.desc