1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #23505 from kaspth/inject-rails-config-through-railtie

Inject Rails related configuration through Railtie
This commit is contained in:
Kasper Timm Hansen 2016-02-14 18:08:46 +01:00
commit 3c96a6eaa4
6 changed files with 16 additions and 54 deletions

View file

@ -31,6 +31,12 @@ module ActionCable
self.cable = Rails.application.config_for(config_path).with_indifferent_access
end
if 'ApplicationCable::Connection'.safe_constantize
self.connection_class = ApplicationCable::Connection
end
self.channel_paths = Rails.application.paths['app/channels'].existent
options.each { |k,v| send("#{k}=", v) }
end
end

View file

@ -5,27 +5,20 @@ module ActionCable
class Configuration
attr_accessor :logger, :log_tags
attr_accessor :connection_class, :worker_pool_size
attr_accessor :channel_load_paths
attr_accessor :disable_request_forgery_protection, :allowed_request_origins
attr_accessor :cable, :url
attr_accessor :channel_paths # :nodoc:
def initialize
@log_tags = []
@connection_class = ApplicationCable::Connection
@worker_pool_size = 100
@channel_load_paths = [Rails.root.join('app/channels')]
@connection_class = ActionCable::Connection::Base
@worker_pool_size = 100
@disable_request_forgery_protection = false
end
def channel_paths
@channel_paths ||= channel_load_paths.flat_map do |path|
Dir["#{path}/**/*_channel.rb"]
end
end
def channel_class_names
@channel_class_names ||= channel_paths.collect do |channel_path|
Pathname.new(channel_path).basename.to_s.split('.').first.camelize

View file

@ -12,24 +12,15 @@ class ClientTest < ActionCable::TestCase
WAIT_WHEN_NOT_EXPECTING_EVENT = 0.2
def setup
# TODO: ActionCable requires a *lot* of setup at the moment...
::Object.const_set(:ApplicationCable, Module.new)
::ApplicationCable.const_set(:Connection, Class.new(ActionCable::Connection::Base))
::Object.const_set(:Rails, Module.new)
::Rails.singleton_class.send(:define_method, :root) { Pathname.new(__dir__) }
ActionCable.instance_variable_set(:@server, nil)
server = ActionCable.server
server.config = ActionCable::Server::Configuration.new
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.logger = ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
server.config.logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.cable = { adapter: 'async' }.with_indifferent_access
# and now the "real" setup for our test:
server.config.disable_request_forgery_protection = true
server.config.channel_load_paths = [File.expand_path('client', __dir__)]
server.config.channel_paths = [ File.expand_path('client/echo_channel.rb', __dir__) ]
Thread.new { EventMachine.run } unless EventMachine.reactor_running?
Thread.pass until EventMachine.reactor_running?
@ -40,15 +31,6 @@ class ClientTest < ActionCable::TestCase
def teardown
$VERBOSE = @previous_verbose
begin
::Object.send(:remove_const, :ApplicationCable)
rescue NameError
end
begin
::Object.send(:remove_const, :Rails)
rescue NameError
end
end
def with_puma_server(rack_app = ActionCable.server, port = 3099)

View file

@ -9,20 +9,7 @@ module CommonSubscriptionAdapterTest
WAIT_WHEN_NOT_EXPECTING_EVENT = 0.2
def setup
# TODO: ActionCable requires a *lot* of setup at the moment...
::Object.const_set(:ApplicationCable, Module.new)
::ApplicationCable.const_set(:Connection, Class.new(ActionCable::Connection::Base))
::Object.const_set(:Rails, Module.new)
::Rails.singleton_class.send(:define_method, :root) { Pathname.new(__dir__) }
server = ActionCable::Server::Base.new
server.config = ActionCable::Server::Configuration.new
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
server.config.logger = ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
# and now the "real" setup for our test:
server.config.cable = cable_config.with_indifferent_access
adapter_klass = server.config.pubsub_adapter
@ -34,15 +21,6 @@ module CommonSubscriptionAdapterTest
def teardown
@tx_adapter.shutdown if @tx_adapter && @tx_adapter != @rx_adapter
@rx_adapter.shutdown if @rx_adapter
begin
::Object.send(:remove_const, :ApplicationCable)
rescue NameError
end
begin
::Object.send(:remove_const, :Rails)
rescue NameError
end
end

View file

@ -17,7 +17,9 @@ class WorkerTest < ActiveSupport::TestCase
end
def logger
ActionCable.server.logger
# Impersonating a connection requires a TaggedLoggerProxy'ied logger.
inner_logger = Logger.new(StringIO.new).tap { |l| l.level = Logger::UNKNOWN }
ActionCable::Connection::TaggedLoggerProxy.new(inner_logger, tags: [])
end
end

View file

@ -39,6 +39,7 @@ module Rails
paths.add "app", eager_load: true, glob: "{*,*/concerns}"
paths.add "app/assets", glob: "*"
paths.add "app/controllers", eager_load: true
paths.add "app/channels", eager_load: true, glob: "**/*_channel.rb"
paths.add "app/helpers", eager_load: true
paths.add "app/models", eager_load: true
paths.add "app/mailers", eager_load: true