Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/spring/application_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def start_child(preload = false)
"RACK_ENV" => app_env,
"SPRING_ORIGINAL_ENV" => JSON.dump(Spring::ORIGINAL_ENV),
"SPRING_PRELOAD" => preload ? "1" : "0",
"SPRING_SPAWN_ENV" => JSON.dump(spawn_env),
"SPRING_SPAWN_ENV" => JSON.dump(spawn_env.compact),
**spawn_env,
},
"ruby",
Expand Down
4 changes: 3 additions & 1 deletion lib/spring/client/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ def default_rails_env
end

def spawn_env
ENV.slice(*Spring.spawn_on_env)
Spring.spawn_on_env.to_h do |key|
[key, ENV[key]]
end
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions test/support/acceptance_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,18 @@ def exec_name
assert_success %(bin/rails runner 'p ENV.key?("FOO")'), stdout: "false"
end

test "spawn_on_env variables are cleared when unset" do
File.write(app.spring_client_config, "Spring.spawn_on_env << 'VAR_FROM_BOOT'")
File.write(app.application_config, "#{app.application_config.read}\nRails.configuration.x.var_from_boot = ENV['VAR_FROM_BOOT']")

app.env["VAR_FROM_BOOT"] = "before"
assert_success %(bin/rails runner 'p Rails.configuration.x.var_from_boot.inspect'), stdout: "before"

app.env.delete "VAR_FROM_BOOT"

assert_success %(bin/rails runner 'p Rails.configuration.x.var_from_boot.inspect'), stdout: "nil"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this line fails:

Expected /nil/ to match "\"\\\"before\\\"\"\n".

end

test "Kernel.raise remains private" do
expr = "p Kernel.private_instance_methods.include?(:raise)"
assert_success %(bin/rails runner '#{expr}'), stdout: "true"
Expand Down