Skip to content

Commit

Permalink
ENV deletes keys on []= with non-string values.
Browse files Browse the repository at this point in the history
ENV is like a hash but it's not a hash.
`ENV['x'] = nil` will remove the 'x' key.

It's magic: ✨

```ruby
ENV["x"] = "true"
=> "true"

ENV.keys.grep(/x/)
=> ["x"]

ENV["x"] =  nil
=> nil

ENV.keys.grep(/x/)
=> []
```

Cleans up the change in #5266
  • Loading branch information
jrafanie committed Nov 6, 2015
1 parent d6c1058 commit d098bc0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec/lib/extensions/database_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
ENV['DATABASE_URL'] = 'postgres://'
example.run
ensure
ENV['DATABASE_URL'] = old_env if old_env
# ENV['x'] = nil deletes the key because ENV accepts only string values
ENV['DATABASE_URL'] = old_env
end
end

Expand All @@ -46,7 +47,8 @@
old = ENV.delete('DATABASE_URL')
expect { @app.config.database_configuration }.to raise_error(/Could not load database configuration/)
ensure
ENV['DATABASE_URL'] = old if old
# ENV['x'] = nil deletes the key because ENV accepts only string values
ENV['DATABASE_URL'] = old
end
end
end
Expand Down

0 comments on commit d098bc0

Please sign in to comment.