Skip to content

Commit

Permalink
Merge pull request #32 from jacob-carlborg-apoex/multiple-listeners-27
Browse files Browse the repository at this point in the history
Fix #27: Make sure only one listener is running
  • Loading branch information
jorgemanrubia authored Dec 20, 2024
2 parents ff6361c + 725ee06 commit 80b02d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hotwire/spark/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Engine < ::Rails::Engine
config.hotwire = ActiveSupport::OrderedOptions.new unless config.respond_to?(:hotwire)
config.hotwire.spark = ActiveSupport::OrderedOptions.new
config.hotwire.spark.merge! \
enabled: Rails.env.development?,
enabled: Rails.env.development? && !defined?(Rails::Server).nil?,
css_paths: File.directory?("app/assets/builds") ? %w[ app/assets/builds ] : %w[ app/assets/stylesheets ],
html_paths: %w[ app/controllers app/helpers app/models app/views ],
stimulus_paths: %w[ app/javascript/controllers ]
Expand Down
11 changes: 11 additions & 0 deletions test/enabled_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "test_helper"

class EnabledTest < ActiveSupport::TestCase
test "that Hotwire-Spark is only enabled when starting the Rails server" do
script = <<~RUBY.strip
Hotwire::Spark.enabled? ? exit(1) : exit(0)
RUBY

assert system({ "RAILS_ENV" => "development" }, "rails", "runner", script, chdir: Rails.application.root)
end
end

0 comments on commit 80b02d0

Please sign in to comment.