Skip to content

Commit

Permalink
follow-up bkeepers#511
Browse files Browse the repository at this point in the history
  • Loading branch information
alpaca-tc committed Sep 18, 2024
1 parent 1e8dae2 commit cc01799
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/dotenv/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Watch all loaded env files with Spring
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
if defined?(Spring)
require "spring/watcher"
event = ActiveSupport::Notifications::Event.new(*args)
Spring.watch event.payload[:env].filename if Rails.application
end
Expand Down
13 changes: 9 additions & 4 deletions spec/dotenv/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
# Restore autoload paths to unfrozen state
ActiveSupport::Dependencies.autoload_paths = autoload_paths
ActiveSupport::Dependencies.autoload_once_paths = autoload_once_paths

# Clear spring to be able to require again
spring_path = Gem::Specification.find_by_name("spring").full_gem_path
$LOADED_FEATURES.delete_if { |f| f.start_with?(spring_path) }
end

before do
Expand Down Expand Up @@ -207,12 +211,13 @@
end

def stub_spring
spring = Struct.new("Spring", :watcher) do
def watch(path)
watcher.add path
spring = Module.new do
class << self
attr_accessor :watcher
end
end
spring.watcher = Set.new

stub_const "Spring", spring.new(Set.new)
stub_const "Spring", spring
end
end

0 comments on commit cc01799

Please sign in to comment.