Skip to content

Commit

Permalink
Override Rack::Handler default server
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Amoêdo <[email protected]>
Signed-off-by: Marcelo Oliveira <[email protected]>
  • Loading branch information
LucasAmoedo committed Apr 18, 2017
1 parent 6c33481 commit efe688b
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ gem 'http_accept_language'
# Routes for JS files
gem 'js-routes', '~> 1.1.0'

# Puma server
# Use Puma webserver for the application.
gem 'puma'

group :test do

# Use Thin webserver for konacha tests.
gem 'thin'

# Easier test writing
gem "shoulda-matchers", '~> 2.8.0'

Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ GEM
mime-types (>= 1.16, < 3)
nokogiri (~> 1.5)
rails (>= 3, < 5)
daemons (1.2.3)
dalli (2.7.4)
database_cleaner (1.5.0)
debug_inspector (0.0.2)
Expand All @@ -108,6 +109,7 @@ GEM
domain_name (0.5.24)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0)
eventmachine (1.0.8)
exception_notification (4.1.1)
actionmailer (>= 3.0.4)
activesupport (>= 3.0.4)
Expand Down Expand Up @@ -301,6 +303,10 @@ GEM
therubyracer (0.12.2)
libv8 (~> 3.16.14.0)
ref
thin (1.6.4)
daemons (~> 1.0, >= 1.0.9)
eventmachine (~> 1.0, >= 1.0.4)
rack (~> 1.0)
thor (0.19.1)
thread_safe (0.3.5)
tilt (2.0.1)
Expand Down Expand Up @@ -380,6 +386,7 @@ DEPENDENCIES
sprockets
sqlite3
therubyracer
thin
turbolinks
uglifier (>= 1.3.0)
web-console (~> 2.0.0)
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ class Application < Rails::Application

# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true

require "#{Rails.root}/lib/core_extensions/rack/handler"

end
end
22 changes: 22 additions & 0 deletions config/initializers/konacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,26 @@
config.stylesheets = %w(application)
config.driver = :poltergeist
end

# Use Thin to run Konacha tests. This is needed because the tests hang frequently in Travis using the default (WEBRick)
# We can't just do 'Capybara.server' in the configure block because it will also apply to anything else run by
# Capybara. So instead, override the Konacha.run method to change the server, and restore it after completion.
module Konacha
class << self
old_run = instance_method(:run)

define_method(:run) do
prev_server = Capybara.server
begin
Capybara.server do |app, port|
require 'rack/handler/thin'
Rack::Handler::Thin.run(app, :Port => port)
end
old_run.bind(self).call
ensure
Capybara.server(&prev_server)
end
end
end
end
end
Empty file added config/initializers/rack.rb
Empty file.
15 changes: 15 additions & 0 deletions lib/core_extensions/rack/handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Monkey Patch for Rack to choose Puma as the default webserver.
# Without this, Thin takes precedence over Puma.
# Removing Thin would make this unnecessary. However, Thin is needed for Konacha.

module Rack
require 'rack/handler/puma'

module Handler

def self.default argument
return Rack::Handler::Puma
end

end
end

0 comments on commit efe688b

Please sign in to comment.