Permalink
Browse files

When autodetecting application type, give Rack higher priority than R…

…ails. This allows one to put config.ru in a Rails app directory. Fixes issue #338.
  • Loading branch information...
1 parent 5967ed7 commit 529aef820dc999fc17ea46f797363d8ffe131fa9 @spohlenz spohlenz committed with FooBarWidget Jul 13, 2009
View
@@ -15,6 +15,10 @@ Release 2.2.6
* Some Ruby 1.9 compatibility fixes. Issue #398.
* The installer now displays correct dependency installation instructions
for Mandriva Linux.
+ * When autodetecting the application type, Rack is now given more priority
+ than Rails. This allows one to drop a config.ru file in a Rails directory
+ and have it detected as a Rack application instead of a Rails application.
+ Patch contributed by Sam Pohlenz: issue #338.
Release 2.2.5
@@ -170,20 +170,20 @@ class DirectoryMapper {
}
UPDATE_TRACE_POINT();
- if (shouldAutoDetectRails()
- && verifyRailsDir(config->getAppRoot(ap_document_root(r)), cstat, throttleRate)) {
+ if (shouldAutoDetectRack()
+ && verifyRackDir(config->getAppRoot(ap_document_root(r)), cstat, throttleRate)) {
baseURIKnown = true;
baseURI = "/";
- appType = RAILS;
+ appType = RACK;
return baseURI;
}
UPDATE_TRACE_POINT();
- if (shouldAutoDetectRack()
- && verifyRackDir(config->getAppRoot(ap_document_root(r)), cstat, throttleRate)) {
+ if (shouldAutoDetectRails()
+ && verifyRailsDir(config->getAppRoot(ap_document_root(r)), cstat, throttleRate)) {
baseURIKnown = true;
baseURI = "/";
- appType = RACK;
+ appType = RAILS;
return baseURI;
}
@@ -91,18 +91,18 @@ detect_application_type(const ngx_str_t *public_dir) {
ngx_memzero(filename, sizeof(filename));
ngx_snprintf(filename, sizeof(filename), "%s/%s",
- public_dir->data, "../config/environment.rb");
+ public_dir->data, "../config.ru");
if (file_exists(filename, 1)) {
- return AP_RAILS;
+ return AP_RACK;
}
ngx_memzero(filename, sizeof(filename));
ngx_snprintf(filename, sizeof(filename), "%s/%s",
- public_dir->data, "../config.ru");
+ public_dir->data, "../config/environment.rb");
if (file_exists(filename, 1)) {
- return AP_RACK;
+ return AP_RAILS;
}
-
+
ngx_memzero(filename, sizeof(filename));
ngx_snprintf(filename, sizeof(filename), "%s/%s",
public_dir->data, "../passenger_wsgi.py");
@@ -554,6 +554,22 @@ def index
it_should_behave_like "HelloWorld Rack application"
end
+ describe "Rack application running within Rails directory structure" do
+ before :all do
+ @stub = setup_rails_stub('mycook')
+ FileUtils.cp_r("stub/rack/.", @stub.app_root)
+ @apache2.set_vhost('passenger.test', File.expand_path(@stub.app_root) + "/public")
+ @apache2.start
+ @server = "http://passenger.test:#{@apache2.port}"
+ end
+
+ after :all do
+ @stub.destroy
+ end
+
+ it_should_behave_like "HelloWorld Rack application"
+ end
+
describe "WSGI application running in root URI" do
before :all do
@stub = setup_stub('wsgi')
@@ -94,6 +94,52 @@
end
end
+ describe "Rack application running in root URI" do
+ before :all do
+ @server = "http://passenger.test:#{@nginx.port}"
+ @stub = setup_stub('rack')
+ @nginx.add_server do |server|
+ server[:server_name] = "passenger.test"
+ server[:root] = File.expand_path("#{@stub.app_root}/public")
+ end
+ @nginx.start
+ end
+
+ after :all do
+ @stub.destroy
+ end
+
+ before :each do
+ @stub.reset
+ end
+
+ it_should_behave_like "HelloWorld Rack application"
+ end
+
+ describe "Rack application running within Rails directory structure" do
+ before :all do
+ @server = "http://passenger.test:#{@nginx.port}"
+ @stub = setup_rails_stub('mycook')
+ FileUtils.cp_r("stub/rack/.", @stub.app_root)
+ @nginx.add_server do |server|
+ server[:server_name] = "passenger.test"
+ server[:root] = File.expand_path("#{@stub.app_root}/public")
+ end
+ @nginx.start
+ end
+
+ after :all do
+ @stub.destroy
+ end
+
+ before :each do
+ @stub.reset
+ FileUtils.cp_r("stub/rack/.", @stub.app_root)
+ end
+
+ it_should_behave_like "HelloWorld Rack application"
+ end
+
##### Helper methods #####

0 comments on commit 529aef8

Please sign in to comment.