mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-31 22:38:49 +01:00
Vendoring Rails 2.3.5
This commit is contained in:
parent
3e83d19299
commit
f8779795ce
943 changed files with 56503 additions and 61351 deletions
159
vendor/rails/actionpack/test/template/render_test.rb
vendored
159
vendor/rails/actionpack/test/template/render_test.rb
vendored
|
|
@ -1,16 +1,23 @@
|
|||
# encoding: utf-8
|
||||
require 'abstract_unit'
|
||||
require 'controller/fake_models'
|
||||
|
||||
class ViewRenderTest < Test::Unit::TestCase
|
||||
def setup
|
||||
module RenderTestCases
|
||||
def setup_view(paths)
|
||||
@assigns = { :secret => 'in the sauce' }
|
||||
@view = ActionView::Base.new(ActionController::Base.view_paths, @assigns)
|
||||
@view = ActionView::Base.new(paths, @assigns)
|
||||
|
||||
# Reload and register danish language for testing
|
||||
I18n.reload!
|
||||
I18n.backend.store_translations 'da', {}
|
||||
I18n.backend.store_translations 'pt-BR', {}
|
||||
|
||||
# Ensure original are still the same since we are reindexing view paths
|
||||
assert_equal ORIGINAL_LOCALES, I18n.available_locales.map(&:to_s).sort
|
||||
end
|
||||
|
||||
def test_render_file
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", @view.render("test/hello_world.erb")
|
||||
end
|
||||
assert_equal "Hello world!", @view.render(:file => "test/hello_world.erb")
|
||||
end
|
||||
|
||||
def test_render_file_not_using_full_path
|
||||
|
|
@ -18,15 +25,46 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_render_file_without_specific_extension
|
||||
assert_deprecated do
|
||||
assert_equal "Hello world!", @view.render("test/hello_world")
|
||||
end
|
||||
assert_equal "Hello world!", @view.render(:file => "test/hello_world")
|
||||
end
|
||||
|
||||
def test_render_file_with_localization
|
||||
old_locale = I18n.locale
|
||||
I18n.locale = :da
|
||||
assert_equal "Hey verden", @view.render(:file => "test/hello_world")
|
||||
ensure
|
||||
I18n.locale = old_locale
|
||||
end
|
||||
|
||||
def test_render_file_with_dashed_locale
|
||||
old_locale = I18n.locale
|
||||
I18n.locale = :"pt-BR"
|
||||
assert_equal "Ola mundo", @view.render(:file => "test/hello_world")
|
||||
ensure
|
||||
I18n.locale = old_locale
|
||||
end
|
||||
|
||||
def test_render_implicit_html_template_from_xhr_request
|
||||
old_format = @view.template_format
|
||||
@view.template_format = :js
|
||||
assert_equal "Hello HTML!", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
|
||||
ensure
|
||||
@view.template_format = old_format
|
||||
end
|
||||
|
||||
def test_render_implicit_html_template_from_xhr_request_with_localization
|
||||
old_locale = I18n.locale
|
||||
old_format = @view.template_format
|
||||
I18n.locale = :da
|
||||
@view.template_format = :js
|
||||
assert_equal "Hey HTML!\n", @view.render(:file => "test/render_implicit_html_template_from_xhr_request")
|
||||
ensure
|
||||
I18n.locale = old_locale
|
||||
@view.template_format = old_format
|
||||
end
|
||||
|
||||
def test_render_file_at_top_level
|
||||
assert_deprecated do
|
||||
assert_equal 'Elastica', @view.render('/shared')
|
||||
end
|
||||
assert_equal 'Elastica', @view.render(:file => '/shared')
|
||||
end
|
||||
|
||||
def test_render_file_with_full_path
|
||||
|
|
@ -35,28 +73,20 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_render_file_with_instance_variables
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_ivar.erb")
|
||||
end
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_ivar.erb")
|
||||
end
|
||||
|
||||
def test_render_file_with_locals
|
||||
locals = { :secret => 'in the sauce' }
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/render_file_with_locals.erb", locals)
|
||||
end
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/render_file_with_locals.erb", :locals => locals)
|
||||
end
|
||||
|
||||
def test_render_file_not_using_full_path_with_dot_in_path
|
||||
assert_deprecated do
|
||||
assert_equal "The secret is in the sauce\n", @view.render("test/dot.directory/render_file_with_ivar")
|
||||
end
|
||||
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar")
|
||||
end
|
||||
|
||||
def test_render_has_access_current_template
|
||||
assert_deprecated do
|
||||
assert_equal "test/template.erb", @view.render("test/template.erb")
|
||||
end
|
||||
assert_equal "test/template.erb", @view.render(:file => "test/template.erb")
|
||||
end
|
||||
|
||||
def test_render_update
|
||||
|
|
@ -65,6 +95,10 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal 'alert("Hello, World!");', @view.render(:update) { |page| page.alert('Hello, World!') }
|
||||
end
|
||||
|
||||
def test_render_partial_from_default
|
||||
assert_equal "only partial", @view.render("test/partial_only")
|
||||
end
|
||||
|
||||
def test_render_partial
|
||||
assert_equal "only partial", @view.render(:partial => "test/partial_only")
|
||||
end
|
||||
|
|
@ -87,6 +121,10 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 })
|
||||
end
|
||||
|
||||
def test_render_partial_with_locals_from_default
|
||||
assert_equal "only partial", @view.render("test/partial_only", :counter_counter => 5)
|
||||
end
|
||||
|
||||
def test_render_partial_with_errors
|
||||
@view.render(:partial => "test/raise")
|
||||
flunk "Render did not raise TemplateError"
|
||||
|
|
@ -107,6 +145,10 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal File.expand_path("#{FIXTURE_LOAD_PATH}/test/_raise.html.erb"), e.file_name
|
||||
end
|
||||
|
||||
def test_render_object
|
||||
assert_equal "Hello: david", @view.render(:partial => "test/customer", :object => Customer.new("david"))
|
||||
end
|
||||
|
||||
def test_render_partial_collection
|
||||
assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", :collection => [ Customer.new("david"), Customer.new("mary") ])
|
||||
end
|
||||
|
|
@ -142,12 +184,6 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
|
||||
end
|
||||
|
||||
# TODO: The reason for this test is unclear, improve documentation
|
||||
def test_render_js_partial_and_fallback_to_erb_layout
|
||||
@view.template_format = :js
|
||||
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })
|
||||
end
|
||||
|
||||
# TODO: The reason for this test is unclear, improve documentation
|
||||
def test_render_missing_xml_partial_and_raise_missing_template
|
||||
@view.template_format = :xml
|
||||
|
|
@ -163,7 +199,7 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_render_fallbacks_to_erb_for_unknown_types
|
||||
assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :foo)
|
||||
assert_equal "Hello, World!", @view.render(:inline => "Hello, World!", :type => :bar)
|
||||
end
|
||||
|
||||
CustomHandler = lambda do |template|
|
||||
|
|
@ -181,6 +217,27 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal 'source: "Hello, <%= name %>!"', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
|
||||
end
|
||||
|
||||
class LegacyHandler < ActionView::TemplateHandler
|
||||
def render(template, local_assigns)
|
||||
"source: #{template.source}; locals: #{local_assigns.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_render_legacy_handler_with_custom_type
|
||||
ActionView::Template.register_template_handler :foo, LegacyHandler
|
||||
assert_equal 'source: Hello, <%= name %>!; locals: {:name=>"Josh"}', @view.render(:inline => "Hello, <%= name %>!", :locals => { :name => "Josh" }, :type => :foo)
|
||||
end
|
||||
|
||||
def test_render_ignores_templates_with_malformed_template_handlers
|
||||
%w(malformed malformed.erb malformed.html.erb malformed.en.html.erb).each do |name|
|
||||
assert_raise(ActionView::MissingTemplate) { @view.render(:file => "test/malformed/#{name}") }
|
||||
end
|
||||
end
|
||||
|
||||
def test_template_with_malformed_template_handler_is_reachable_through_its_exact_filename
|
||||
assert_equal "Don't render me!", @view.render(:file => 'test/malformed/malformed.html.erb~')
|
||||
end
|
||||
|
||||
def test_render_with_layout
|
||||
assert_equal %(<title></title>\nHello world!\n),
|
||||
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
|
||||
|
|
@ -190,4 +247,44 @@ class ViewRenderTest < Test::Unit::TestCase
|
|||
assert_equal %(<title>title</title>\n<div id="column">column</div>\n<div id="content">content</div>\n),
|
||||
@view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")
|
||||
end
|
||||
|
||||
if '1.9'.respond_to?(:force_encoding)
|
||||
def test_render_utf8_template
|
||||
result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
|
||||
assert_equal "Русский текст\n日本語のテキスト", result
|
||||
assert_equal Encoding::UTF_8, result.encoding
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module TemplatesSetupTeardown
|
||||
def setup_view_paths_for(new_cache_template_loading)
|
||||
@previous_cache_template_loading, ActionView::Base.cache_template_loading = ActionView::Base.cache_template_loading, new_cache_template_loading
|
||||
view_paths = new_cache_template_loading ? CACHED_VIEW_PATHS : ActionView::Base.process_view_paths(CACHED_VIEW_PATHS.map(&:to_s))
|
||||
assert_equal(new_cache_template_loading ? ActionView::Template::EagerPath : ActionView::ReloadableTemplate::ReloadablePath, view_paths.first.class)
|
||||
setup_view(view_paths)
|
||||
end
|
||||
|
||||
def teardown
|
||||
ActionView::Base.cache_template_loading = @previous_cache_template_loading
|
||||
end
|
||||
end
|
||||
|
||||
class CachedRenderTest < Test::Unit::TestCase
|
||||
include TemplatesSetupTeardown
|
||||
include RenderTestCases
|
||||
|
||||
def setup
|
||||
setup_view_paths_for(cache_templates = true)
|
||||
end
|
||||
end
|
||||
|
||||
class ReloadableRenderTest < Test::Unit::TestCase
|
||||
include TemplatesSetupTeardown
|
||||
include RenderTestCases
|
||||
|
||||
def setup
|
||||
setup_view_paths_for(cache_templates = false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue