aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--actionpack/Gemfile14
-rw-r--r--actionpack/Rakefile12
-rw-r--r--actionpack/lib/action_controller/metal.rb22
-rw-r--r--actionpack/test/abstract_unit.rb9
-rw-r--r--actionpack/test/new_base/middleware_test.rb77
-rw-r--r--actionpack/test/new_base/test_helper.rb5
-rw-r--r--actionpack/vendor/gems/cache/RedCloth-4.2.2.gembin0 -> 224256 bytes
-rw-r--r--actionpack/vendor/gems/cache/mocha-0.9.7.gembin0 -> 59906 bytes
-rw-r--r--actionpack/vendor/gems/cache/rack-1.0.0.gembin0 -> 133632 bytes
-rw-r--r--actionpack/vendor/gems/cache/rack-test-0.4.2.gembin0 -> 17408 bytes
-rw-r--r--actionpack/vendor/gems/cache/rake-0.8.7.gembin0 -> 104960 bytes
-rw-r--r--actionpack/vendor/gems/cache/sqlite3-ruby-1.2.5.gembin0 -> 74240 bytes
-rw-r--r--activesupport/lib/active_support/message_verifier.rb15
14 files changed, 139 insertions, 20 deletions
diff --git a/.gitignore b/.gitignore
index 7a61c37718..f0e6c8385f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,8 @@ railties/guides/output
*.rbc
*.swp
*.swo
+actionpack/bin
+*/vendor/gems/gems
+*/vendor/gems/specifications
+actionpack/vendor/gems/environment.rb
+*/vendor/gems/dirs/specifications \ No newline at end of file
diff --git a/actionpack/Gemfile b/actionpack/Gemfile
new file mode 100644
index 0000000000..ed1ae2e9c0
--- /dev/null
+++ b/actionpack/Gemfile
@@ -0,0 +1,14 @@
+rails_root = Pathname.new(File.dirname(__FILE__)).join("..")
+
+gem "rack", "~> 1.0.0"
+gem "rack-test", "~> 0.4.2"
+gem "activesupport", "3.0.pre", :vendored_at => rails_root.join("activesupport")
+gem "activemodel", "3.0.pre", :vendored_at => rails_root.join("activemodel")
+
+only :test do
+ gem "mocha"
+ gem "sqlite3-ruby"
+ gem "RedCloth"
+end
+
+disable_system_gems \ No newline at end of file
diff --git a/actionpack/Rakefile b/actionpack/Rakefile
index 06f6905af0..6d98aa3190 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -17,7 +17,17 @@ RUBY_FORGE_PROJECT = "actionpack"
RUBY_FORGE_USER = "webster132"
desc "Default Task"
-task :default => [ :test ]
+task :default => [ :bundle, :test ]
+
+task :bundle do
+ puts "Checking if the bundled testing requirements are up to date..."
+ result = system "gem bundle"
+ unless result
+ puts "The gem bundler is not installed. Installing."
+ system "gem install bundler"
+ system "gem bundle"
+ end
+end
# Run the unit tests
diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb
index 51fbba3661..6aa4fe6019 100644
--- a/actionpack/lib/action_controller/metal.rb
+++ b/actionpack/lib/action_controller/metal.rb
@@ -79,6 +79,15 @@ module ActionController
end
class ActionEndpoint
+ @@endpoints = Hash.new {|h,k| h[k] = Hash.new {|h,k| h[k] = {} } }
+
+ def self.for(controller, action, stack)
+ @@endpoints[controller][action][stack] ||= begin
+ endpoint = new(controller, action)
+ stack.build(endpoint)
+ end
+ end
+
def initialize(controller, action)
@controller, @action = controller, action
end
@@ -88,6 +97,16 @@ module ActionController
end
end
+ extlib_inheritable_accessor(:middleware_stack) { ActionDispatch::MiddlewareStack.new }
+
+ def self.use(*args)
+ middleware_stack.use(*args)
+ end
+
+ def self.middleware
+ middleware_stack
+ end
+
# Return a rack endpoint for the given action. Memoize the endpoint, so
# multiple calls into MyController.action will return the same object
# for the same action.
@@ -98,8 +117,7 @@ module ActionController
# ==== Returns
# Proc:: A rack application
def self.action(name)
- @actions ||= {}
- @actions[name.to_s] ||= ActionEndpoint.new(self, name)
+ ActionEndpoint.for(self, name, middleware_stack)
end
end
end
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index a5222fc96d..528180ae32 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -1,20 +1,15 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
-$:.unshift(File.dirname(__FILE__) + '/../../activemodel/lib')
$:.unshift(File.dirname(__FILE__) + '/lib')
-
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
+require File.join(File.dirname(__FILE__), "..", "vendor", "gems", "environment")
+
ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp')
ENV['new_base'] = "true"
$stderr.puts "Running old tests on new_base"
-require 'rubygems'
-gem "rack", "~> 1.0.0"
-gem "rack-test", "~> 0.4.2"
-
require 'test/unit'
require 'active_support'
require 'active_support/test_case'
diff --git a/actionpack/test/new_base/middleware_test.rb b/actionpack/test/new_base/middleware_test.rb
new file mode 100644
index 0000000000..15aef270e2
--- /dev/null
+++ b/actionpack/test/new_base/middleware_test.rb
@@ -0,0 +1,77 @@
+require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
+
+module MiddlewareTest
+ class MyMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Test"] = "Success"
+ result[1]["Middleware-Order"] = "First"
+ result
+ end
+ end
+
+ class ExclaimerMiddleware
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ result = @app.call(env)
+ result[1]["Middleware-Order"] << "!"
+ result
+ end
+ end
+
+ class MyController < ActionController::Metal
+ use MyMiddleware
+
+ middleware.insert_before MyMiddleware, ExclaimerMiddleware
+
+ def index
+ self.response_body = "Hello World"
+ end
+ end
+
+ class InheritedController < MyController
+ end
+
+ module MiddlewareTests
+ extend ActiveSupport::Testing::Declarative
+
+ test "middleware that is 'use'd is called as part of the Rack application" do
+ result = @app.call(env_for("/"))
+ assert_equal "Hello World", result[2]
+ assert_equal "Success", result[1]["Middleware-Test"]
+ end
+
+ test "the middleware stack is exposed as 'middleware' in the controller" do
+ result = @app.call(env_for("/"))
+ assert_equal "First!", result[1]["Middleware-Order"]
+ end
+ end
+
+ class TestMiddleware < ActiveSupport::TestCase
+ include MiddlewareTests
+
+ def setup
+ @app = MyController.action(:index)
+ end
+
+ def env_for(url)
+ Rack::MockRequest.env_for(url)
+ end
+ end
+
+ class TestInheritedMiddleware < TestMiddleware
+ def setup
+ @app = InheritedController.action(:index)
+ end
+
+ test "middleware inherits" do
+ end
+ end
+end
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index 0833e1a11d..5a901ab9d8 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -1,10 +1,7 @@
$:.unshift(File.dirname(__FILE__) + '/../../lib')
-$:.unshift(File.dirname(__FILE__) + '/../../../activesupport/lib')
$:.unshift(File.dirname(__FILE__) + '/../lib')
-require 'rubygems'
-gem "rack", "~> 1.0.0"
-gem "rack-test", "~> 0.4.2"
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "vendor", "gems", "environment"))
require 'test/unit'
require 'active_support'
diff --git a/actionpack/vendor/gems/cache/RedCloth-4.2.2.gem b/actionpack/vendor/gems/cache/RedCloth-4.2.2.gem
new file mode 100644
index 0000000000..b754b7d113
--- /dev/null
+++ b/actionpack/vendor/gems/cache/RedCloth-4.2.2.gem
Binary files differ
diff --git a/actionpack/vendor/gems/cache/mocha-0.9.7.gem b/actionpack/vendor/gems/cache/mocha-0.9.7.gem
new file mode 100644
index 0000000000..1cbb7253a5
--- /dev/null
+++ b/actionpack/vendor/gems/cache/mocha-0.9.7.gem
Binary files differ
diff --git a/actionpack/vendor/gems/cache/rack-1.0.0.gem b/actionpack/vendor/gems/cache/rack-1.0.0.gem
new file mode 100644
index 0000000000..e20843cf92
--- /dev/null
+++ b/actionpack/vendor/gems/cache/rack-1.0.0.gem
Binary files differ
diff --git a/actionpack/vendor/gems/cache/rack-test-0.4.2.gem b/actionpack/vendor/gems/cache/rack-test-0.4.2.gem
new file mode 100644
index 0000000000..0b82741938
--- /dev/null
+++ b/actionpack/vendor/gems/cache/rack-test-0.4.2.gem
Binary files differ
diff --git a/actionpack/vendor/gems/cache/rake-0.8.7.gem b/actionpack/vendor/gems/cache/rake-0.8.7.gem
new file mode 100644
index 0000000000..0740cec7b0
--- /dev/null
+++ b/actionpack/vendor/gems/cache/rake-0.8.7.gem
Binary files differ
diff --git a/actionpack/vendor/gems/cache/sqlite3-ruby-1.2.5.gem b/actionpack/vendor/gems/cache/sqlite3-ruby-1.2.5.gem
new file mode 100644
index 0000000000..a009b0ba71
--- /dev/null
+++ b/actionpack/vendor/gems/cache/sqlite3-ruby-1.2.5.gem
Binary files differ
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb
index 5596784eff..8d14423d91 100644
--- a/activesupport/lib/active_support/message_verifier.rb
+++ b/activesupport/lib/active_support/message_verifier.rb
@@ -38,21 +38,24 @@ module ActiveSupport
end
private
- if "foo".respond_to?(:bytesize)
+ if "foo".respond_to?(:force_encoding)
# constant-time comparison algorithm to prevent timing attacks
- # > 1.8.6 friendly version
def secure_compare(a, b)
- if a.bytesize == b.bytesize
+ a = a.force_encoding(Encoding::BINARY)
+ b = b.force_encoding(Encoding::BINARY)
+
+ if a.length == b.length
result = 0
- j = b.each_byte
- a.each_byte { |i| result |= i ^ j.next }
+ for i in 0..(a.length - 1)
+ result |= a[i].ord ^ b[i].ord
+ end
result == 0
else
false
end
end
else
- # For <= 1.8.6
+ # For 1.8
def secure_compare(a, b)
if a.length == b.length
result = 0