aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb1
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb6
-rw-r--r--actionpack/lib/action_dispatch/testing/test_process.rb4
-rw-r--r--actionpack/lib/action_view/test_case.rb1
-rw-r--r--actionpack/test/controller/mime_responds_test.rb1
-rw-r--r--actionpack/test/controller/test_test.rb16
-rw-r--r--actionpack/test/dispatch/routing_test.rb9
-rw-r--r--actionpack/test/template/erb_util_test.rb4
9 files changed, 37 insertions, 7 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 388169d981..064e06bf92 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*Rails 3.0.0 [beta 4/release candidate] (unreleased)*
+* Add support for shorthand routes like /projects/status(.:format) #4423 [Diego Carrion]
+
* Changed translate helper so that it doesn’t mark every translation as safe HTML. Only keys with a "_html" suffix and keys named "html" are considered to be safe HTML. All other translations are left untouched. [Craig Davey]
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 362e5ec970..8b730a97ee 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -1,6 +1,7 @@
require 'digest/md5'
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/object/blank'
+require 'active_support/core_ext/class/attribute_accessors'
module ActionDispatch # :nodoc:
# Represents an HTTP response generated by a controller action. One can use
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 53585740ce..ef2826a4e8 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -66,8 +66,8 @@ module ActionDispatch
path = normalize_path(path)
if using_match_shorthand?(path, options)
- options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1')
- options[:as] ||= path[1..-1].gsub("/", "_")
+ options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1').sub(%r{\(.*\)}, '')
+ options[:as] ||= path[1..-1].gsub("/", "_").sub(%r{\(.*\)}, '')
end
[ path, options ]
@@ -80,7 +80,7 @@ module ActionDispatch
# match "account/overview"
def using_match_shorthand?(path, options)
- path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$}
+ path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w+/?]+(\(.*\))*$}
end
def normalize_path(path)
diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb
index d4eecac2de..79f309cae7 100644
--- a/actionpack/lib/action_dispatch/testing/test_process.rb
+++ b/actionpack/lib/action_dispatch/testing/test_process.rb
@@ -3,13 +3,13 @@ require 'action_dispatch/middleware/flash'
module ActionDispatch
module TestProcess
def assigns(key = nil)
- assigns = {}
+ assigns = {}.with_indifferent_access
@controller.instance_variable_names.each do |ivar|
next if ActionController::Base.protected_instance_variables.include?(ivar)
assigns[ivar[1..-1]] = @controller.instance_variable_get(ivar)
end
- key.nil? ? assigns : assigns[key.to_s]
+ key.nil? ? assigns : assigns[key]
end
def session
diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb
index ddea9cfd92..beda7743bf 100644
--- a/actionpack/lib/action_view/test_case.rb
+++ b/actionpack/lib/action_view/test_case.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/object/blank'
+require 'action_controller'
require 'action_controller/test_case'
require 'action_view'
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index 53cd3f0801..c8ba8bcaf3 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'controller/fake_models'
+require 'active_support/core_ext/hash/conversions'
class RespondToController < ActionController::Base
layout :set_layout
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 6f1ce2fef7..f9fc7a0976 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -113,6 +113,11 @@ XML
render :nothing => true
end
+ def test_assigns
+ @foo = "foo"
+ render :nothing => true
+ end
+
private
def rescue_action(e)
raise e
@@ -230,6 +235,17 @@ XML
assert_equal "OK", @response.body
end
+ def test_assigns
+ process :test_assigns
+ # assigns can be accessed using assigns(key)
+ # or assigns[key], where key is a string or
+ # a symbol
+ assert_equal "foo", assigns(:foo)
+ assert_equal "foo", assigns("foo")
+ assert_equal "foo", assigns[:foo]
+ assert_equal "foo", assigns["foo"]
+ end
+
def test_assert_tag_tag
process :test_html_output
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 8940990712..5bca476b27 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -54,6 +54,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match "/local/:action", :controller => "local"
+ match "/projects/status(.:format)"
+
constraints(:ip => /192\.168\.1\.\d\d\d/) do
get 'admin' => "queenbee#index"
end
@@ -426,6 +428,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_projects_status
+ with_test_routes do
+ assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true)
+ assert_equal '/projects/status.json', url_for(:controller => 'projects', :action => 'status', :format => 'json', :only_path => true)
+ end
+ end
+
def test_projects
with_test_routes do
get '/projects'
diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb
index 06155b1f30..d3129d0e1a 100644
--- a/actionpack/test/template/erb_util_test.rb
+++ b/actionpack/test/template/erb_util_test.rb
@@ -4,12 +4,12 @@ class ErbUtilTest < Test::Unit::TestCase
include ERB::Util
ERB::Util::HTML_ESCAPE.each do |given, expected|
- define_method "test_html_escape_#{expected.gsub /\W/, ''}" do
+ define_method "test_html_escape_#{expected.gsub(/\W/, '')}" do
assert_equal expected, html_escape(given)
end
unless given == '"'
- define_method "test_json_escape_#{expected.gsub /\W/, ''}" do
+ define_method "test_json_escape_#{expected.gsub(/\W/, '')}" do
assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
end
end