module Decidim::CapybaraTestHelpers

def protocol

def protocol
  return "https" if ENV["TEST_SSL"]
  "http"
end

def switch_to_default_host

def switch_to_default_host
  Capybara.app_host = nil
end

def switch_to_host(host = "lvh.me")

def switch_to_host(host = "lvh.me")
  raise "Cannot switch to a custom host unless it really exists. Use `whatever.lvh.me` as a workaround." unless /lvh\.me$/.match?(host)
  app_host = (host ? "#{protocol}://#{host}" : nil)
  Capybara.app_host = app_host
  Rails.application.config.action_controller.asset_host = host
end

def switch_to_secure_context_host

def switch_to_secure_context_host
  Capybara.app_host = "#{protocol}://localhost"
end