lib/stimulus_reflex/reflex.rb in stimulus_reflex-3.3.0 vs lib/stimulus_reflex/reflex.rb in stimulus_reflex-3.4.0.pre0
- old
+ new
@@ -43,12 +43,14 @@
end
end
attr_reader :channel, :url, :element, :selectors, :method_name, :broadcaster, :permanent_attribute_name
+ alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
+
delegate :connection, :stream_name, to: :channel
- delegate :session, to: :request
+ delegate :flash, :session, to: :request
delegate :broadcast, :broadcast_message, to: :broadcaster
def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, permanent_attribute_name: nil, params: {})
@channel = channel
@url = url
@@ -64,25 +66,30 @@
def request
@request ||= begin
uri = URI.parse(url)
path = ActionDispatch::Journey::Router::Utils.normalize_path(uri.path)
query_hash = Rack::Utils.parse_nested_query(uri.query)
- req = ActionDispatch::Request.new(
- connection.env.merge(
- Rack::MockRequest.env_for(uri.to_s).merge(
- "rack.request.query_hash" => query_hash,
- "rack.request.query_string" => uri.query,
- "ORIGINAL_SCRIPT_NAME" => "",
- "ORIGINAL_FULLPATH" => path,
- Rack::SCRIPT_NAME => "",
- Rack::PATH_INFO => path,
- Rack::REQUEST_PATH => path,
- Rack::QUERY_STRING => uri.query
- )
- )
+ mock_env = Rack::MockRequest.env_for(uri.to_s)
+
+ mock_env.merge!(
+ "rack.request.query_hash" => query_hash,
+ "rack.request.query_string" => uri.query,
+ "ORIGINAL_SCRIPT_NAME" => "",
+ "ORIGINAL_FULLPATH" => path,
+ Rack::SCRIPT_NAME => "",
+ Rack::PATH_INFO => path,
+ Rack::REQUEST_PATH => path,
+ Rack::QUERY_STRING => uri.query
)
+
+ env = connection.env.merge(mock_env)
+ req = ActionDispatch::Request.new(env)
+
path_params = Rails.application.routes.recognize_path_with_request(req, url, req.env[:extras] || {})
+ path_params[:controller] = path_params[:controller].force_encoding("UTF-8")
+ path_params[:action] = path_params[:action].force_encoding("UTF-8")
+
req.env.merge(ActionDispatch::Http::Parameters::PARAMETERS_KEY => path_params)
req.env["action_dispatch.request.parameters"] = req.parameters.merge(@params)
req.tap { |r| r.session.send :load! }
end
end
@@ -108,13 +115,9 @@
instance_variables.each { |name| c.instance_variable_set name, instance_variable_get(name) }
c.request = request
c.response = ActionDispatch::Response.new
end
end
- end
-
- def url_params
- @url_params ||= Rails.application.routes.recognize_path_with_request(request, request.path, request.env[:extras] || {})
end
def process(name, *args)
reflex_invoked = false
result = run_callbacks(:process) {