This project is archived and is in readonly mode.
[PATCH] Using Sinatra as middleware fails
-
jaswope
- Tag changed from patch to 2-3-stable, patch
-
jaswope
- Title changed from Using Sinatra as middleware fails to [PATCH] Using Sinatra as middleware fails
-
Yehuda Katz (wycats)
- Milestone set to 2.3.6
- Assigned user set to Yehuda Katz (wycats)
This is handled in master by first checking for respond_to?(:new), the middleware convention:
def klass if @klass.respond_to?(:new) @klass elsif @klass.respond_to?(:call) @klass.call else ActiveSupport::Inflector.constantize(@klass.to_s) end endPerhaps do the same for 2.3? Maybe just backport the entire middleware stack?
-
Anil Wadghule
I am able to do this
λ cat config.ru
require "config/environment" require 'sinatra' use Rack::Reloader use Sinatra::Application use Rails::Rack::LogTailer use Rails::Rack::Static use Rack::CommonLogger run ActionController::Dispatcher.newAttached is a app showing it's running properly.
Am I missing something here?
-
José Valim
- Assigned user changed from Yehuda Katz (wycats) to José Valim
Can someone provide a patch with the fix mentioned by Yehuda on 2-3-stable?
-
Rizwan Reza
- State changed from new to open
-
Anil Wadghule
Attached is a patch to backport middleware stack from Rails 3 to Rails 2-3. All the tests pass fine.
-
Rizwan Reza
Hey Anil,
Nice work. There are some tests in middleware_stack_test you might want backport as well. Just the ones we need.
-
José Valim
There is no need to backport the whole middleware stack. And as Rizwan said, it would be good to backport the relative tests as well.
-
Anil Wadghule
Attached is a patch which backports a test from Rails 3 middleware stack to Rails 2-3
Also I don't see any code which I should remove from the 'backport_middleware_stack' patch.
-
José Valim
Anil, your patch, for instance, change the build method to allow a block to be given. But there are no tests for it in your patch. Also there are not tests for the case described in this ticket. So if we backport all these, we need to add the respective tests. Thanks!
-
Anil Wadghule
Okay I will add patch with necessary tests.
-
José Valim
- State changed from open to incomplete
Anil, you just need to backport the part relative to the naming (that Yehuda posted) and not the whole middleware stack. Still willing to try out a patch?
-
Anil Wadghule
okay Jose, I will try to provide the patch soon.
-
Anil Wadghule
José, I have attached a patch which fixes this issue.
I could not find way to write tests for it. Even in Rails 3 master seems that there are no tests which tests @klass.respond_to?(:call) which I could just refer to. If there are any, can you tell me where are those.
-
Neeraj Singh
@Anil Can you post an app which uses Sinatra as a middleware and fails without the patch. I don't fully understand rack stuff and an app demonstrating the problem would be helpful.
I am close to finishing writing test case for the patch you added. However a deeper understanding of the problem would help me write better test. Thanks.
-
Anil Wadghule
Neeraj, Attached is a rails app which fails on Rails 2.3.8 without my fix (try to access http://localhost:3000/).
I am eager to see the test patch you have writteen for the fix :) -
Anil Wadghule
Neeraj, any update on the test patch?
-
Neeraj Singh
Hey Anil,
Thanks for providing the app but I couldn't create the tests.
-
José Valim
- State changed from incomplete to stale
