aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-03-12 15:31:24 +0000
committerPratik Naik <pratiknaik@gmail.com>2009-03-12 15:31:24 +0000
commit53744c543880999a7ad3f1e026875df3283978f1 (patch)
tree8d01e0c15a384a46db176ad8d5cdd0bd6c9024a8 /railties
parent053afbe3bd26d627ee04a0aaa73554b7be422f05 (diff)
parent47bdf3bf40ec17e1f8ca1c0e3d7f697d0c4cd1bf (diff)
downloadrails-53744c543880999a7ad3f1e026875df3283978f1.tar.gz
rails-53744c543880999a7ad3f1e026875df3283978f1.tar.bz2
rails-53744c543880999a7ad3f1e026875df3283978f1.zip
Merge commit 'mainstream/master'
Conflicts: actionpack/lib/action_view/helpers/text_helper.rb activesupport/lib/active_support/inflector.rb
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/commands/plugin.rb3
-rw-r--r--railties/lib/rails/rack/static.rb17
-rw-r--r--railties/lib/rails_generator/generators/applications/app/template_runner.rb2
-rw-r--r--railties/test/fixtures/public/foo/bar.html1
-rw-r--r--railties/test/fixtures/public/foo/index.html1
-rw-r--r--railties/test/fixtures/public/index.html1
-rw-r--r--railties/test/generators/rails_template_runner_test.rb5
-rw-r--r--railties/test/rack_static_test.rb46
8 files changed, 70 insertions, 6 deletions
diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb
index a67c2ab447..8589b1698d 100644
--- a/railties/lib/commands/plugin.rb
+++ b/railties/lib/commands/plugin.rb
@@ -134,7 +134,8 @@ class RailsEnvironment
def externals
return [] unless use_externals?
ext = `svn propget svn:externals "#{root}/vendor/plugins"`
- ext.reject{ |line| line.strip == '' }.map do |line|
+ lines = ext.respond_to?(:lines) ? ext.lines : ext
+ lines.reject{ |line| line.strip == '' }.map do |line|
line.strip.split(/\s+/, 2)
end
end
diff --git a/railties/lib/rails/rack/static.rb b/railties/lib/rails/rack/static.rb
index ef4e2642e2..f07c6beb5e 100644
--- a/railties/lib/rails/rack/static.rb
+++ b/railties/lib/rails/rack/static.rb
@@ -13,14 +13,18 @@ module Rails
def call(env)
path = env['PATH_INFO'].chomp('/')
method = env['REQUEST_METHOD']
- cached_path = (path.empty? ? 'index' : path) + ::ActionController::Base.page_cache_extension
if FILE_METHODS.include?(method)
if file_exist?(path)
return @file_server.call(env)
- elsif file_exist?(cached_path)
- env['PATH_INFO'] = cached_path
- return @file_server.call(env)
+ else
+ cached_path = directory_exist?(path) ? "#{path}/index" : path
+ cached_path += ::ActionController::Base.page_cache_extension
+
+ if file_exist?(cached_path)
+ env['PATH_INFO'] = cached_path
+ return @file_server.call(env)
+ end
end
end
@@ -32,6 +36,11 @@ module Rails
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
File.file?(full_path) && File.readable?(full_path)
end
+
+ def directory_exist?(path)
+ full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
+ File.directory?(full_path) && File.readable?(full_path)
+ end
end
end
end
diff --git a/railties/lib/rails_generator/generators/applications/app/template_runner.rb b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
index 73ab57d4f0..3b49b1fa92 100644
--- a/railties/lib/rails_generator/generators/applications/app/template_runner.rb
+++ b/railties/lib/rails_generator/generators/applications/app/template_runner.rb
@@ -90,7 +90,7 @@ module Rails
gems_code = "config.gem '#{name}'"
if options.any?
- opts = options.inject([]) {|result, h| result << [":#{h[0]} => '#{h[1]}'"] }.sort.join(", ")
+ opts = options.inject([]) {|result, h| result << [":#{h[0]} => #{h[1].inspect.gsub('"',"'")}"] }.sort.join(", ")
gems_code << ", #{opts}"
end
diff --git a/railties/test/fixtures/public/foo/bar.html b/railties/test/fixtures/public/foo/bar.html
new file mode 100644
index 0000000000..9a35646205
--- /dev/null
+++ b/railties/test/fixtures/public/foo/bar.html
@@ -0,0 +1 @@
+/foo/bar.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/foo/index.html b/railties/test/fixtures/public/foo/index.html
new file mode 100644
index 0000000000..497a2e898f
--- /dev/null
+++ b/railties/test/fixtures/public/foo/index.html
@@ -0,0 +1 @@
+/foo/index.html \ No newline at end of file
diff --git a/railties/test/fixtures/public/index.html b/railties/test/fixtures/public/index.html
new file mode 100644
index 0000000000..525950ba6b
--- /dev/null
+++ b/railties/test/fixtures/public/index.html
@@ -0,0 +1 @@
+/index.html \ No newline at end of file
diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb
index 4e1937e0c6..2da6bd59b5 100644
--- a/railties/test/generators/rails_template_runner_test.rb
+++ b/railties/test/generators/rails_template_runner_test.rb
@@ -93,6 +93,11 @@ class RailsTemplateRunnerTest < GeneratorTestCase
assert_generated_file_with_data('config/environments/test.rb', "config.gem 'quietbacktrace'")
end
+ def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly
+ run_template_method(:gem, 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com')
+ assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com'")
+ end
+
def test_environment_should_include_data_in_environment_initializer_block
load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]'
run_template_method(:environment, load_paths)
diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb
new file mode 100644
index 0000000000..ad673f6f19
--- /dev/null
+++ b/railties/test/rack_static_test.rb
@@ -0,0 +1,46 @@
+require 'abstract_unit'
+
+require 'action_controller'
+require 'rails/rack'
+
+class RackStaticTest < ActiveSupport::TestCase
+ def setup
+ FileUtils.cp_r "#{RAILS_ROOT}/fixtures/public", "#{RAILS_ROOT}/public"
+ end
+
+ def teardown
+ FileUtils.rm_rf "#{RAILS_ROOT}/public"
+ end
+
+ DummyApp = lambda { |env|
+ [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]]
+ }
+ App = Rails::Rack::Static.new(DummyApp)
+
+ test "serves dynamic content" do
+ assert_equal "Hello, World!", get("/nofile")
+ end
+
+ test "serves static index at root" do
+ assert_equal "/index.html", get("/index.html")
+ assert_equal "/index.html", get("/index")
+ assert_equal "/index.html", get("/")
+ end
+
+ test "serves static file in directory" do
+ assert_equal "/foo/bar.html", get("/foo/bar.html")
+ assert_equal "/foo/bar.html", get("/foo/bar/")
+ assert_equal "/foo/bar.html", get("/foo/bar")
+ end
+
+ test "serves static index file in directory" do
+ assert_equal "/foo/index.html", get("/foo/index.html")
+ assert_equal "/foo/index.html", get("/foo/")
+ assert_equal "/foo/index.html", get("/foo")
+ end
+
+ private
+ def get(path)
+ Rack::MockRequest.new(App).request("GET", path).body
+ end
+end