aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2008-04-20 15:30:41 -0700
commit3b93ca221d3a1b777bd880c18f52010cbd56c18c (patch)
tree7b49713994125de123775102eac2655d7b29b231 /actionpack/test
parentdaab53d8c0bca1114c1485d0dcc52858a264ab9e (diff)
parent46ab7422d9ebac0d529f71a3a7c2feaf0b9d5dbd (diff)
downloadrails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.gz
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.tar.bz2
rails-3b93ca221d3a1b777bd880c18f52010cbd56c18c.zip
Merge commit 'rails/master'
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/abstract_unit.rb2
-rw-r--r--actionpack/test/controller/caching_test.rb9
-rw-r--r--actionpack/test/controller/cookie_test.rb2
-rw-r--r--actionpack/test/controller/custom_handler_test.rb6
-rw-r--r--actionpack/test/controller/dispatcher_test.rb64
-rw-r--r--actionpack/test/controller/flash_test.rb2
-rw-r--r--actionpack/test/controller/layout_test.rb2
-rw-r--r--actionpack/test/controller/mime_responds_test.rb2
-rw-r--r--actionpack/test/controller/new_render_test.rb4
-rw-r--r--actionpack/test/controller/rescue_test.rb26
-rw-r--r--actionpack/test/fixtures/public/javascripts/version.1.0.js1
-rw-r--r--actionpack/test/fixtures/public/stylesheets/version.1.0.css1
-rw-r--r--actionpack/test/template/active_record_helper_test.rb9
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb28
-rw-r--r--actionpack/test/template/benchmark_helper_test.rb4
-rwxr-xr-xactionpack/test/template/date_helper_test.rb5
-rw-r--r--actionpack/test/template/form_helper_test.rb11
-rw-r--r--actionpack/test/template/form_options_helper_test.rb5
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb8
-rw-r--r--actionpack/test/template/javascript_helper_test.rb10
-rw-r--r--actionpack/test/template/number_helper_test.rb4
-rw-r--r--actionpack/test/template/prototype_helper_test.rb56
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb11
-rw-r--r--actionpack/test/template/sanitize_helper_test.rb5
-rw-r--r--actionpack/test/template/scriptaculous_helper_test.rb14
-rw-r--r--actionpack/test/template/tag_helper_test.rb7
-rw-r--r--actionpack/test/template/template_object_test.rb2
-rw-r--r--actionpack/test/template/test_test.rb56
-rw-r--r--actionpack/test/template/text_helper_test.rb5
-rw-r--r--actionpack/test/template/url_helper_test.rb18
30 files changed, 188 insertions, 191 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 700bc1f5e3..fa1c3293b4 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -8,6 +8,7 @@ require 'test/unit'
require 'action_controller'
require 'action_controller/cgi_ext'
require 'action_controller/test_process'
+require 'action_view/test_case'
begin
require 'ruby-debug'
@@ -19,7 +20,6 @@ end
ActiveSupport::Deprecation.debug = true
ActionController::Base.logger = nil
-ActionController::Base.ignore_missing_templates = false
ActionController::Routing::Routes.reload rescue nil
diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb
index 7bd64e2870..ddc1c68383 100644
--- a/actionpack/test/controller/caching_test.rb
+++ b/actionpack/test/controller/caching_test.rb
@@ -8,7 +8,8 @@ ActionController::Base.page_cache_directory = FILE_STORE_PATH
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
class PageCachingTestController < ActionController::Base
- caches_page :ok, :no_content, :found, :not_found
+ caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
+ caches_page :found, :not_found
def ok
head :ok
@@ -127,6 +128,12 @@ class PageCachingTest < Test::Unit::TestCase
end
end
end
+
+ def test_page_caching_conditional_options
+ @request.env['HTTP_ACCEPT'] = 'application/json'
+ get :ok
+ assert_page_not_cached :ok
+ end
private
def assert_page_cached(action, message = "#{action} should have been cached")
diff --git a/actionpack/test/controller/cookie_test.rb b/actionpack/test/controller/cookie_test.rb
index 0483fe918a..42f3bd26a4 100644
--- a/actionpack/test/controller/cookie_test.rb
+++ b/actionpack/test/controller/cookie_test.rb
@@ -37,7 +37,7 @@ class CookieTest < Test::Unit::TestCase
end
def rescue_action(e)
- raise unless ActionController::MissingTemplate # No templates here, and we don't care about the output
+ raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
end
end
diff --git a/actionpack/test/controller/custom_handler_test.rb b/actionpack/test/controller/custom_handler_test.rb
index cf1e2361bd..ac484ae17e 100644
--- a/actionpack/test/controller/custom_handler_test.rb
+++ b/actionpack/test/controller/custom_handler_test.rb
@@ -20,7 +20,7 @@ class CustomHandlerTest < Test::Unit::TestCase
end
def test_custom_render
- template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo")
+ template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo")
result = @view.render_template(template)
assert_equal(
@@ -29,7 +29,7 @@ class CustomHandlerTest < Test::Unit::TestCase
end
def test_custom_render2
- template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "foo2")
+ template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "foo2")
result = @view.render_template(template)
assert_equal(
[ "hello <%= one %>", { :one => "two" }, @view ],
@@ -38,7 +38,7 @@ class CustomHandlerTest < Test::Unit::TestCase
def test_unhandled_extension
# uses the ERb handler by default if the extension isn't recognized
- template = ActionView::Template.new(@view, "hello <%= one %>", false, { :one => "two" }, true, "bar")
+ template = ActionView::InlineTemplate.new(@view, "hello <%= one %>", { :one => "two" }, "bar")
result = @view.render_template(template)
assert_equal "hello two", result
end
diff --git a/actionpack/test/controller/dispatcher_test.rb b/actionpack/test/controller/dispatcher_test.rb
index 9f90872734..eea0813ed5 100644
--- a/actionpack/test/controller/dispatcher_test.rb
+++ b/actionpack/test/controller/dispatcher_test.rb
@@ -11,7 +11,13 @@ class DispatcherTest < Test::Unit::TestCase
@output = StringIO.new
ENV['REQUEST_METHOD'] = 'GET'
+ # Clear callbacks as they are redefined by Dispatcher#define_dispatcher_callbacks
Dispatcher.instance_variable_set("@prepare_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Dispatcher.instance_variable_set("@before_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+ Dispatcher.instance_variable_set("@after_dispatch_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
+
+ Dispatcher.stubs(:require_dependency)
+
@dispatcher = Dispatcher.new(@output)
end
@@ -20,68 +26,52 @@ class DispatcherTest < Test::Unit::TestCase
end
def test_clears_dependencies_after_dispatch_if_in_loading_mode
- Dependencies.stubs(:load?).returns(true)
-
ActionController::Routing::Routes.expects(:reload).once
Dependencies.expects(:clear).once
- dispatch
+ dispatch(@output, false)
end
def test_leaves_dependencies_after_dispatch_if_not_in_loading_mode
- Dependencies.stubs(:load?).returns(false)
-
ActionController::Routing::Routes.expects(:reload).never
Dependencies.expects(:clear).never
dispatch
end
+ # Stub out dispatch error logger
+ class << Dispatcher
+ def log_failsafe_exception(status, exception); end
+ end
+
def test_failsafe_response
CGI.expects(:new).raises('some multipart parsing failure')
-
- ActionController::Routing::Routes.stubs(:reload)
- Dispatcher.any_instance.stubs(:log_failsafe_exception)
+ Dispatcher.expects(:log_failsafe_exception)
assert_nothing_raised { dispatch }
assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string
end
- def test_reload_application_sets_unprepared_if_loading_dependencies
- Dependencies.stubs(:load?).returns(false)
- ActionController::Routing::Routes.expects(:reload).never
- @dispatcher.unprepared = false
- @dispatcher.send!(:reload_application)
- assert !@dispatcher.unprepared
-
- Dependencies.stubs(:load?).returns(true)
- ActionController::Routing::Routes.expects(:reload).once
- @dispatcher.send!(:reload_application)
- assert @dispatcher.unprepared
- end
-
- def test_prepare_application_runs_callbacks_if_unprepared
+ def test_prepare_callbacks
a = b = c = nil
Dispatcher.to_prepare { |*args| a = b = c = 1 }
Dispatcher.to_prepare { |*args| b = c = 2 }
Dispatcher.to_prepare { |*args| c = 3 }
- # Skip the callbacks when already prepared.
- @dispatcher.unprepared = false
- @dispatcher.send! :prepare_application
+ # Ensure to_prepare callbacks are not run when defined
assert_nil a || b || c
- # Perform the callbacks when unprepared.
- @dispatcher.unprepared = true
- @dispatcher.send! :prepare_application
+ # Run callbacks
+ @dispatcher.send :run_callbacks, :prepare_dispatch
+
assert_equal 1, a
assert_equal 2, b
assert_equal 3, c
- # But when not :load, make sure they are only run once
+ # Make sure they are only run once
a = b = c = nil
- @dispatcher.send! :prepare_application
+ @dispatcher.send :dispatch
assert_nil a || b || c
end
@@ -90,28 +80,20 @@ class DispatcherTest < Test::Unit::TestCase
Dispatcher.to_prepare(:unique_id) { |*args| a = b = 1 }
Dispatcher.to_prepare(:unique_id) { |*args| a = 2 }
- @dispatcher.unprepared = true
- @dispatcher.send! :prepare_application
+ @dispatcher.send :run_callbacks, :prepare_dispatch
assert_equal 2, a
assert_equal nil, b
end
- def test_to_prepare_only_runs_once_if_not_loading_dependencies
- Dependencies.stubs(:load?).returns(false)
- called = 0
- Dispatcher.to_prepare(:unprepared_test) { |*args| called += 1 }
- 2.times { dispatch }
- assert_equal 1, called
- end
-
private
- def dispatch(output = @output)
+ def dispatch(output = @output, cache_classes = true)
controller = mock
controller.stubs(:process).returns(controller)
controller.stubs(:out).with(output).returns('response')
ActionController::Routing::Routes.stubs(:recognize).returns(controller)
+ Dispatcher.define_dispatcher_callbacks(cache_classes)
Dispatcher.dispatch(nil, {}, output)
end
diff --git a/actionpack/test/controller/flash_test.rb b/actionpack/test/controller/flash_test.rb
index f672f2f427..e562531bf3 100644
--- a/actionpack/test/controller/flash_test.rb
+++ b/actionpack/test/controller/flash_test.rb
@@ -52,7 +52,7 @@ class FlashTest < Test::Unit::TestCase
end
def rescue_action(e)
- raise unless ActionController::MissingTemplate === e
+ raise unless ActionView::MissingTemplate === e
end
# methods for test_sweep_after_halted_filter_chain
diff --git a/actionpack/test/controller/layout_test.rb b/actionpack/test/controller/layout_test.rb
index 145543a357..3dc311b78a 100644
--- a/actionpack/test/controller/layout_test.rb
+++ b/actionpack/test/controller/layout_test.rb
@@ -216,7 +216,7 @@ class LayoutExceptionRaised < Test::Unit::TestCase
@controller = SetsNonExistentLayoutFile.new
get :hello
@response.template.class.module_eval { attr_accessor :exception }
- assert_equal ActionController::MissingTemplate, @response.template.exception.class
+ assert_equal ActionView::MissingTemplate, @response.template.exception.class
end
end
diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb
index c34643ddd5..c617cb2e84 100644
--- a/actionpack/test/controller/mime_responds_test.rb
+++ b/actionpack/test/controller/mime_responds_test.rb
@@ -468,7 +468,7 @@ class MimeControllerTest < Test::Unit::TestCase
assert_equal '<html><div id="html_missing">Hello future from Firefox!</div></html>', @response.body
@request.env["HTTP_ACCEPT"] = "text/iphone"
- assert_raises(ActionController::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
+ assert_raises(ActionView::MissingTemplate) { get :iphone_with_html_response_type_without_layout }
end
end
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index 342e2e7f87..80cf09e5f3 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -652,7 +652,7 @@ EOS
end
def test_bad_render_to_string_still_throws_exception
- assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception }
+ assert_raises(ActionView::MissingTemplate) { get :render_to_string_with_exception }
end
def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns
@@ -787,7 +787,7 @@ EOS
end
def test_render_missing_partial_template
- assert_raises(ActionView::ActionViewError) do
+ assert_raises(ActionView::MissingTemplate) do
get :missing_partial
end
end
diff --git a/actionpack/test/controller/rescue_test.rb b/actionpack/test/controller/rescue_test.rb
index 55631e0777..27fcc5e04c 100644
--- a/actionpack/test/controller/rescue_test.rb
+++ b/actionpack/test/controller/rescue_test.rb
@@ -279,7 +279,7 @@ class RescueTest < Test::Unit::TestCase
assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates.default
assert_equal ActionController::Rescue::DEFAULT_RESCUE_TEMPLATE, templates[Exception.new]
- assert_equal 'missing_template', templates[ActionController::MissingTemplate.name]
+ assert_equal 'missing_template', templates[ActionView::MissingTemplate.name]
assert_equal 'routing_error', templates[ActionController::RoutingError.name]
assert_equal 'unknown_action', templates[ActionController::UnknownAction.name]
assert_equal 'template_error', templates[ActionView::TemplateError.name]
@@ -305,7 +305,9 @@ class RescueTest < Test::Unit::TestCase
def test_not_implemented
with_all_requests_local false do
- head :not_implemented
+ with_rails_public_path(".") do
+ head :not_implemented
+ end
end
assert_response :not_implemented
assert_equal "GET, PUT", @response.headers['Allow']
@@ -313,7 +315,9 @@ class RescueTest < Test::Unit::TestCase
def test_method_not_allowed
with_all_requests_local false do
- get :method_not_allowed
+ with_rails_public_path(".") do
+ get :method_not_allowed
+ end
end
assert_response :method_not_allowed
assert_equal "GET, HEAD, PUT", @response.headers['Allow']
@@ -391,7 +395,19 @@ class RescueTest < Test::Unit::TestCase
@request.remote_addr = old_remote_addr
end
- def with_rails_root(path = nil)
+ def with_rails_public_path(rails_root)
+ old_rails = Object.const_get(:Rails) rescue nil
+ mod = Object.const_set(:Rails, Module.new)
+ (class << mod; self; end).instance_eval do
+ define_method(:public_path) { "#{rails_root}/public" }
+ end
+ yield
+ ensure
+ Object.module_eval { remove_const(:Rails) } if defined?(Rails)
+ Object.const_set(:Rails, old_rails) if old_rails
+ end
+
+ def with_rails_root(path = nil,&block)
old_rails_root = RAILS_ROOT if defined?(RAILS_ROOT)
if path
silence_warnings { Object.const_set(:RAILS_ROOT, path) }
@@ -399,7 +415,7 @@ class RescueTest < Test::Unit::TestCase
Object.remove_const(:RAILS_ROOT) rescue nil
end
- yield
+ with_rails_public_path(path, &block)
ensure
if old_rails_root
diff --git a/actionpack/test/fixtures/public/javascripts/version.1.0.js b/actionpack/test/fixtures/public/javascripts/version.1.0.js
new file mode 100644
index 0000000000..cfd5fce70e
--- /dev/null
+++ b/actionpack/test/fixtures/public/javascripts/version.1.0.js
@@ -0,0 +1 @@
+// version.1.0 js \ No newline at end of file
diff --git a/actionpack/test/fixtures/public/stylesheets/version.1.0.css b/actionpack/test/fixtures/public/stylesheets/version.1.0.css
new file mode 100644
index 0000000000..30f5f9ba6e
--- /dev/null
+++ b/actionpack/test/fixtures/public/stylesheets/version.1.0.css
@@ -0,0 +1 @@
+/* version.1.0.css */ \ No newline at end of file
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index 31fe7bbc29..dfc30e651a 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -1,12 +1,7 @@
require 'abstract_unit'
-class ActiveRecordHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::ActiveRecordHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::FormTagHelper
+class ActiveRecordHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::ActiveRecordHelper
silence_warnings do
Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index be605329fc..4a8117a88a 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -1,9 +1,7 @@
require 'abstract_unit'
-class AssetTagHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::AssetTagHelper
+class AssetTagHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::AssetTagHelper
def setup
silence_warnings do
@@ -84,7 +82,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
%(javascript_include_tag("xmlhr", :lang => "vbscript")) => %(<script lang="vbscript" src="/javascripts/xmlhr.js" type="text/javascript"></script>),
%(javascript_include_tag("common.javascript", "/elsewhere/cools")) => %(<script src="/javascripts/common.javascript" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>),
%(javascript_include_tag(:defaults)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
- %(javascript_include_tag(:all)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
+ %(javascript_include_tag(:all)) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
%(javascript_include_tag(:defaults, "test")) => %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
%(javascript_include_tag("test", :defaults)) => %(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
}
@@ -109,8 +107,8 @@ class AssetTagHelperTest < Test::Unit::TestCase
%(stylesheet_link_tag("/dir/file")) => %(<link href="/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
%(stylesheet_link_tag("dir/file")) => %(<link href="/stylesheets/dir/file.css" media="screen" rel="stylesheet" type="text/css" />),
%(stylesheet_link_tag("style", :media => "all")) => %(<link href="/stylesheets/style.css" media="all" rel="stylesheet" type="text/css" />),
- %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
- %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />),
+ %(stylesheet_link_tag(:all)) => %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
+ %(stylesheet_link_tag(:all, :media => "all")) => %(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="all" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="all" rel="stylesheet" type="text/css" />),
%(stylesheet_link_tag("random.styles", "/css/stylish")) => %(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" type="text/css" />\n<link href="/css/stylish.css" media="screen" rel="stylesheet" type="text/css" />),
%(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />)
}
@@ -358,7 +356,7 @@ class AssetTagHelperTest < Test::Unit::TestCase
assert File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
assert_equal(
- %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js),
+ %(// prototype js\n\n// effects js\n\n// dragdrop js\n\n// controls js\n\n// application js\n\n// bank js\n\n// robber js\n\n// version.1.0 js),
IO.read(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'combined.js'))
)
@@ -371,14 +369,14 @@ class AssetTagHelperTest < Test::Unit::TestCase
ActionController::Base.perform_caching = false
assert_dom_equal(
- %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
javascript_include_tag(:all, :cache => true)
)
assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::JAVASCRIPTS_DIR, 'all.js'))
assert_dom_equal(
- %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>),
+ %(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/javascripts/version.1.0.js" type="text/javascript"></script>),
javascript_include_tag(:all, :cache => "money")
)
@@ -430,14 +428,14 @@ class AssetTagHelperTest < Test::Unit::TestCase
ActionController::Base.perform_caching = false
assert_dom_equal(
- %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
stylesheet_link_tag(:all, :cache => true)
)
assert !File.exist?(File.join(ActionView::Helpers::AssetTagHelper::STYLESHEETS_DIR, 'all.css'))
assert_dom_equal(
- %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />),
+ %(<link href="/stylesheets/bank.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/robber.css" media="screen" rel="stylesheet" type="text/css" />\n<link href="/stylesheets/version.1.0.css" media="screen" rel="stylesheet" type="text/css" />),
stylesheet_link_tag(:all, :cache => "money")
)
@@ -445,10 +443,8 @@ class AssetTagHelperTest < Test::Unit::TestCase
end
end
-class AssetTagHelperNonVhostTest < Test::Unit::TestCase
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::AssetTagHelper
+class AssetTagHelperNonVhostTest < ActionView::TestCase
+ tests ActionView::Helpers::AssetTagHelper
def setup
@controller = Class.new do
diff --git a/actionpack/test/template/benchmark_helper_test.rb b/actionpack/test/template/benchmark_helper_test.rb
index 76c0780482..d95a3dee26 100644
--- a/actionpack/test/template/benchmark_helper_test.rb
+++ b/actionpack/test/template/benchmark_helper_test.rb
@@ -1,8 +1,8 @@
require 'abstract_unit'
require 'action_view/helpers/benchmark_helper'
-class BenchmarkHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::BenchmarkHelper
+class BenchmarkHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::BenchmarkHelper
class MockLogger
attr_reader :logged
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index 25b1f9f002..9bd433e76b 100755
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -1,8 +1,7 @@
require 'abstract_unit'
-class DateHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::DateHelper
- include ActionView::Helpers::FormHelper
+class DateHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::DateHelper
silence_warnings do
Post = Struct.new("Post", :id, :written_on, :updated_at)
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 766e88375b..c48d5dfd2d 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -30,15 +30,8 @@ end
class Comment::Nested < Comment; end
-class FormHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::FormTagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::ActiveRecordHelper
- include ActionView::Helpers::RecordIdentificationHelper
- include ActionController::PolymorphicRoutes
+class FormHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::FormHelper
def setup
@post = Post.new
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index f3ecc18233..48a26deea9 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -22,9 +22,8 @@ end
ActionView::Helpers::FormOptionsHelper::TimeZone = MockTimeZone
-class FormOptionsHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::FormOptionsHelper
+class FormOptionsHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::FormOptionsHelper
silence_warnings do
Post = Struct.new('Post', :title, :author_name, :body, :secret, :written_on, :category, :origin)
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index 7caa85802a..73a8bd4d87 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -1,11 +1,7 @@
require 'abstract_unit'
-class FormTagHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::FormTagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::CaptureHelper
+class FormTagHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::FormTagHelper
def setup
@controller = Class.new do
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index 581ca58f89..f18adb990c 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -1,13 +1,7 @@
require 'abstract_unit'
-class JavaScriptHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::JavaScriptHelper
-
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::CaptureHelper
+class JavaScriptHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::JavaScriptHelper
def test_define_javascript_functions
# check if prototype.js is included first
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index 7065ca7a84..4a8d09b544 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -1,7 +1,7 @@
require 'abstract_unit'
-class NumberHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::NumberHelper
+class NumberHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::NumberHelper
def test_number_to_phone
assert_equal("800-555-1212", number_to_phone(8005551212))
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 28e58b0a08..a84d4e72af 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -24,24 +24,11 @@ end
class Author::Nested < Author; end
-module BaseTest
- def self.included(base)
- base.send :attr_accessor, :template_format
- end
+class PrototypeHelperBaseTest < ActionView::TestCase
+ tests ActionView::Helpers::PrototypeHelper
+
+ attr_accessor :template_format
- include ActionView::Helpers::JavaScriptHelper
- include ActionView::Helpers::PrototypeHelper
- include ActionView::Helpers::ScriptaculousHelper
-
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::FormTagHelper
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::CaptureHelper
- include ActionView::Helpers::RecordIdentificationHelper
- include ActionController::PolymorphicRoutes
-
def setup
@template = nil
@controller = Class.new do
@@ -59,25 +46,22 @@ module BaseTest
end.new
end
-protected
-
- def request_forgery_protection_token
- nil
- end
-
- def protect_against_forgery?
- false
- end
-
- def create_generator
- block = Proc.new { |*args| yield *args if block_given? }
- JavaScriptGenerator.new self, &block
- end
+ protected
+ def request_forgery_protection_token
+ nil
+ end
+
+ def protect_against_forgery?
+ false
+ end
+
+ def create_generator
+ block = Proc.new { |*args| yield *args if block_given? }
+ JavaScriptGenerator.new self, &block
+ end
end
-class PrototypeHelperTest < Test::Unit::TestCase
- include BaseTest
-
+class PrototypeHelperTest < PrototypeHelperBaseTest
def setup
@record = @author = Author.new
@article = Article.new
@@ -294,9 +278,7 @@ class PrototypeHelperTest < Test::Unit::TestCase
end
end
-class JavaScriptGeneratorTest < Test::Unit::TestCase
- include BaseTest
-
+class JavaScriptGeneratorTest < PrototypeHelperBaseTest
def setup
super
@generator = create_generator
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index bb5440be20..0afbb54f57 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -9,14 +9,9 @@ class Post
end
end
-class RecordTagHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::RecordTagHelper
- include ActionView::Helpers::CaptureHelper
- include ActionView::Helpers::RecordIdentificationHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::UrlHelper
-
+class RecordTagHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::RecordTagHelper
+
def setup
@post = Post.new
end
diff --git a/actionpack/test/template/sanitize_helper_test.rb b/actionpack/test/template/sanitize_helper_test.rb
index a840c8b4cb..e5427d9dc1 100644
--- a/actionpack/test/template/sanitize_helper_test.rb
+++ b/actionpack/test/template/sanitize_helper_test.rb
@@ -3,9 +3,8 @@ require 'testing_sandbox'
# The exhaustive tests are in test/controller/html/sanitizer_test.rb.
# This tests the that the helpers hook up correctly to the sanitizer classes.
-class SanitizeHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::SanitizeHelper
- include ActionView::Helpers::TagHelper
+class SanitizeHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::SanitizeHelper
include TestingSandbox
def test_strip_links
diff --git a/actionpack/test/template/scriptaculous_helper_test.rb b/actionpack/test/template/scriptaculous_helper_test.rb
index 91856ff980..690a7751b5 100644
--- a/actionpack/test/template/scriptaculous_helper_test.rb
+++ b/actionpack/test/template/scriptaculous_helper_test.rb
@@ -1,16 +1,8 @@
require 'abstract_unit'
-class ScriptaculousHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::JavaScriptHelper
- include ActionView::Helpers::PrototypeHelper
- include ActionView::Helpers::ScriptaculousHelper
-
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::FormHelper
- include ActionView::Helpers::CaptureHelper
-
+class ScriptaculousHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::ScriptaculousHelper
+
def setup
@controller = Class.new do
def url_for(options)
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
index 4b73289060..4da6116095 100644
--- a/actionpack/test/template/tag_helper_test.rb
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -1,10 +1,7 @@
require 'abstract_unit'
-class TagHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::TagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::CaptureHelper
+class TagHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::TagHelper
def test_tag
assert_equal "<br />", tag("br")
diff --git a/actionpack/test/template/template_object_test.rb b/actionpack/test/template/template_object_test.rb
index b3a33938cf..7adcde421f 100644
--- a/actionpack/test/template/template_object_test.rb
+++ b/actionpack/test/template/template_object_test.rb
@@ -82,7 +82,7 @@ class TemplateObjectTest < Test::Unit::TestCase
def test_xml
@view.template_format = :xml
- assert_raise ActionView::ActionViewError do
+ assert_raise ActionView::MissingTemplate do
ActionView::PartialTemplate.new(@view, @path, nil)
end
end
diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb
new file mode 100644
index 0000000000..660f51b3be
--- /dev/null
+++ b/actionpack/test/template/test_test.rb
@@ -0,0 +1,56 @@
+require 'abstract_unit'
+
+module PeopleHelper
+ def title(text)
+ content_tag(:h1, text)
+ end
+
+ def homepage_path
+ people_path
+ end
+
+ def homepage_url
+ people_url
+ end
+
+ def link_to_person(person)
+ link_to person.name, person
+ end
+end
+
+class PeopleHelperTest < ActionView::TestCase
+ def setup
+ ActionController::Routing::Routes.draw do |map|
+ map.people 'people', :controller => 'people', :action => 'index'
+ map.connect ':controller/:action/:id'
+ end
+ end
+
+ def test_title
+ assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails")
+ end
+
+ def test_homepage_path
+ assert_equal "/people", homepage_path
+ end
+
+ def test_homepage_url
+ assert_equal "http://test.host/people", homepage_url
+ end
+
+ uses_mocha "link_to_person" do
+ def test_link_to_person
+ person = mock(:name => "David")
+ expects(:mocha_mock_path).with(person).returns("/people/1")
+ assert_equal '<a href="/people/1">David</a>', link_to_person(person)
+ end
+ end
+end
+
+class CrazyHelperTest < ActionView::TestCase
+ tests PeopleHelper
+
+ def test_helper_class_can_be_set_manually_not_just_inferred
+ assert_equal PeopleHelper, self.class.helper_class
+ end
+end
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 7d92bce4bd..25ecda687f 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -1,9 +1,8 @@
require 'abstract_unit'
require 'testing_sandbox'
-class TextHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::TextHelper
- include ActionView::Helpers::TagHelper
+class TextHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::TextHelper
include TestingSandbox
def setup
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 9cd3b6e2f9..d45ea08a6f 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -2,10 +2,8 @@ require 'abstract_unit'
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)
-class UrlHelperTest < Test::Unit::TestCase
- include ActionView::Helpers::AssetTagHelper
- include ActionView::Helpers::UrlHelper
- include ActionView::Helpers::TagHelper
+class UrlHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::UrlHelper
def setup
@controller = Class.new do
@@ -293,7 +291,7 @@ class UrlHelperTest < Test::Unit::TestCase
end
end
-class UrlHelperWithControllerTest < Test::Unit::TestCase
+class UrlHelperWithControllerTest < ActionView::TestCase
class UrlHelperController < ActionController::Base
self.view_paths = [ "#{File.dirname(__FILE__)}/../fixtures/" ]
@@ -310,7 +308,7 @@ class UrlHelperWithControllerTest < Test::Unit::TestCase
def rescue_action(e) raise e end
end
- include ActionView::Helpers::UrlHelper
+ tests ActionView::Helpers::UrlHelper
def setup
@request = ActionController::TestRequest.new
@@ -348,7 +346,7 @@ class UrlHelperWithControllerTest < Test::Unit::TestCase
end
end
-class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase
+class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase
class TasksController < ActionController::Base
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
@@ -372,7 +370,7 @@ class LinkToUnlessCurrentWithControllerTest < Test::Unit::TestCase
end
end
- include ActionView::Helpers::UrlHelper
+ tests ActionView::Helpers::UrlHelper
def setup
@request = ActionController::TestRequest.new
@@ -440,7 +438,7 @@ class Session
end
end
-class PolymorphicControllerTest < Test::Unit::TestCase
+class PolymorphicControllerTest < ActionView::TestCase
class WorkshopsController < ActionController::Base
self.view_paths = ["#{File.dirname(__FILE__)}/../fixtures/"]
@@ -479,7 +477,7 @@ class PolymorphicControllerTest < Test::Unit::TestCase
def rescue_action(e) raise e end
end
- include ActionView::Helpers::UrlHelper
+ tests ActionView::Helpers::UrlHelper
def setup
@request = ActionController::TestRequest.new