aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorBrian Lopez <seniorlopez@gmail.com>2010-08-09 12:43:49 -0700
committerBrian Lopez <seniorlopez@gmail.com>2010-08-09 12:43:49 -0700
commitee9c950f2fe0c7953f0a9ad6a53439da7a4e89bc (patch)
tree1b3f6a3e49be0ebacb251de0c0fc12bf64e2e596 /actionpack
parentd8b90114ddd2a432280d114b9fe4ef1fdb38d132 (diff)
parent7171161124a2852ee7b40c5c632ba8e092c97409 (diff)
downloadrails-ee9c950f2fe0c7953f0a9ad6a53439da7a4e89bc.tar.gz
rails-ee9c950f2fe0c7953f0a9ad6a53439da7a4e89bc.tar.bz2
rails-ee9c950f2fe0c7953f0a9ad6a53439da7a4e89bc.zip
bringing over latest from master
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/README.rdoc2
-rw-r--r--actionpack/lib/abstract_controller/base.rb12
-rw-r--r--actionpack/lib/action_dispatch/middleware/best_standards_support.rb13
-rw-r--r--actionpack/lib/action_dispatch/routing/deprecated_mapper.rb1
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb5
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb9
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb1
-rw-r--r--actionpack/lib/action_view/helpers/form_tag_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/sanitize_helper.rb2
-rw-r--r--actionpack/lib/action_view/helpers/text_helper.rb3
-rw-r--r--actionpack/test/abstract/abstract_controller_test.rb14
-rw-r--r--actionpack/test/controller/resources_test.rb1
-rw-r--r--actionpack/test/dispatch/routing_test.rb55
-rw-r--r--actionpack/test/template/form_helper_test.rb2
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb2
15 files changed, 84 insertions, 40 deletions
diff --git a/actionpack/README.rdoc b/actionpack/README.rdoc
index 0e7d164623..b297ceb0e2 100644
--- a/actionpack/README.rdoc
+++ b/actionpack/README.rdoc
@@ -1,6 +1,6 @@
= Action Pack -- From request to response
-Action Pack is a framework for handling and responding to web requests. It it
+Action Pack is a framework for handling and responding to web requests. It
provides mechanisms for *routing* (mapping request URLs to actions), defining
*controllers* that implement actions, and generating responses by rendering
*views*, which are templates of various formats. In short, Action Pack
diff --git a/actionpack/lib/abstract_controller/base.rb b/actionpack/lib/abstract_controller/base.rb
index 8a8337858b..db0a6736e0 100644
--- a/actionpack/lib/abstract_controller/base.rb
+++ b/actionpack/lib/abstract_controller/base.rb
@@ -72,6 +72,13 @@ module AbstractController
end
end
+ # action_methods are cached and there is sometimes need to refresh
+ # them. clear_action_methods! allows you to do that, so next time
+ # you run action_methods, they will be recalculated
+ def clear_action_methods!
+ @action_methods = nil
+ end
+
# Returns the full controller name, underscored, without the ending Controller.
# For instance, MyApp::MyPostsController would return "my_app/my_posts" for
# controller_name.
@@ -81,6 +88,11 @@ module AbstractController
def controller_path
@controller_path ||= name.sub(/Controller$/, '').underscore unless anonymous?
end
+
+ def method_added(name)
+ super
+ clear_action_methods!
+ end
end
abstract!
diff --git a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb
index df8f7766bb..69adcc419f 100644
--- a/actionpack/lib/action_dispatch/middleware/best_standards_support.rb
+++ b/actionpack/lib/action_dispatch/middleware/best_standards_support.rb
@@ -1,12 +1,21 @@
module ActionDispatch
class BestStandardsSupport
- def initialize(app)
+ def initialize(app, type = true)
@app = app
+
+ @header = case type
+ when true
+ "IE=Edge,chrome=1"
+ when :builtin
+ "IE=Edge"
+ when false
+ nil
+ end
end
def call(env)
status, headers, body = @app.call(env)
- headers["X-UA-Compatible"] = "IE=Edge,chrome=1"
+ headers["X-UA-Compatible"] = @header
[status, headers, body]
end
end
diff --git a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
index 4904f0633d..e04062ce8b 100644
--- a/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/deprecated_mapper.rb
@@ -1,5 +1,6 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/with_options'
+require 'active_support/core_ext/object/try'
module ActionDispatch
module Routing
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 526c97ff8e..c118c72440 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1,3 +1,4 @@
+require 'erb'
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/object/blank'
@@ -277,7 +278,6 @@ module ActionDispatch
path = args.shift || block
path_proc = path.is_a?(Proc) ? path : proc { |params| path % params }
status = options[:status] || 301
- body = 'Moved Permanently'
lambda do |env|
req = Request.new(env)
@@ -290,11 +290,14 @@ module ActionDispatch
uri.host ||= req.host
uri.port ||= req.port unless req.port == 80
+ body = %(<html><body>You are being <a href="#{ERB::Util.h(uri.to_s)}">redirected</a>.</body></html>)
+
headers = {
'Location' => uri.to_s,
'Content-Type' => 'text/html',
'Content-Length' => body.length.to_s
}
+
[ status, headers, [body] ]
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 77688fe397..d23b580d97 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -392,10 +392,9 @@ module ActionDispatch
end
def generate
- error = ActionController::RoutingError.new("No route matches #{options.inspect}")
path, params = @set.set.generate(:path_info, named_route, options, recall, opts)
- raise error unless path
+ raise_routing_error unless path
params.reject! {|k,v| !v }
@@ -404,7 +403,7 @@ module ActionDispatch
path << "?#{params.to_query}" if params.any?
"#{script_name}#{path}"
rescue Rack::Mount::RoutingError
- raise error
+ raise_routing_error
end
def opts
@@ -421,6 +420,10 @@ module ActionDispatch
{:parameterize => parameterize}
end
+ def raise_routing_error
+ raise ActionController::RoutingError.new("No route matches #{options.inspect}")
+ end
+
def different_controller?
return false unless current_controller
controller.to_param != current_controller.to_param
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 8e58adaf59..b52795c575 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -1,6 +1,7 @@
require 'stringio'
require 'uri'
require 'active_support/core_ext/kernel/singleton_class'
+require 'active_support/core_ext/object/try'
require 'rack/test'
require 'test/unit/assertions'
diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb
index 9dac2d4538..1ea870426a 100644
--- a/actionpack/lib/action_view/helpers/form_tag_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb
@@ -538,7 +538,7 @@ module ActionView
def extra_tags_for_form(html_options)
snowman_tag = tag(:input, :type => "hidden",
- :name => "_snowman", :value => "&#9731;".html_safe)
+ :name => "_e", :value => "&#9731;".html_safe)
method = html_options.delete("method").to_s
diff --git a/actionpack/lib/action_view/helpers/sanitize_helper.rb b/actionpack/lib/action_view/helpers/sanitize_helper.rb
index 63f6154ec4..d82005fa24 100644
--- a/actionpack/lib/action_view/helpers/sanitize_helper.rb
+++ b/actionpack/lib/action_view/helpers/sanitize_helper.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/try'
require 'action_controller/vendor/html-scanner'
require 'action_view/helpers/tag_helper'
@@ -7,6 +8,7 @@ module ActionView
# The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements.
# These helper methods extend Action View making them callable within your template files.
module SanitizeHelper
+ extend ActiveSupport::Concern
# This +sanitize+ helper will html encode all tags and strip all attributes that
# aren't specifically allowed.
#
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 52a016c9c1..c1de5c8cb3 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -10,6 +10,9 @@ module ActionView
# your views. These helper methods extend Action View making them callable
# within your template files.
module TextHelper
+ extend ActiveSupport::Concern
+
+ include SanitizeHelper
# The preferred method of outputting text in your views is to use the
# <%= "text" %> eRuby syntax. The regular _puts_ and _print_ methods
# do not operate as expected in an eRuby code block. If you absolutely must
diff --git a/actionpack/test/abstract/abstract_controller_test.rb b/actionpack/test/abstract/abstract_controller_test.rb
index 3b5013a47a..19855490b4 100644
--- a/actionpack/test/abstract/abstract_controller_test.rb
+++ b/actionpack/test/abstract/abstract_controller_test.rb
@@ -250,5 +250,19 @@ module AbstractController
end
end
+ class Me6 < AbstractController::Base
+ self.action_methods
+
+ def index
+ end
+ end
+
+ class TestActionMethodsReloading < ActiveSupport::TestCase
+
+ test "action_methods should be reloaded after defining a new method" do
+ assert_equal ["index"], Me6.action_methods
+ end
+ end
+
end
end
diff --git a/actionpack/test/controller/resources_test.rb b/actionpack/test/controller/resources_test.rb
index a9d1c55c05..6c8f470fba 100644
--- a/actionpack/test/controller/resources_test.rb
+++ b/actionpack/test/controller/resources_test.rb
@@ -1,3 +1,4 @@
+require 'active_support/core_ext/object/try'
require 'abstract_unit'
class ResourcesController < ActionController::Base
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 4808663aa9..3f090b7254 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -1,3 +1,4 @@
+require 'erb'
require 'abstract_unit'
require 'controller/fake_controllers'
@@ -56,7 +57,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" }
match 'account/proc_req' => redirect {|params, req| "/#{req.method}" }
- match 'account/google' => redirect('http://www.google.com/')
+ match 'account/google' => redirect('http://www.google.com/', :status => 302)
match 'openid/login', :via => [:get, :post], :to => "openid#login"
@@ -501,9 +502,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
def test_login_redirect
with_test_routes do
get '/account/login'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/login', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/login'
end
end
@@ -511,18 +510,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
with_test_routes do
assert_equal '/account/logout', logout_redirect_path
get '/account/logout'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/logout', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/logout'
end
end
def test_namespace_redirect
with_test_routes do
get '/private'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/private/index', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/private/index'
end
end
@@ -586,27 +581,21 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
def test_redirect_modulo
with_test_routes do
get '/account/modulo/name'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/names', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/names'
end
end
def test_redirect_proc
with_test_routes do
get '/account/proc/person'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/people', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/people'
end
end
def test_redirect_proc_with_request
with_test_routes do
get '/account/proc_req'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com/GET', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com/GET'
end
end
@@ -1203,12 +1192,10 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- def test_redirect_with_complete_url
+ def test_redirect_with_complete_url_and_status
with_test_routes do
get '/account/google'
- assert_equal 301, @response.status
- assert_equal 'http://www.google.com/', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.google.com/', 302
end
end
@@ -1216,9 +1203,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
previous_host, self.host = self.host, 'www.example.com:3000'
with_test_routes do
get '/account/login'
- assert_equal 301, @response.status
- assert_equal 'http://www.example.com:3000/login', @response.headers['Location']
- assert_equal 'Moved Permanently', @response.body
+ verify_redirect 'http://www.example.com:3000/login'
end
ensure
self.host = previous_host
@@ -1899,8 +1884,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- private
- def with_test_routes
- yield
- end
+private
+ def with_test_routes
+ yield
+ end
+
+ def verify_redirect(url, status=301)
+ assert_equal status, @response.status
+ assert_equal url, @response.headers['Location']
+ assert_equal expected_redirect_body(url), @response.body
+ end
+
+ def expected_redirect_body(url)
+ %(<html><body>You are being <a href="#{ERB::Util.h(url)}">redirected</a>.</body></html>)
+ end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 9086a23345..be66710ae5 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -1513,7 +1513,7 @@ class FormHelperTest < ActionView::TestCase
def snowman(method = nil)
txt = %{<div style="margin:0;padding:0;display:inline">}
- txt << %{<input name="_snowman" type="hidden" value="&#9731;" />}
+ txt << %{<input name="_e" type="hidden" value="&#9731;" />}
txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
txt << %{</div>}
end
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 8a0f352bc0..6c85952d40 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -12,7 +12,7 @@ class FormTagHelperTest < ActionView::TestCase
method = options[:method]
txt = %{<div style="margin:0;padding:0;display:inline">}
- txt << %{<input name="_snowman" type="hidden" value="&#9731;" />}
+ txt << %{<input name="_e" type="hidden" value="&#9731;" />}
txt << %{<input name="_method" type="hidden" value="#{method}" />} if method
txt << %{</div>}
end