Skip to content

Commit

Permalink
Merge pull request #34980 from y-yagi/fixes_34979
Browse files Browse the repository at this point in the history
Don't add `RAILS_ENV` in generate action
  • Loading branch information
y-yagi committed Jan 30, 2019
2 parents 535a8b9 + 82e9866 commit 6729cef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions railties/lib/rails/generators/actions.rb
Expand Up @@ -222,6 +222,7 @@ def generate(what, *args)
log :generate, what

options = args.extract_options!
options[:without_rails_env] = true
argument = args.flat_map(&:to_s).join(" ")

execute_command :rails, "generate #{what} #{argument}", options
Expand Down Expand Up @@ -284,14 +285,15 @@ def log(*args) # :doc:
# based on the executor parameter provided.
def execute_command(executor, command, options = {}) # :doc:
log executor, command
env = options[:env] || ENV["RAILS_ENV"] || "development"
env = options[:env] || ENV["RAILS_ENV"] || "development"
rails_env = " RAILS_ENV=#{env}" unless options[:without_rails_env]
sudo = options[:sudo] && !Gem.win_platform? ? "sudo " : ""
config = { verbose: false }

config[:capture] = options[:capture] if options[:capture]
config[:abort_on_failure] = options[:abort_on_failure] if options[:abort_on_failure]

in_root { run("#{sudo}#{extify(executor)} #{command} RAILS_ENV=#{env}", config) }
in_root { run("#{sudo}#{extify(executor)} #{command}#{rails_env}", config) }
end

# Add an extension to the given name based on the platform.
Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/actions_test.rb
Expand Up @@ -320,6 +320,12 @@ def test_generate_aborts_when_subprocess_fails_if_requested
assert_no_file "app/models/my_model.rb"
end

def test_generate_should_run_command_without_env
assert_called_with(generator, :run, ["rails generate model MyModel name:string", verbose: false]) do
action :generate, "model", "MyModel", "name:string"
end
end

def test_rake_should_run_rake_command_with_default_env
assert_called_with(generator, :run, ["rake log:clear RAILS_ENV=development", verbose: false]) do
with_rails_env nil do
Expand Down

0 comments on commit 6729cef

Please sign in to comment.