aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_controller/abstract_controller_test.rb53
-rw-r--r--actionpack/test/abstract_controller/callbacks_test.rb94
-rw-r--r--actionpack/test/abstract_controller/helper_test.rb5
-rw-r--r--actionpack/test/abstract_controller/layouts_test.rb55
-rw-r--r--actionpack/test/abstract_unit.rb12
-rw-r--r--actionpack/test/activerecord/active_record_store_test.rb25
-rw-r--r--actionpack/test/controller/action_pack_assertions_test.rb8
-rw-r--r--actionpack/test/controller/routing_test.rb86
-rw-r--r--actionpack/test/controller/test_test.rb3
-rw-r--r--actionpack/test/controller/url_rewriter_test.rb26
-rw-r--r--actionpack/test/controller/webservice_test.rb1
-rw-r--r--actionpack/test/dispatch/request/json_params_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/request/multipart_params_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/request/query_string_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/request/xml_params_parsing_test.rb1
-rw-r--r--actionpack/test/dispatch/session/cookie_store_test.rb19
-rw-r--r--actionpack/test/dispatch/session/mem_cache_store_test.rb16
-rw-r--r--actionpack/test/lib/controller/fake_controllers.rb9
-rw-r--r--actionpack/test/new_base/metal_test.rb11
-rw-r--r--actionpack/test/new_base/test_helper.rb24
-rw-r--r--actionpack/test/template/form_options_helper_i18n_test.rb27
22 files changed, 273 insertions, 206 deletions
diff --git a/actionpack/test/abstract_controller/abstract_controller_test.rb b/actionpack/test/abstract_controller/abstract_controller_test.rb
index 9438a4dfc9..7991436703 100644
--- a/actionpack/test/abstract_controller/abstract_controller_test.rb
+++ b/actionpack/test/abstract_controller/abstract_controller_test.rb
@@ -19,8 +19,9 @@ module AbstractController
class TestBasic < ActiveSupport::TestCase
test "dispatching works" do
- result = Me.new.process(:index)
- assert_equal "Hello world", result.response_body
+ controller = Me.new
+ controller.process(:index)
+ assert_equal "Hello world", controller.response_body
end
end
@@ -67,29 +68,33 @@ module AbstractController
end
class TestRenderingController < ActiveSupport::TestCase
+ def setup
+ @controller = Me2.new
+ end
+
test "rendering templates works" do
- result = Me2.new.process(:index)
- assert_equal "Hello from index.erb", result.response_body
+ @controller.process(:index)
+ assert_equal "Hello from index.erb", @controller.response_body
end
test "rendering passes ivars to the view" do
- result = Me2.new.process(:action_with_ivars)
- assert_equal "Hello from index_with_ivars.erb", result.response_body
+ @controller.process(:action_with_ivars)
+ assert_equal "Hello from index_with_ivars.erb", @controller.response_body
end
test "rendering with no template name" do
- result = Me2.new.process(:naked_render)
- assert_equal "Hello from naked_render.erb", result.response_body
+ @controller.process(:naked_render)
+ assert_equal "Hello from naked_render.erb", @controller.response_body
end
test "rendering to a rack body" do
- result = Me2.new.process(:rendering_to_body)
- assert_equal "Hello from naked_render.erb", result.response_body
+ @controller.process(:rendering_to_body)
+ assert_equal "Hello from naked_render.erb", @controller.response_body
end
test "rendering to a string" do
- result = Me2.new.process(:rendering_to_string)
- assert_equal "Hello from naked_render.erb", result.response_body
+ @controller.process(:rendering_to_string)
+ assert_equal "Hello from naked_render.erb", @controller.response_body
end
end
@@ -119,14 +124,18 @@ module AbstractController
end
class TestPrefixedViews < ActiveSupport::TestCase
+ def setup
+ @controller = Me3.new
+ end
+
test "templates are located inside their 'prefix' folder" do
- result = Me3.new.process(:index)
- assert_equal "Hello from me3/index.erb", result.response_body
+ @controller.process(:index)
+ assert_equal "Hello from me3/index.erb", @controller.response_body
end
test "templates included their format" do
- result = Me3.new.process(:formatted)
- assert_equal "Hello from me3/formatted.html.erb", result.response_body
+ @controller.process(:formatted)
+ assert_equal "Hello from me3/formatted.html.erb", @controller.response_body
end
end
@@ -168,8 +177,9 @@ module AbstractController
class TestLayouts < ActiveSupport::TestCase
test "layouts are included" do
- result = Me4.new.process(:index)
- assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", result.response_body
+ controller = Me4.new
+ result = controller.process(:index)
+ assert_equal "Me4 Enter : Hello from me4/index.erb : Exit", controller.response_body
end
end
@@ -203,10 +213,11 @@ module AbstractController
end
class TestRespondToAction < ActiveSupport::TestCase
-
+
def assert_dispatch(klass, body = "success", action = :index)
- response = klass.new.process(action).response_body
- assert_equal body, response
+ controller = klass.new
+ controller.process(action)
+ assert_equal body, controller.response_body
end
test "an arbitrary method is available as an action by default" do
diff --git a/actionpack/test/abstract_controller/callbacks_test.rb b/actionpack/test/abstract_controller/callbacks_test.rb
index 817f60f7d1..8f62adce8c 100644
--- a/actionpack/test/abstract_controller/callbacks_test.rb
+++ b/actionpack/test/abstract_controller/callbacks_test.rb
@@ -19,10 +19,11 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacks1 < ActiveSupport::TestCase
test "basic callbacks work" do
- result = Callback1.new.process(:index)
- assert_equal "Hello world", result.response_body
+ controller = Callback1.new
+ result = controller.process(:index)
+ assert_equal "Hello world", controller.response_body
end
end
@@ -50,20 +51,24 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacks2 < ActiveSupport::TestCase
+ def setup
+ @controller = Callback2.new
+ end
+
test "before_filter works" do
- result = Callback2.new.process(:index)
- assert_equal "Hello world", result.response_body
+ result = @controller.process(:index)
+ assert_equal "Hello world", @controller.response_body
end
test "after_filter works" do
- result = Callback2.new.process(:index)
- assert_equal "Goodbye", result.instance_variable_get("@second")
+ @controller.process(:index)
+ assert_equal "Goodbye", @controller.instance_variable_get("@second")
end
test "around_filter works" do
- result = Callback2.new.process(:index)
- assert_equal "FIRSTSECOND", result.instance_variable_get("@aroundz")
+ @controller.process(:index)
+ assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz")
end
end
@@ -81,15 +86,19 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacks3 < ActiveSupport::TestCase
+ def setup
+ @controller = Callback3.new
+ end
+
test "before_filter works with procs" do
- result = Callback3.new.process(:index)
- assert_equal "Hello world", result.response_body
+ result = @controller.process(:index)
+ assert_equal "Hello world", @controller.response_body
end
test "after_filter works with procs" do
- result = Callback3.new.process(:index)
- assert_equal "Goodbye", result.instance_variable_get("@second")
+ result = @controller.process(:index)
+ assert_equal "Goodbye", @controller.instance_variable_get("@second")
end
end
@@ -116,20 +125,24 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacksWithConditions < ActiveSupport::TestCase
+ def setup
+ @controller = CallbacksWithConditions.new
+ end
+
test "when :only is specified, a before filter is triggered on that action" do
- result = CallbacksWithConditions.new.process(:index)
- assert_equal "Hello, World", result.response_body
+ @controller.process(:index)
+ assert_equal "Hello, World", @controller.response_body
end
test "when :only is specified, a before filter is not triggered on other actions" do
- result = CallbacksWithConditions.new.process(:sekrit_data)
- assert_equal "true", result.response_body
+ @controller.process(:sekrit_data)
+ assert_equal "true", @controller.response_body
end
test "when :except is specified, an after filter is not triggered on that action" do
- result = CallbacksWithConditions.new.process(:index)
- assert_nil result.instance_variable_get("@authenticated")
+ result = @controller.process(:index)
+ assert_nil @controller.instance_variable_get("@authenticated")
end
end
@@ -156,20 +169,24 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacksWithArrayConditions < ActiveSupport::TestCase
+ def setup
+ @controller = CallbacksWithArrayConditions.new
+ end
+
test "when :only is specified with an array, a before filter is triggered on that action" do
- result = CallbacksWithArrayConditions.new.process(:index)
- assert_equal "Hello, World", result.response_body
+ result = @controller.process(:index)
+ assert_equal "Hello, World", @controller.response_body
end
test "when :only is specified with an array, a before filter is not triggered on other actions" do
- result = CallbacksWithArrayConditions.new.process(:sekrit_data)
- assert_equal "true", result.response_body
+ result = @controller.process(:sekrit_data)
+ assert_equal "true", @controller.response_body
end
test "when :except is specified with an array, an after filter is not triggered on that action" do
- result = CallbacksWithArrayConditions.new.process(:index)
- assert_nil result.instance_variable_get("@authenticated")
+ result = @controller.process(:index)
+ assert_nil @controller.instance_variable_get("@authenticated")
end
end
@@ -181,15 +198,19 @@ module AbstractController
end
end
- class TestCallbacks < ActiveSupport::TestCase
+ class TestCallbacksWithChangedConditions < ActiveSupport::TestCase
+ def setup
+ @controller = ChangedConditions.new
+ end
+
test "when a callback is modified in a child with :only, it works for the :only action" do
- result = ChangedConditions.new.process(:index)
- assert_equal "Hello world", result.response_body
+ result = @controller.process(:index)
+ assert_equal "Hello world", @controller.response_body
end
test "when a callback is modified in a child with :only, it does not work for other actions" do
- result = ChangedConditions.new.process(:not_index)
- assert_equal "", result.response_body
+ result = @controller.process(:not_index)
+ assert_equal "", @controller.response_body
end
end
@@ -207,8 +228,9 @@ module AbstractController
class TestHalting < ActiveSupport::TestCase
test "when a callback sets the response body, the action should not be invoked" do
- result = SetsResponseBody.new.process(:index)
- assert_equal "Success", result.response_body
+ controller = SetsResponseBody.new
+ controller.process(:index)
+ assert_equal "Success", controller.response_body
end
end
diff --git a/actionpack/test/abstract_controller/helper_test.rb b/actionpack/test/abstract_controller/helper_test.rb
index e9a60c0307..34a10cecc9 100644
--- a/actionpack/test/abstract_controller/helper_test.rb
+++ b/actionpack/test/abstract_controller/helper_test.rb
@@ -34,8 +34,9 @@ module AbstractController
class TestHelpers < ActiveSupport::TestCase
def test_helpers
- result = MyHelpers1.new.process(:index)
- assert_equal "Hello World : Included", result.response_body
+ controller = MyHelpers1.new
+ controller.process(:index)
+ assert_equal "Hello World : Included", controller.response_body
end
end
diff --git a/actionpack/test/abstract_controller/layouts_test.rb b/actionpack/test/abstract_controller/layouts_test.rb
index 42f73faa61..995aac7fad 100644
--- a/actionpack/test/abstract_controller/layouts_test.rb
+++ b/actionpack/test/abstract_controller/layouts_test.rb
@@ -143,13 +143,15 @@ module AbstractControllerTests
class TestBase < ActiveSupport::TestCase
test "when no layout is specified, and no default is available, render without a layout" do
- result = Blank.new.process(:index)
- assert_equal "Hello blank!", result.response_body
+ controller = Blank.new
+ controller.process(:index)
+ assert_equal "Hello blank!", controller.response_body
end
test "when layout is specified as a string, render with that layout" do
- result = WithString.new.process(:index)
- assert_equal "With String Hello string!", result.response_body
+ controller = WithString.new
+ controller.process(:index)
+ assert_equal "With String Hello string!", controller.response_body
end
test "when layout is specified as a string, but the layout is missing, raise an exception" do
@@ -157,23 +159,27 @@ module AbstractControllerTests
end
test "when layout is specified as false, do not use a layout" do
- result = WithFalseLayout.new.process(:index)
- assert_equal "Hello false!", result.response_body
+ controller = WithFalseLayout.new
+ controller.process(:index)
+ assert_equal "Hello false!", controller.response_body
end
test "when layout is specified as nil, do not use a layout" do
- result = WithNilLayout.new.process(:index)
- assert_equal "Hello nil!", result.response_body
+ controller = WithNilLayout.new
+ controller.process(:index)
+ assert_equal "Hello nil!", controller.response_body
end
test "when layout is specified as a symbol, call the requested method and use the layout returned" do
- result = WithSymbol.new.process(:index)
- assert_equal "OMGHI2U Hello symbol!", result.response_body
+ controller = WithSymbol.new
+ controller.process(:index)
+ assert_equal "OMGHI2U Hello symbol!", controller.response_body
end
test "when layout is specified as a symbol and the method returns nil, don't use a layout" do
- result = WithSymbolReturningNil.new.process(:index)
- assert_equal "Hello nilz!", result.response_body
+ controller = WithSymbolReturningNil.new
+ controller.process(:index)
+ assert_equal "Hello nilz!", controller.response_body
end
test "when the layout is specified as a symbol and the method doesn't exist, raise an exception" do
@@ -185,29 +191,34 @@ module AbstractControllerTests
end
test "when a child controller does not have a layout, use the parent controller layout" do
- result = WithStringChild.new.process(:index)
- assert_equal "With String Hello string!", result.response_body
+ controller = WithStringChild.new
+ controller.process(:index)
+ assert_equal "With String Hello string!", controller.response_body
end
test "when a child controller has specified a layout, use that layout and not the parent controller layout" do
- result = WithStringOverriddenChild.new.process(:index)
- assert_equal "With Override Hello string!", result.response_body
+ controller = WithStringOverriddenChild.new
+ controller.process(:index)
+ assert_equal "With Override Hello string!", controller.response_body
end
test "when a child controller has an implied layout, use that layout and not the parent controller layout" do
- result = WithStringImpliedChild.new.process(:index)
- assert_equal "With Implied Hello string!", result.response_body
+ controller = WithStringImpliedChild.new
+ controller.process(:index)
+ assert_equal "With Implied Hello string!", controller.response_body
end
test "when a child controller specifies layout nil, do not use the parent layout" do
- result = WithNilChild.new.process(:index)
- assert_equal "Hello string!", result.response_body
+ controller = WithNilChild.new
+ controller.process(:index)
+ assert_equal "Hello string!", controller.response_body
end
test "when a grandchild has no layout specified, the child has an implied layout, and the " \
"parent has specified a layout, use the child controller layout" do
- result = WithChildOfImplied.new.process(:index)
- assert_equal "With Implied Hello string!", result.response_body
+ controller = WithChildOfImplied.new
+ controller.process(:index)
+ assert_equal "With Implied Hello string!", controller.response_body
end
test "raises an exception when specifying layout true" do
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index a21b00915e..07ba37c51c 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -62,8 +62,20 @@ module ActionController
}
Base.session_store = nil
+ class << Routing
+ def possible_controllers
+ @@possible_controllers ||= []
+ end
+ end
+
class Base
include ActionController::Testing
+
+ def self.inherited(klass)
+ name = klass.name.underscore.sub(/_controller$/, '')
+ ActionController::Routing.possible_controllers << name unless name.blank?
+ super
+ end
end
Base.view_paths = FIXTURE_LOAD_PATH
diff --git a/actionpack/test/activerecord/active_record_store_test.rb b/actionpack/test/activerecord/active_record_store_test.rb
index 47f8496181..a46ce7a0aa 100644
--- a/actionpack/test/activerecord/active_record_store_test.rb
+++ b/actionpack/test/activerecord/active_record_store_test.rb
@@ -1,12 +1,6 @@
require 'active_record_unit'
class ActiveRecordStoreTest < ActionController::IntegrationTest
- DispatcherApp = ActionController::Dispatcher.new
- SessionApp = ActiveRecord::SessionStore.new(DispatcherApp,
- :key => '_session_id')
- SessionAppWithFixation = ActiveRecord::SessionStore.new(DispatcherApp,
- :key => '_session_id', :cookie_only => false)
-
class TestController < ActionController::Base
def no_session_access
head :ok
@@ -39,7 +33,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
def setup
ActiveRecord::SessionStore.session_class.create_table!
- @integration_session = open_session(SessionApp)
+ reset_app!
end
def teardown
@@ -138,9 +132,9 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
end
def test_allows_session_fixation
- @integration_session = open_session(SessionAppWithFixation)
-
with_test_route_set do
+ reset_with_fixation!
+
get '/set_session_value'
assert_response :success
assert cookies['_session_id']
@@ -151,8 +145,7 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
session_id = cookies['_session_id']
assert session_id
- reset!
- @integration_session = open_session(SessionAppWithFixation)
+ reset_with_fixation!
get '/set_session_value', :_session_id => session_id, :foo => "baz"
assert_response :success
@@ -166,6 +159,16 @@ class ActiveRecordStoreTest < ActionController::IntegrationTest
end
private
+ def reset_app!
+ app = ActiveRecord::SessionStore.new(ActionController::Dispatcher.new, :key => '_session_id')
+ @integration_session = open_session(app)
+ end
+
+ def reset_with_fixation!
+ app = ActiveRecord::SessionStore.new(ActionController::Dispatcher.new, :key => '_session_id', :cookie_only => false)
+ @integration_session = open_session(app)
+ end
+
def with_test_route_set
with_routing do |set|
set.draw do |map|
diff --git a/actionpack/test/controller/action_pack_assertions_test.rb b/actionpack/test/controller/action_pack_assertions_test.rb
index 06827e5fbc..453812c128 100644
--- a/actionpack/test/controller/action_pack_assertions_test.rb
+++ b/actionpack/test/controller/action_pack_assertions_test.rb
@@ -182,14 +182,6 @@ end
# a test case to exercise the new capabilities TestRequest & TestResponse
class ActionPackAssertionsControllerTest < ActionController::TestCase
- # let's get this party started
- def setup
- super
-
- ActionController::Routing.use_controllers!(%w(action_pack_assertions admin/inner_module user content admin/user))
- ActionController::Routing::Routes.load_routes!
- end
-
# -- assertion-based testing ------------------------------------------------
def test_assert_tag_and_url_for
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 5be780dd42..d20684296f 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -44,11 +44,11 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
end
def test_route_recognition_unescapes_path_components
- options = { :controller => "controller",
+ options = { :controller => "content",
:action => "act#{@segment}ion",
:variable => "var#{@segment}iable",
:additional => ["add#{@segment}itional-1", "add#{@segment}itional-2"] }
- assert_equal options, @set.recognize_path("/controller/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
+ assert_equal options, @set.recognize_path("/content/act#{@escaped}ion/var#{@escaped}iable/add#{@escaped}itional-1/add#{@escaped}itional-2")
end
def test_route_generation_allows_passing_non_string_values_to_generated_helper
@@ -60,58 +60,6 @@ class UriReservedCharactersRoutingTest < Test::Unit::TestCase
end
class RoutingTest < Test::Unit::TestCase
- def test_possible_controllers
- true_controller_paths = ActionController::Routing.controller_paths
-
- ActionController::Routing.use_controllers! nil
-
- Object.send(:remove_const, :RAILS_ROOT) if defined?(::RAILS_ROOT)
- Object.const_set(:RAILS_ROOT, File.dirname(__FILE__) + '/controller_fixtures')
-
- ActionController::Routing.controller_paths = [
- RAILS_ROOT, RAILS_ROOT + '/app/controllers', RAILS_ROOT + '/vendor/plugins/bad_plugin/lib'
- ]
-
- assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort
- ensure
- if true_controller_paths
- ActionController::Routing.controller_paths = true_controller_paths
- end
- ActionController::Routing.use_controllers! nil
- Object.send(:remove_const, :RAILS_ROOT) rescue nil
- end
-
- def test_possible_controllers_are_reset_on_each_load
- true_possible_controllers = ActionController::Routing.possible_controllers
- true_controller_paths = ActionController::Routing.controller_paths
-
- ActionController::Routing.use_controllers! nil
- root = File.dirname(__FILE__) + '/controller_fixtures'
-
- ActionController::Routing.controller_paths = []
- assert_equal [], ActionController::Routing.possible_controllers
-
- ActionController::Routing.controller_paths = [
- root, root + '/app/controllers', root + '/vendor/plugins/bad_plugin/lib'
- ]
- ActionController::Routing::Routes.load!
-
- assert_equal ["admin/user", "plugin", "user"], ActionController::Routing.possible_controllers.sort
- ensure
- ActionController::Routing.controller_paths = true_controller_paths
- ActionController::Routing.use_controllers! true_possible_controllers
- Object.send(:remove_const, :RAILS_ROOT) rescue nil
-
- ActionController::Routing::Routes.reload!
- end
-
- def test_with_controllers
- c = %w(admin/accounts admin/users account pages)
- ActionController::Routing.with_controllers c do
- assert_equal c, ActionController::Routing.possible_controllers
- end
- end
-
def test_normalize_unix_paths
load_paths = %w(. config/../app/controllers config/../app//helpers script/../config/../vendor/rails/actionpack/lib vendor/rails/railties/builtin/rails_info app/models lib script/../config/../foo/bar/../../app/models .foo/../.bar foo.bar/../config)
paths = ActionController::Routing.normalize_paths(load_paths)
@@ -1815,22 +1763,20 @@ class RouteSetTest < ActiveSupport::TestCase
end
def test_slashes_are_implied
- ActionController::Routing.with_controllers(['foo']) do
- ['/:controller/:action/:id/', '/:controller/:action/:id',
- ':controller/:action/:id', '/:controller/:action/:id/'
- ].each do |path|
- @set = nil
- set.draw { |map| map.connect(path) }
-
- assert_equal '/foo', set.generate(:controller => 'foo', :action => 'index')
- assert_equal '/foo/list', set.generate(:controller => 'foo', :action => 'list')
- assert_equal '/foo/show/1', set.generate(:controller => 'foo', :action => 'show', :id => '1')
-
- assert_equal({:controller => "foo", :action => "index"}, set.recognize_path('/foo'))
- assert_equal({:controller => "foo", :action => "index"}, set.recognize_path('/foo/index'))
- assert_equal({:controller => "foo", :action => "list"}, set.recognize_path('/foo/list'))
- assert_equal({:controller => "foo", :action => "show", :id => "1"}, set.recognize_path('/foo/show/1'))
- end
+ ['/:controller/:action/:id/', '/:controller/:action/:id',
+ ':controller/:action/:id', '/:controller/:action/:id/'
+ ].each do |path|
+ @set = nil
+ set.draw { |map| map.connect(path) }
+
+ assert_equal '/content', set.generate(:controller => 'content', :action => 'index')
+ assert_equal '/content/list', set.generate(:controller => 'content', :action => 'list')
+ assert_equal '/content/show/1', set.generate(:controller => 'content', :action => 'show', :id => '1')
+
+ assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content'))
+ assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content/index'))
+ assert_equal({:controller => "content", :action => "list"}, set.recognize_path('/content/list'))
+ assert_equal({:controller => "content", :action => "show", :id => "1"}, set.recognize_path('/content/show/1'))
end
end
diff --git a/actionpack/test/controller/test_test.rb b/actionpack/test/controller/test_test.rb
index 84c97851ee..73870a56bb 100644
--- a/actionpack/test/controller/test_test.rb
+++ b/actionpack/test/controller/test_test.rb
@@ -123,9 +123,6 @@ XML
@controller = TestController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
-
- ActionController::Routing.use_controllers! %w(content admin/user test_test/test)
- ActionController::Routing::Routes.load_routes!
end
def test_raw_post_handling
diff --git a/actionpack/test/controller/url_rewriter_test.rb b/actionpack/test/controller/url_rewriter_test.rb
index ad915e7a57..9b8d07222b 100644
--- a/actionpack/test/controller/url_rewriter_test.rb
+++ b/actionpack/test/controller/url_rewriter_test.rb
@@ -46,6 +46,20 @@ class UrlRewriterTests < ActionController::TestCase
)
end
+ def test_anchor_should_call_to_param
+ assert_equal(
+ 'http://test.host/c/a/i#anchor',
+ @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anchor'))
+ )
+ end
+
+ def test_anchor_should_be_cgi_escaped
+ assert_equal(
+ 'http://test.host/c/a/i#anc%2Fhor',
+ @rewriter.rewrite(:controller => 'c', :action => 'a', :id => 'i', :anchor => Struct.new(:to_param).new('anc/hor'))
+ )
+ end
+
def test_overwrite_params
@params[:controller] = 'hi'
@params[:action] = 'bye'
@@ -110,6 +124,18 @@ class UrlWriterTests < ActionController::TestCase
)
end
+ def test_anchor_should_call_to_param
+ assert_equal('/c/a#anchor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anchor'))
+ )
+ end
+
+ def test_anchor_should_be_cgi_escaped
+ assert_equal('/c/a#anc%2Fhor',
+ W.new.url_for(:only_path => true, :controller => 'c', :action => 'a', :anchor => Struct.new(:to_param).new('anc/hor'))
+ )
+ end
+
def test_default_host
add_host!
assert_equal('http://www.basecamphq.com/c/a/i',
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb
index 3fded34d78..916124e221 100644
--- a/actionpack/test/controller/webservice_test.rb
+++ b/actionpack/test/controller/webservice_test.rb
@@ -259,6 +259,7 @@ class WebServiceTest < ActionController::IntegrationTest
c.connect "/", :action => "assign_parameters"
end
end
+ reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb
index db6cf7b330..995f36bb29 100644
--- a/actionpack/test/dispatch/request/json_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb
@@ -59,6 +59,7 @@ class JsonParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "json_params_parsing_test/test"
end
+ reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
index 301080842e..d4ee4362eb 100644
--- a/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/multipart_params_parsing_test.rb
@@ -153,6 +153,7 @@ class MultipartParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "multipart_params_parsing_test/test"
end
+ reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/query_string_parsing_test.rb b/actionpack/test/dispatch/request/query_string_parsing_test.rb
index a31e326ddf..2261934e45 100644
--- a/actionpack/test/dispatch/request/query_string_parsing_test.rb
+++ b/actionpack/test/dispatch/request/query_string_parsing_test.rb
@@ -111,6 +111,7 @@ class QueryStringParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "query_string_parsing_test/test"
end
+ reset!
get "/parse", actual
assert_response :ok
diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
index 7167cdafac..6c9967d26e 100644
--- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb
@@ -132,6 +132,7 @@ class UrlEncodedParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "url_encoded_params_parsing_test/test"
end
+ reset!
yield
end
end
diff --git a/actionpack/test/dispatch/request/xml_params_parsing_test.rb b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
index 521002b519..2f2dd695c4 100644
--- a/actionpack/test/dispatch/request/xml_params_parsing_test.rb
+++ b/actionpack/test/dispatch/request/xml_params_parsing_test.rb
@@ -86,6 +86,7 @@ class XmlParamsParsingTest < ActionController::IntegrationTest
set.draw do |map|
map.connect ':action', :controller => "xml_params_parsing_test/test"
end
+ reset!
yield
end
end
diff --git a/actionpack/test/dispatch/session/cookie_store_test.rb b/actionpack/test/dispatch/session/cookie_store_test.rb
index 2db76818ac..0723a76d2b 100644
--- a/actionpack/test/dispatch/session/cookie_store_test.rb
+++ b/actionpack/test/dispatch/session/cookie_store_test.rb
@@ -8,10 +8,6 @@ class CookieStoreTest < ActionController::IntegrationTest
# Make sure Session middleware doesnt get included in the middleware stack
ActionController::Base.session_store = nil
- DispatcherApp = ActionController::Dispatcher.new
- CookieStoreApp = ActionDispatch::Session::CookieStore.new(DispatcherApp,
- :key => SessionKey, :secret => SessionSecret)
-
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16))
@@ -51,7 +47,7 @@ class CookieStoreTest < ActionController::IntegrationTest
end
def setup
- @integration_session = open_session(CookieStoreApp)
+ reset_app!
end
def test_raises_argument_error_if_missing_session_key
@@ -197,10 +193,10 @@ class CookieStoreTest < ActionController::IntegrationTest
end
def test_session_store_with_expire_after
- app = ActionDispatch::Session::CookieStore.new(DispatcherApp, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
- @integration_session = open_session(app)
-
with_test_route_set do
+ app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new, :key => SessionKey, :secret => SessionSecret, :expire_after => 5.hours)
+ @integration_session = open_session(app)
+
# First request accesses the session
time = Time.local(2008, 4, 24)
Time.stubs(:now).returns(time)
@@ -230,6 +226,12 @@ class CookieStoreTest < ActionController::IntegrationTest
end
private
+ def reset_app!
+ app = ActionDispatch::Session::CookieStore.new(ActionController::Dispatcher.new,
+ :key => SessionKey, :secret => SessionSecret)
+ @integration_session = open_session(app)
+ end
+
def with_test_route_set
with_routing do |set|
set.draw do |map|
@@ -237,6 +239,7 @@ class CookieStoreTest < ActionController::IntegrationTest
c.connect "/:action"
end
end
+ reset_app!
yield
end
end
diff --git a/actionpack/test/dispatch/session/mem_cache_store_test.rb b/actionpack/test/dispatch/session/mem_cache_store_test.rb
index 7561c93e4a..1588918be7 100644
--- a/actionpack/test/dispatch/session/mem_cache_store_test.rb
+++ b/actionpack/test/dispatch/session/mem_cache_store_test.rb
@@ -32,14 +32,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end
begin
- DispatcherApp = ActionController::Dispatcher.new
- MemCacheStoreApp = ActionDispatch::Session::MemCacheStore.new(
- DispatcherApp, :key => '_session_id')
-
-
- def setup
- @integration_session = open_session(MemCacheStoreApp)
- end
+ App = ActionDispatch::Session::MemCacheStore.new(ActionController::Dispatcher.new, :key => '_session_id')
def test_setting_and_getting_session_value
with_test_route_set do
@@ -114,6 +107,12 @@ class MemCacheStoreTest < ActionController::IntegrationTest
end
private
+ def reset_app!
+ app = ActionDispatch::Session::MemCacheStore.new(
+ ActionController::Dispatcher.new, :key => '_session_id')
+ @integration_session = open_session(app)
+ end
+
def with_test_route_set
with_routing do |set|
set.draw do |map|
@@ -121,6 +120,7 @@ class MemCacheStoreTest < ActionController::IntegrationTest
c.connect "/:action"
end
end
+ reset_app!
yield
end
end
diff --git a/actionpack/test/lib/controller/fake_controllers.rb b/actionpack/test/lib/controller/fake_controllers.rb
index 75c114c103..6e02e2d21b 100644
--- a/actionpack/test/lib/controller/fake_controllers.rb
+++ b/actionpack/test/lib/controller/fake_controllers.rb
@@ -1,15 +1,16 @@
class << Object; alias_method :const_available?, :const_defined?; end
-
-class ContentController < Class.new(ActionController::Base)
+
+class ContentController < ActionController::Base
end
class NotAController
end
module Admin
class << self; alias_method :const_available?, :const_defined?; end
- class UserController < Class.new(ActionController::Base); end
- class NewsFeedController < Class.new(ActionController::Base); end
+ class UserController < ActionController::Base; end
+ class NewsFeedController < ActionController::Base; end
end
+
# For speed test
class SpeedController < ActionController::Base; end
class SearchController < SpeedController; end
diff --git a/actionpack/test/new_base/metal_test.rb b/actionpack/test/new_base/metal_test.rb
index c7c45b5cc9..2b7720863a 100644
--- a/actionpack/test/new_base/metal_test.rb
+++ b/actionpack/test/new_base/metal_test.rb
@@ -1,13 +1,12 @@
require File.join(File.expand_path(File.dirname(__FILE__)), "test_helper")
module MetalTest
- class MetalMiddleware < ActionController::Metal
- def index
+ class MetalMiddleware < ActionController::Middleware
+ def call(env)
if env["PATH_INFO"] =~ /authed/
- self.response = app.call(env)
+ app.call(env)
else
- self.response_body = "Not authed!"
- self.status = 401
+ [401, headers, "Not authed!"]
end
end
end
@@ -21,7 +20,7 @@ module MetalTest
class TestMiddleware < ActiveSupport::TestCase
def setup
@app = Rack::Builder.new do
- use MetalMiddleware.middleware(:index)
+ use MetalMiddleware
run Endpoint.new
end.to_app
end
diff --git a/actionpack/test/new_base/test_helper.rb b/actionpack/test/new_base/test_helper.rb
index 9271b2dd59..b7ccd3db8d 100644
--- a/actionpack/test/new_base/test_helper.rb
+++ b/actionpack/test/new_base/test_helper.rb
@@ -35,12 +35,6 @@ class Rack::TestCase < ActionController::IntegrationTest
setup do
ActionController::Base.session_options[:key] = "abc"
ActionController::Base.session_options[:secret] = ("*" * 30)
-
- controllers = ActionController::Base.subclasses.map do |k|
- k.underscore.sub(/_controller$/, '')
- end
-
- ActionController::Routing.use_controllers!(controllers)
end
def app
@@ -91,10 +85,26 @@ end
class ::ApplicationController < ActionController::Base
end
+module ActionController
+ class << Routing
+ def possible_controllers
+ @@possible_controllers ||= []
+ end
+ end
+
+ class Base
+ def self.inherited(klass)
+ name = klass.name.underscore.sub(/_controller$/, '')
+ ActionController::Routing.possible_controllers << name unless name.blank?
+ super
+ end
+ end
+end
+
class SimpleRouteCase < Rack::TestCase
setup do
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
end
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/form_options_helper_i18n_test.rb b/actionpack/test/template/form_options_helper_i18n_test.rb
new file mode 100644
index 0000000000..91e370efa7
--- /dev/null
+++ b/actionpack/test/template/form_options_helper_i18n_test.rb
@@ -0,0 +1,27 @@
+require 'abstract_unit'
+
+class FormOptionsHelperI18nTests < ActionView::TestCase
+ tests ActionView::Helpers::FormOptionsHelper
+
+ def setup
+ @prompt_message = 'Select!'
+ I18n.backend.send(:init_translations)
+ I18n.backend.store_translations :en, :support => { :select => { :prompt => @prompt_message } }
+ end
+
+ def teardown
+ I18n.backend = I18n::Backend::Simple.new
+ end
+
+ def test_select_with_prompt_true_translates_prompt_message
+ I18n.expects(:translate).with('support.select.prompt', { :default => 'Please select' })
+ select('post', 'category', [], :prompt => true)
+ end
+
+ def test_select_with_translated_prompt
+ assert_dom_equal(
+ %Q(<select id="post_category" name="post[category]"><option value="">#{@prompt_message}</option>\n</select>),
+ select('post', 'category', [], :prompt => true)
+ )
+ end
+end \ No newline at end of file