aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/asset_tag_helper_test.rb38
-rw-r--r--actionpack/test/template/capture_helper_test.rb16
-rw-r--r--actionpack/test/template/date_helper_test.rb10
-rw-r--r--actionpack/test/template/erb_util_test.rb3
-rw-r--r--actionpack/test/template/form_helper_test.rb36
-rw-r--r--actionpack/test/template/form_options_helper_test.rb3
-rw-r--r--actionpack/test/template/form_tag_helper_test.rb3
-rw-r--r--actionpack/test/template/javascript_helper_test.rb40
-rw-r--r--actionpack/test/template/lookup_context_test.rb25
-rw-r--r--actionpack/test/template/number_helper_test.rb5
-rw-r--r--actionpack/test/template/prototype_helper_test.rb476
-rw-r--r--actionpack/test/template/render_test.rb17
-rw-r--r--actionpack/test/template/resolver_patterns_test.rb31
-rw-r--r--actionpack/test/template/scriptaculous_helper_test.rb86
-rw-r--r--actionpack/test/template/sprockets_helper_test.rb119
-rw-r--r--actionpack/test/template/streaming_render_test.rb105
-rw-r--r--actionpack/test/template/template_test.rb38
-rw-r--r--actionpack/test/template/text_helper_test.rb16
18 files changed, 347 insertions, 720 deletions
diff --git a/actionpack/test/template/asset_tag_helper_test.rb b/actionpack/test/template/asset_tag_helper_test.rb
index 1bf748af14..2abc806e97 100644
--- a/actionpack/test/template/asset_tag_helper_test.rb
+++ b/actionpack/test/template/asset_tag_helper_test.rb
@@ -66,6 +66,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(auto_discovery_link_tag(:xml)) => %(<link href="http://www.example.com" rel="alternate" title="XML" type="application/xml" />),
%(auto_discovery_link_tag(:rss, :action => "feed")) => %(<link href="http://www.example.com" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss, "http://localhost/feed")) => %(<link href="http://localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
+ %(auto_discovery_link_tag(:rss, "//localhost/feed")) => %(<link href="//localhost/feed" rel="alternate" title="RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(:rss, {}, {:title => "My RSS"})) => %(<link href="http://www.example.com" rel="alternate" title="My RSS" type="application/rss+xml" />),
%(auto_discovery_link_tag(nil, {}, {:type => "text/html"})) => %(<link href="http://www.example.com" rel="alternate" title="" type="text/html" />),
@@ -100,6 +101,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(javascript_include_tag("http://example.com/all")) => %(<script src="http://example.com/all" type="text/javascript"></script>),
%(javascript_include_tag("http://example.com/all.js")) => %(<script src="http://example.com/all.js" type="text/javascript"></script>),
+ %(javascript_include_tag("//example.com/all.js")) => %(<script src="//example.com/all.js" type="text/javascript"></script>),
}
StylePathToTag = {
@@ -129,6 +131,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(stylesheet_link_tag("http://www.example.com/styles/style")) => %(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" type="text/css" />),
%(stylesheet_link_tag("http://www.example.com/styles/style.css")) => %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />),
+ %(stylesheet_link_tag("//www.example.com/styles/style.css")) => %(<link href="//www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />),
}
ImagePathToTag = {
@@ -157,6 +160,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(image_tag("slash..png")) => %(<img alt="Slash." src="/images/slash..png" />),
%(image_tag(".pdf.png")) => %(<img alt=".pdf" src="/images/.pdf.png" />),
%(image_tag("http://www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="http://www.rubyonrails.com/images/rails.png" />),
+ %(image_tag("//www.rubyonrails.com/images/rails.png")) => %(<img alt="Rails" src="//www.rubyonrails.com/images/rails.png" />),
%(image_tag("mouse.png", :mouseover => "/images/mouse_over.png")) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
%(image_tag("mouse.png", :mouseover => image_path("mouse_over.png"))) => %(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
%(image_tag("mouse.png", :alt => nil)) => %(<img src="/images/mouse.png" />)
@@ -195,6 +199,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(video_tag("error.avi", "size" => "100 x 100")) => %(<video src="/videos/error.avi" />),
%(video_tag("error.avi", "size" => "x")) => %(<video src="/videos/error.avi" />),
%(video_tag("http://media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="http://media.rubyonrails.org/video/rails_blog_2.mov" />),
+ %(video_tag("//media.rubyonrails.org/video/rails_blog_2.mov")) => %(<video src="//media.rubyonrails.org/video/rails_blog_2.mov" />),
%(video_tag(["multiple.ogg", "multiple.avi"])) => %(<video><source src="multiple.ogg" /><source src="multiple.avi" /></video>),
%(video_tag(["multiple.ogg", "multiple.avi"], :size => "160x120", :controls => true)) => %(<video controls="controls" height="120" width="160"><source src="multiple.ogg" /><source src="multiple.avi" /></video>)
}
@@ -217,6 +222,7 @@ class AssetTagHelperTest < ActionView::TestCase
%(audio_tag("xml.wav")) => %(<audio src="/audios/xml.wav" />),
%(audio_tag("rss.wav", :autoplay => true, :controls => true)) => %(<audio autoplay="autoplay" controls="controls" src="/audios/rss.wav" />),
%(audio_tag("http://media.rubyonrails.org/audio/rails_blog_2.mov")) => %(<audio src="http://media.rubyonrails.org/audio/rails_blog_2.mov" />),
+ %(audio_tag("//media.rubyonrails.org/audio/rails_blog_2.mov")) => %(<audio src="//media.rubyonrails.org/audio/rails_blog_2.mov" />),
}
def test_auto_discovery_link_tag
@@ -477,15 +483,6 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end
- def test_env_asset_path
- @controller.config.asset_path = "/assets%s"
- def @controller.env; @_env ||= {} end
- @controller.env["action_dispatch.asset_path"] = "/omg%s"
-
- expected_path = "/assets/omg/images/rails.png"
- assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
- end
-
def test_proc_asset_id
@controller.config.asset_path = Proc.new do |asset_path|
"/assets.v12345#{asset_path}"
@@ -495,20 +492,6 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
end
- def test_env_proc_asset_path
- @controller.config.asset_path = Proc.new do |asset_path|
- "/assets.v12345#{asset_path}"
- end
-
- def @controller.env; @_env ||= {} end
- @controller.env["action_dispatch.asset_path"] = Proc.new do |asset_path|
- "/omg#{asset_path}"
- end
-
- expected_path = "/assets.v12345/omg/images/rails.png"
- assert_equal %(<img alt="Rails" src="#{expected_path}" />), image_tag("rails.png")
- end
-
def test_image_tag_interpreting_email_cid_correctly
# An inline image has no need for an alt tag to be automatically generated from the cid:
assert_equal '<img src="cid:thi%25%25sis@acontentid" />', image_tag("cid:thi%25%25sis@acontentid")
@@ -528,6 +511,10 @@ class AssetTagHelperTest < ActionView::TestCase
assert_equal %(<img alt="Rails" src="http://www.example.com/rails.png" />), image_tag("http://www.example.com/rails.png")
end
+ def test_should_skip_asset_id_on_scheme_relative_url
+ assert_equal %(<img alt="Rails" src="//www.example.com/rails.png" />), image_tag("//www.example.com/rails.png")
+ end
+
def test_should_use_preset_asset_id
ENV["RAILS_ASSET_ID"] = "4500"
assert_equal %(<img alt="Rails" src="/images/rails.png?4500" />), image_tag("rails.png")
@@ -1118,6 +1105,11 @@ class AssetTagHelperNonVhostTest < ActionView::TestCase
assert_dom_equal(%(<link href="http://bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("http://bar.example.com/stylesheets/style.css"))
end
+ def test_should_ignore_asset_host_on_scheme_relative_url
+ @controller.config.asset_host = "http://assets.example.com"
+ assert_dom_equal(%(<link href="//bar.example.com/stylesheets/style.css" media="screen" rel="stylesheet" type="text/css" />), stylesheet_link_tag("//bar.example.com/stylesheets/style.css"))
+ end
+
def test_should_wildcard_asset_host_between_zero_and_four
@controller.config.asset_host = 'http://a%d.example.com'
assert_match(%r(http://a[0123].example.com/collaboration/hieraki/images/xml.png), image_path('xml.png'))
diff --git a/actionpack/test/template/capture_helper_test.rb b/actionpack/test/template/capture_helper_test.rb
index 03050485fa..a9a36e6e6b 100644
--- a/actionpack/test/template/capture_helper_test.rb
+++ b/actionpack/test/template/capture_helper_test.rb
@@ -4,7 +4,7 @@ class CaptureHelperTest < ActionView::TestCase
def setup
super
@av = ActionView::Base.new
- @_content_for = Hash.new {|h,k| h[k] = "" }
+ @_view_flow = ActionView::OutputFlow.new
end
def test_capture_captures_the_temporary_output_buffer_in_its_block
@@ -45,6 +45,20 @@ class CaptureHelperTest < ActionView::TestCase
assert ! content_for?(:something_else)
end
+ def test_provide
+ assert !content_for?(:title)
+ provide :title, "hi"
+ assert content_for?(:title)
+ assert_equal "hi", @_view_flow.get(:title)
+ provide :title, "<p>title</p>"
+ assert_equal "hi&lt;p&gt;title&lt;/p&gt;", @_view_flow.get(:title)
+
+ @_view_flow = ActionView::OutputFlow.new
+ provide :title, "hi"
+ provide :title, "<p>title</p>".html_safe
+ assert_equal "hi<p>title</p>", @_view_flow.get(:title)
+ end
+
def test_with_output_buffer_swaps_the_output_buffer_given_no_argument
assert_nil @av.output_buffer
buffer = @av.with_output_buffer do
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index aca2fef170..12d2410f49 100644
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -53,12 +53,12 @@ class DateHelperTest < ActionView::TestCase
assert_equal "about 2 hours", distance_of_time_in_words(from, to + 89.minutes + 30.seconds)
assert_equal "about 24 hours", distance_of_time_in_words(from, to + 23.hours + 59.minutes + 29.seconds)
- # 1440..2529
+ # 1440..2519
assert_equal "1 day", distance_of_time_in_words(from, to + 23.hours + 59.minutes + 30.seconds)
assert_equal "1 day", distance_of_time_in_words(from, to + 41.hours + 59.minutes + 29.seconds)
- # 2530..43199
- assert_equal "2 days", distance_of_time_in_words(from, to + 42.hours + 59.minutes + 30.seconds)
+ # 2520..43199
+ assert_equal "2 days", distance_of_time_in_words(from, to + 41.hours + 59.minutes + 30.seconds)
assert_equal "3 days", distance_of_time_in_words(from, to + 2.days + 12.hours)
assert_equal "30 days", distance_of_time_in_words(from, to + 29.days + 23.hours + 59.minutes + 29.seconds)
@@ -2720,11 +2720,11 @@ class DateHelperTest < ActionView::TestCase
end
def test_time_tag_pubdate_option
- assert_match /<time.*pubdate="pubdate">.*<\/time>/, time_tag(Time.now, :pubdate => true)
+ assert_match(/<time.*pubdate="pubdate">.*<\/time>/, time_tag(Time.now, :pubdate => true))
end
def test_time_tag_with_given_text
- assert_match /<time.*>Right now<\/time>/, time_tag(Time.now, 'Right now')
+ assert_match(/<time.*>Right now<\/time>/, time_tag(Time.now, 'Right now'))
end
def test_time_tag_with_different_format
diff --git a/actionpack/test/template/erb_util_test.rb b/actionpack/test/template/erb_util_test.rb
index d1891094e8..30f6d1a213 100644
--- a/actionpack/test/template/erb_util_test.rb
+++ b/actionpack/test/template/erb_util_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'active_support/core_ext/object/inclusion'
class ErbUtilTest < Test::Unit::TestCase
include ERB::Util
@@ -29,7 +30,7 @@ class ErbUtilTest < Test::Unit::TestCase
def test_rest_in_ascii
(0..127).to_a.map {|int| int.chr }.each do |chr|
- next if %w(& " < >).include?(chr)
+ next if chr.in?('&"<>')
assert_equal chr, html_escape(chr)
end
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 359b078466..c25c850eb3 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'controller/fake_models'
+require 'active_support/core_ext/object/inclusion'
class FormHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper
@@ -23,7 +24,10 @@ class FormHelperTest < ActionView::TestCase
:helpers => {
:label => {
:post => {
- :body => "Write entire text here"
+ :body => "Write entire text here",
+ :color => {
+ :red => "Rojo"
+ }
}
}
}
@@ -140,6 +144,13 @@ class FormHelperTest < ActionView::TestCase
I18n.locale = old_locale
end
+ def test_label_with_locales_and_value
+ old_locale, I18n.locale = I18n.locale, :label
+ assert_dom_equal('<label for="post_color_red">Rojo</label>', label(:post, :color, :value => "red"))
+ ensure
+ I18n.locale = old_locale
+ end
+
def test_label_with_for_attribute_as_symbol
assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
end
@@ -715,14 +726,31 @@ class FormHelperTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
+ def test_form_for_with_method_as_part_of_html_options
+ form_for(@post, :url => '/', :html => { :id => 'create-post', :method => :delete }) do |f|
+ concat f.text_field(:title)
+ concat f.text_area(:body)
+ concat f.check_box(:secret)
+ end
+
+ expected = whole_form("/", "create-post", "edit_post", "delete") do
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
+ "<input name='post[secret]' type='hidden' value='0' />" +
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
+ end
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_with_method
- form_for(@post, :url => '/', :html => { :id => 'create-post', :method => :put }) do |f|
+ form_for(@post, :url => '/', :method => :delete, :html => { :id => 'create-post' }) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
end
- expected = whole_form("/", "create-post", "edit_post", "put") do
+ expected = whole_form("/", "create-post", "edit_post", "delete") do
"<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
@@ -1726,7 +1754,7 @@ class FormHelperTest < ActionView::TestCase
def snowman(method = nil)
txt = %{<div style="margin:0;padding:0;display:inline">}
txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
- if (method && !['get','post'].include?(method.to_s))
+ if method && !method.to_s.in?(['get', 'post'])
txt << %{<input name="_method" type="hidden" value="#{method}" />}
end
txt << %{</div>}
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 93ff7ba0fd..b92e1d9890 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -1,5 +1,6 @@
require 'abstract_unit'
require 'tzinfo'
+require 'active_support/core_ext/object/inclusion'
class Map < Hash
def category
@@ -82,7 +83,7 @@ class FormOptionsHelperTest < ActionView::TestCase
def test_collection_options_with_proc_for_disabled
assert_dom_equal(
"<option value=\"&lt;Abe&gt;\">&lt;Abe&gt; went home</option>\n<option value=\"Babe\" disabled=\"disabled\">Babe went home</option>\n<option value=\"Cabe\" disabled=\"disabled\">Cabe went home</option>",
- options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| %w(Babe Cabe).include? p.author_name })
+ options_from_collection_for_select(dummy_posts, "author_name", "title", :disabled => lambda{|p| p.author_name.in?(["Babe", "Cabe"]) })
)
end
diff --git a/actionpack/test/template/form_tag_helper_test.rb b/actionpack/test/template/form_tag_helper_test.rb
index f8671f2980..656fa0356b 100644
--- a/actionpack/test/template/form_tag_helper_test.rb
+++ b/actionpack/test/template/form_tag_helper_test.rb
@@ -1,4 +1,5 @@
require 'abstract_unit'
+require 'active_support/core_ext/object/inclusion'
class FormTagHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormTagHelper
@@ -13,7 +14,7 @@ class FormTagHelperTest < ActionView::TestCase
txt = %{<div style="margin:0;padding:0;display:inline">}
txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
- if (method && !['get','post'].include?(method.to_s))
+ if method && !method.to_s.in?(['get','post'])
txt << %{<input name="_method" type="hidden" value="#{method}" />}
end
txt << %{</div>}
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index 2e7484afaf..538e0e9874 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -27,6 +27,7 @@ class JavaScriptHelperTest < ActionView::TestCase
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) )
assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags))
+ assert_equal %(dont <\\/close> tags), j(%(dont </close> tags))
end
def test_button_to_function
@@ -34,20 +35,6 @@ class JavaScriptHelperTest < ActionView::TestCase
button_to_function("Greeting", "alert('Hello world!')")
end
- def test_button_to_function_with_rjs_block
- html = button_to_function( "Greet me!" ) do |page|
- page.replace_html 'header', "<h1>Greetings</h1>"
- end
- assert_dom_equal %(<input type="button" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);;" value="Greet me!" />), html
- end
-
- def test_button_to_function_with_rjs_block_and_options
- html = button_to_function( "Greet me!", :class => "greeter" ) do |page|
- page.replace_html 'header', "<h1>Greetings</h1>"
- end
- assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C\/h1\\u003E&quot;);;" value="Greet me!" />), html
- end
-
def test_button_to_function_with_onclick
assert_dom_equal "<input onclick=\"alert('Goodbye World :('); alert('Hello world!');\" type=\"button\" value=\"Greeting\" />",
button_to_function("Greeting", "alert('Hello world!')", :onclick => "alert('Goodbye World :(')")
@@ -68,34 +55,11 @@ class JavaScriptHelperTest < ActionView::TestCase
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
end
- def test_link_to_function_with_rjs_block
- html = link_to_function( "Greet me!" ) do |page|
- page.replace_html 'header', "<h1>Greetings</h1>"
- end
- assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
- end
-
- def test_link_to_function_with_rjs_block_and_options
- html = link_to_function( "Greet me!", :class => "updater" ) do |page|
- page.replace_html 'header', "<h1>Greetings</h1>"
- end
- assert_dom_equal %(<a href="#" class="updater" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
- end
-
- def test_link_to_function_with_href
+ def test_function_with_href
assert_dom_equal %(<a href="http://example.com/" onclick="alert('Hello world!'); return false;">Greeting</a>),
link_to_function("Greeting", "alert('Hello world!')", :href => 'http://example.com/')
end
- def test_link_to_function_with_inner_block_does_not_raise_exception
- html = link_to_function( "Greet me!" ) do |page|
- page.replace_html 'header', (content_tag :h1 do
- 'Greetings'
- end)
- end
- assert_dom_equal %(<a href="#" onclick="Element.update(&quot;header&quot;, &quot;\\u003Ch1\\u003EGreetings\\u003C/h1\\u003E&quot;);; return false;">Greet me!</a>), html
- end
-
def test_javascript_tag
self.output_buffer = 'foo'
diff --git a/actionpack/test/template/lookup_context_test.rb b/actionpack/test/template/lookup_context_test.rb
index 8d063e66b0..ff94cba59f 100644
--- a/actionpack/test/template/lookup_context_test.rb
+++ b/actionpack/test/template/lookup_context_test.rb
@@ -180,16 +180,6 @@ class LookupContextTest < ActiveSupport::TestCase
assert_not_equal template, old_template
end
-
- test "data can be stored in cached templates" do
- template = @lookup_context.find("hello_world", %w(test))
- template.data["cached"] = "data"
- assert_equal "Hello world!", template.source
-
- template = @lookup_context.find("hello_world", %w(test))
- assert_equal "data", template.data["cached"]
- assert_equal "Hello world!", template.source
- end
end
class LookupContextWithFalseCaching < ActiveSupport::TestCase
@@ -235,21 +225,6 @@ class LookupContextWithFalseCaching < ActiveSupport::TestCase
template = @lookup_context.find("foo", %w(test), true)
assert_equal "Foo", template.source
end
-
- test "data can be stored as long as template was not updated" do
- template = @lookup_context.find("foo", %w(test), true)
- template.data["cached"] = "data"
- assert_equal "Foo", template.source
-
- template = @lookup_context.find("foo", %w(test), true)
- assert_equal "data", template.data["cached"]
- assert_equal "Foo", template.source
-
- @resolver.hash["test/_foo.erb"][1] = Time.now.utc
- template = @lookup_context.find("foo", %w(test), true)
- assert_nil template.data["cached"]
- assert_equal "Foo", template.source
- end
end
class TestMissingTemplate < ActiveSupport::TestCase
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index c1b4bab903..23a7e17e65 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -32,6 +32,7 @@ class NumberHelperTest < ActionView::TestCase
assert_equal("555-1234", number_to_phone(5551234))
assert_equal("800-555-1212", number_to_phone(8005551212))
assert_equal("(800) 555-1212", number_to_phone(8005551212, {:area_code => true}))
+ assert_equal("", number_to_phone("", {:area_code => true}))
assert_equal("800 555 1212", number_to_phone(8005551212, {:delimiter => " "}))
assert_equal("(800) 555-1212 x 123", number_to_phone(8005551212, {:area_code => true, :extension => 123}))
assert_equal("800-555-1212", number_to_phone(8005551212, :extension => " "))
@@ -195,7 +196,9 @@ class NumberHelperTest < ActionView::TestCase
def test_number_to_human
assert_equal '-123', number_to_human(-123)
- assert_equal '0', number_to_human(0)
+ assert_equal '-0.5', number_to_human(-0.5)
+ assert_equal '0', number_to_human(0)
+ assert_equal '0.5', number_to_human(0.5)
assert_equal '123', number_to_human(123)
assert_equal '1.23 Thousand', number_to_human(1234)
assert_equal '12.3 Thousand', number_to_human(12345)
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
deleted file mode 100644
index a6aa848a00..0000000000
--- a/actionpack/test/template/prototype_helper_test.rb
+++ /dev/null
@@ -1,476 +0,0 @@
-require 'abstract_unit'
-require 'active_model'
-
-class Bunny < Struct.new(:Bunny, :id)
- extend ActiveModel::Naming
- include ActiveModel::Conversion
- def to_key() id ? [id] : nil end
-end
-
-class Author
- extend ActiveModel::Naming
- include ActiveModel::Conversion
-
- attr_reader :id
- def to_key() id ? [id] : nil end
- def save; @id = 1 end
- def new_record?; @id.nil? end
- def name
- @id.nil? ? 'new author' : "author ##{@id}"
- end
-end
-
-class Article
- extend ActiveModel::Naming
- include ActiveModel::Conversion
- attr_reader :id
- attr_reader :author_id
- def to_key() id ? [id] : nil end
- def save; @id = 1; @author_id = 1 end
- def new_record?; @id.nil? end
- def name
- @id.nil? ? 'new article' : "article ##{@id}"
- end
-end
-
-class Author::Nested < Author; end
-
-
-class PrototypeHelperBaseTest < ActionView::TestCase
- attr_accessor :formats, :output_buffer
-
- def update_details(details)
- @details = details
- yield if block_given?
- end
-
- def setup
- super
- @template = self
- end
-
- def url_for(options)
- if options.is_a?(String)
- options
- else
- url = "http://www.example.com/"
- url << options[:action].to_s if options and options[:action]
- url << "?a=#{options[:a]}" if options && options[:a]
- url << "&b=#{options[:b]}" if options && options[:a] && options[:b]
- url
- end
- 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 < PrototypeHelperBaseTest
- def _evaluate_assigns_and_ivars() end
-
- def setup
- @record = @author = Author.new
- @article = Article.new
- super
- end
-
- def test_update_page
- old_output_buffer = output_buffer
-
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
- assert_equal create_generator(&block).to_s, update_page(&block)
-
- assert_equal old_output_buffer, output_buffer
- end
-
- def test_update_page_tag
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
- assert_equal javascript_tag(create_generator(&block).to_s), update_page_tag(&block)
- end
-
- def test_update_page_tag_with_html_options
- block = Proc.new { |page| page.replace_html('foo', 'bar') }
- assert_equal javascript_tag(create_generator(&block).to_s, {:defer => 'true'}), update_page_tag({:defer => 'true'}, &block)
- end
-
- def test_remote_function
- res = remote_function(:url => authors_path, :with => "'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')")
- assert_equal "new Ajax.Request('/authors', {asynchronous:true, evalScripts:true, parameters:'author[name]='+$F('author_name')+'&author[dob]='+$F('author_dob')})", res
- assert res.html_safe?
- end
-
- protected
- def author_path(record)
- "/authors/#{record.id}"
- end
-
- def authors_path
- "/authors"
- end
-
- def author_articles_path(author)
- "/authors/#{author.id}/articles"
- end
-
- def author_article_path(author, article)
- "/authors/#{author.id}/articles/#{article.id}"
- end
-end
-
-class JavaScriptGeneratorTest < PrototypeHelperBaseTest
- def setup
- super
- @generator = create_generator
- ActiveSupport.escape_html_entities_in_json = true
- end
-
- def teardown
- ActiveSupport.escape_html_entities_in_json = false
- end
-
- def _evaluate_assigns_and_ivars() end
-
- def test_insert_html_with_string
- assert_equal 'Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });',
- @generator.insert_html(:top, 'element', '<p>This is a test</p>')
- assert_equal 'Element.insert("element", { bottom: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
- @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
- assert_equal 'Element.insert("element", { before: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
- @generator.insert_html(:before, 'element', '<p>This is a test</p>')
- assert_equal 'Element.insert("element", { after: "\\u003Cp\u003EThis is a test\\u003C/p\u003E" });',
- @generator.insert_html(:after, 'element', '<p>This is a test</p>')
- end
-
- def test_replace_html_with_string
- assert_equal 'Element.update("element", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");',
- @generator.replace_html('element', '<p>This is a test</p>')
- end
-
- def test_replace_element_with_string
- assert_equal 'Element.replace("element", "\\u003Cdiv id=\"element\"\\u003E\\u003Cp\\u003EThis is a test\\u003C/p\\u003E\\u003C/div\\u003E");',
- @generator.replace('element', '<div id="element"><p>This is a test</p></div>')
- end
-
- def test_remove
- assert_equal 'Element.remove("foo");',
- @generator.remove('foo')
- assert_equal '["foo","bar","baz"].each(Element.remove);',
- @generator.remove('foo', 'bar', 'baz')
- end
-
- def test_show
- assert_equal 'Element.show("foo");',
- @generator.show('foo')
- assert_equal '["foo","bar","baz"].each(Element.show);',
- @generator.show('foo', 'bar', 'baz')
- end
-
- def test_hide
- assert_equal 'Element.hide("foo");',
- @generator.hide('foo')
- assert_equal '["foo","bar","baz"].each(Element.hide);',
- @generator.hide('foo', 'bar', 'baz')
- end
-
- def test_toggle
- assert_equal 'Element.toggle("foo");',
- @generator.toggle('foo')
- assert_equal '["foo","bar","baz"].each(Element.toggle);',
- @generator.toggle('foo', 'bar', 'baz')
- end
-
- def test_alert
- assert_equal 'alert("hello");', @generator.alert('hello')
- end
-
- def test_redirect_to
- assert_equal 'window.location.href = "http://www.example.com/welcome";',
- @generator.redirect_to(:action => 'welcome')
- assert_equal 'window.location.href = "http://www.example.com/welcome?a=b&c=d";',
- @generator.redirect_to("http://www.example.com/welcome?a=b&c=d")
- end
-
- def test_reload
- assert_equal 'window.location.reload();',
- @generator.reload
- end
-
- def test_delay
- @generator.delay(20) do
- @generator.hide('foo')
- end
-
- assert_equal "setTimeout(function() {\n;\nElement.hide(\"foo\");\n}, 20000);", @generator.to_s
- end
-
- def test_to_s
- @generator.insert_html(:top, 'element', '<p>This is a test</p>')
- @generator.insert_html(:bottom, 'element', '<p>This is a test</p>')
- @generator.remove('foo', 'bar')
- @generator.replace_html('baz', '<p>This is a test</p>')
-
- assert_equal <<-EOS.chomp, @generator.to_s
-Element.insert("element", { top: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
-Element.insert("element", { bottom: "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E" });
-["foo","bar"].each(Element.remove);
-Element.update("baz", "\\u003Cp\\u003EThis is a test\\u003C/p\\u003E");
- EOS
- end
-
- def test_element_access
- assert_equal %($("hello");), @generator['hello']
- end
-
- def test_element_access_on_records
- assert_equal %($("bunny_5");), @generator[Bunny.new(:id => 5)]
- assert_equal %($("new_bunny");), @generator[Bunny.new]
- end
-
- def test_element_proxy_one_deep
- @generator['hello'].hide
- assert_equal %($("hello").hide();), @generator.to_s
- end
-
- def test_element_proxy_variable_access
- @generator['hello']['style']
- assert_equal %($("hello").style;), @generator.to_s
- end
-
- def test_element_proxy_variable_access_with_assignment
- @generator['hello']['style']['color'] = 'red'
- assert_equal %($("hello").style.color = "red";), @generator.to_s
- end
-
- def test_element_proxy_assignment
- @generator['hello'].width = 400
- assert_equal %($("hello").width = 400;), @generator.to_s
- end
-
- def test_element_proxy_two_deep
- @generator['hello'].hide("first").clean_whitespace
- assert_equal %($("hello").hide("first").cleanWhitespace();), @generator.to_s
- end
-
- def test_select_access
- assert_equal %($$("div.hello");), @generator.select('div.hello')
- end
-
- def test_select_proxy_one_deep
- @generator.select('p.welcome b').first.hide
- assert_equal %($$("p.welcome b").first().hide();), @generator.to_s
- end
-
- def test_visual_effect
- assert_equal %(new Effect.Puff("blah",{});),
- @generator.visual_effect(:puff,'blah')
- end
-
- def test_visual_effect_toggle
- assert_equal %(Effect.toggle("blah",'appear',{});),
- @generator.visual_effect(:toggle_appear,'blah')
- end
-
- def test_sortable
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
- @generator.sortable('blah', :url => { :action => "order" })
- assert_equal %(Sortable.create("blah", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:Sortable.serialize("blah")})}});),
- @generator.sortable('blah', :url => { :action => "order" }, :type => :synchronous)
- end
-
- def test_draggable
- assert_equal %(new Draggable("blah", {});),
- @generator.draggable('blah')
- end
-
- def test_drop_receiving
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
- @generator.drop_receiving('blah', :url => { :action => "order" })
- assert_equal %(Droppables.add("blah", {onDrop:function(element){new Ajax.Request('http://www.example.com/order', {asynchronous:false, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}});),
- @generator.drop_receiving('blah', :url => { :action => "order" }, :type => :synchronous)
- end
-
- def test_collection_first_and_last
- @generator.select('p.welcome b').first.hide()
- @generator.select('p.welcome b').last.show()
- assert_equal <<-EOS.strip, @generator.to_s
-$$("p.welcome b").first().hide();
-$$("p.welcome b").last().show();
- EOS
- end
-
- def test_collection_proxy_with_each
- @generator.select('p.welcome b').each do |value|
- value.remove_class_name 'selected'
- end
- @generator.select('p.welcome b').each do |value, index|
- @generator.visual_effect :highlight, value
- end
- assert_equal <<-EOS.strip, @generator.to_s
-$$("p.welcome b").each(function(value, index) {
-value.removeClassName("selected");
-});
-$$("p.welcome b").each(function(value, index) {
-new Effect.Highlight(value,{});
-});
- EOS
- end
-
- def test_collection_proxy_on_collect
- @generator.select('p').collect('a') { |para| para.show }
- @generator.select('p').collect { |para| para.hide }
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").collect(function(value, index) {
-return value.show();
-});
-$$("p").collect(function(value, index) {
-return value.hide();
-});
- EOS
- @generator = create_generator
- end
-
- def test_collection_proxy_with_grep
- @generator.select('p').grep 'a', /^a/ do |value|
- @generator << '(value.className == "welcome")'
- end
- @generator.select('p').grep 'b', /b$/ do |value, index|
- @generator.call 'alert', value
- @generator << '(value.className == "welcome")'
- end
-
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").grep(/^a/, function(value, index) {
-return (value.className == "welcome");
-});
-var b = $$("p").grep(/b$/, function(value, index) {
-alert(value);
-return (value.className == "welcome");
-});
- EOS
- end
-
- def test_collection_proxy_with_inject
- @generator.select('p').inject 'a', [] do |memo, value|
- @generator << '(value.className == "welcome")'
- end
- @generator.select('p').inject 'b', nil do |memo, value, index|
- @generator.call 'alert', memo
- @generator << '(value.className == "welcome")'
- end
-
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").inject([], function(memo, value, index) {
-return (value.className == "welcome");
-});
-var b = $$("p").inject(null, function(memo, value, index) {
-alert(memo);
-return (value.className == "welcome");
-});
- EOS
- end
-
- def test_collection_proxy_with_pluck
- @generator.select('p').pluck('a', 'className')
- assert_equal %(var a = $$("p").pluck("className");), @generator.to_s
- end
-
- def test_collection_proxy_with_zip
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('a', [4, 5, 6], [7, 8, 9])
- ActionView::Helpers::JavaScriptCollectionProxy.new(@generator, '[1, 2, 3]').zip('b', [4, 5, 6], [7, 8, 9]) do |array|
- @generator.call 'array.reverse'
- end
-
- assert_equal <<-EOS.strip, @generator.to_s
-var a = [1, 2, 3].zip([4,5,6], [7,8,9]);
-var b = [1, 2, 3].zip([4,5,6], [7,8,9], function(array) {
-return array.reverse();
-});
- EOS
- end
-
- def test_collection_proxy_with_find_all
- @generator.select('p').find_all 'a' do |value, index|
- @generator << '(value.className == "welcome")'
- end
-
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").findAll(function(value, index) {
-return (value.className == "welcome");
-});
- EOS
- end
-
- def test_collection_proxy_with_in_groups_of
- @generator.select('p').in_groups_of('a', 3)
- @generator.select('p').in_groups_of('a', 3, 'x')
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").inGroupsOf(3);
-var a = $$("p").inGroupsOf(3, "x");
- EOS
- end
-
- def test_collection_proxy_with_each_slice
- @generator.select('p').each_slice('a', 3)
- @generator.select('p').each_slice('a', 3) do |group, index|
- group.reverse
- end
-
- assert_equal <<-EOS.strip, @generator.to_s
-var a = $$("p").eachSlice(3);
-var a = $$("p").eachSlice(3, function(value, index) {
-return value.reverse();
-});
- EOS
- end
-
- def test_debug_rjs
- ActionView::Base.debug_rjs = true
- @generator['welcome'].replace_html 'Welcome'
- assert_equal "try {\n$(\"welcome\").update(\"Welcome\");\n} catch (e) { alert('RJS error:\\n\\n' + e.toString()); alert('$(\\\"welcome\\\").update(\\\"Welcome\\\");'); throw e }", @generator.to_s
- ensure
- ActionView::Base.debug_rjs = false
- end
-
- def test_literal
- literal = @generator.literal("function() {}")
- assert_equal "function() {}", ActiveSupport::JSON.encode(literal)
- assert_equal "", @generator.to_s
- end
-
- def test_class_proxy
- @generator.form.focus('my_field')
- assert_equal "Form.focus(\"my_field\");", @generator.to_s
- end
-
- def test_call_with_block
- @generator.call(:before)
- @generator.call(:my_method) do |p|
- p[:one].show
- p[:two].hide
- end
- @generator.call(:in_between)
- @generator.call(:my_method_with_arguments, true, "hello") do |p|
- p[:three].visual_effect(:highlight)
- end
- assert_equal "before();\nmy_method(function() { $(\"one\").show();\n$(\"two\").hide(); });\nin_between();\nmy_method_with_arguments(true, \"hello\", function() { $(\"three\").visualEffect(\"highlight\"); });", @generator.to_s
- end
-
- def test_class_proxy_call_with_block
- @generator.my_object.my_method do |p|
- p[:one].show
- p[:two].hide
- end
- assert_equal "MyObject.myMethod(function() { $(\"one\").show();\n$(\"two\").hide(); });", @generator.to_s
- end
-end
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 034fb6c210..d4e912c410 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -68,10 +68,6 @@ module RenderTestCases
assert_equal "The secret is in the sauce\n", @view.render(:file => "test/dot.directory/render_file_with_ivar")
end
- def test_render_update
- 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
@@ -231,20 +227,11 @@ module RenderTestCases
"@output_buffer << 'source: #{template.source.inspect}'\n"
end
- WithViewHandler = lambda do |template, view|
- %'"#{template.class} #{view.class}"'
- end
-
def test_render_inline_with_render_from_to_proc
ActionView::Template.register_template_handler :ruby_handler, :source.to_proc
assert_equal '3', @view.render(:inline => "(1 + 2).to_s", :type => :ruby_handler)
end
- def test_render_inline_with_template_handler_with_view
- ActionView::Template.register_template_handler :with_view, WithViewHandler
- assert_equal 'ActionView::Template ActionView::Base', @view.render(:inline => "Hello, World!", :type => :with_view)
- end
-
def test_render_inline_with_compilable_custom_type
ActionView::Template.register_template_handler :foo, CustomHandler
assert_equal 'source: "Hello, World!"', @view.render(:inline => "Hello, World!", :type => :foo)
@@ -381,7 +368,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
end
def test_render_utf8_template_with_incompatible_external_encoding
- with_external_encoding Encoding::SJIS do
+ with_external_encoding Encoding::SHIFT_JIS do
begin
result = @view.render(:file => "test/utf8.html.erb", :layouts => "layouts/yield")
flunk 'Should have raised incompatible encoding error'
@@ -392,7 +379,7 @@ class LazyViewRenderTest < ActiveSupport::TestCase
end
def test_render_utf8_template_with_partial_with_incompatible_encoding
- with_external_encoding Encoding::SJIS do
+ with_external_encoding Encoding::SHIFT_JIS do
begin
result = @view.render(:file => "test/utf8_magic_with_bare_partial.html.erb", :layouts => "layouts/yield")
flunk 'Should have raised incompatible encoding error'
diff --git a/actionpack/test/template/resolver_patterns_test.rb b/actionpack/test/template/resolver_patterns_test.rb
new file mode 100644
index 0000000000..97b1bad055
--- /dev/null
+++ b/actionpack/test/template/resolver_patterns_test.rb
@@ -0,0 +1,31 @@
+require 'abstract_unit'
+
+class ResolverPatternsTest < ActiveSupport::TestCase
+ def setup
+ path = File.expand_path("../../fixtures/", __FILE__)
+ pattern = ":prefix/{:formats/,}:action{.:formats,}{.:handlers,}"
+ @resolver = ActionView::FileSystemResolver.new(path, pattern)
+ end
+
+ def test_should_return_empty_list_for_unknown_path
+ templates = @resolver.find_all("unknown", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ assert_equal [], templates, "expected an empty list of templates"
+ end
+
+ def test_should_return_template_for_declared_path
+ templates = @resolver.find_all("path", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ assert_equal 1, templates.size, "expected one template"
+ assert_equal "Hello custom patterns!", templates.first.source
+ assert_equal "custom_pattern/path", templates.first.virtual_path
+ assert_equal [:html], templates.first.formats
+ end
+
+ def test_should_return_all_templates_when_ambigous_pattern
+ templates = @resolver.find_all("another", "custom_pattern", false, {:locale => [], :formats => [:html], :handlers => [:erb]})
+ assert_equal 2, templates.size, "expected two templates"
+ assert_equal "Another template!", templates[0].source
+ assert_equal "custom_pattern/another", templates[0].virtual_path
+ assert_equal "Hello custom patterns!", templates[1].source
+ assert_equal "custom_pattern/another", templates[1].virtual_path
+ end
+end
diff --git a/actionpack/test/template/scriptaculous_helper_test.rb b/actionpack/test/template/scriptaculous_helper_test.rb
deleted file mode 100644
index 233012bfdd..0000000000
--- a/actionpack/test/template/scriptaculous_helper_test.rb
+++ /dev/null
@@ -1,86 +0,0 @@
-require 'abstract_unit'
-
-class ScriptaculousHelperTest < ActionView::TestCase
- tests ActionView::Helpers::ScriptaculousHelper
-
- def url_for(options)
- url = "http://www.example.com/"
- url << options[:action].to_s if options and options[:action]
- url
- end
-
- def test_effect
- assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, "posts")
- assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect("highlight", :posts)
- assert_equal "new Effect.Highlight(\"posts\",{});", visual_effect(:highlight, :posts)
- assert_equal "new Effect.Fade(\"fademe\",{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
- assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
- assert_equal "new Effect.DropOut(\"dropme\",{queue:'end'});", visual_effect(:drop_out, 'dropme', :queue => :end)
- assert_equal "new Effect.Highlight(\"status\",{endcolor:'#EEEEEE'});", visual_effect(:highlight, 'status', :endcolor => '#EEEEEE')
- assert_equal "new Effect.Highlight(\"status\",{restorecolor:'#500000', startcolor:'#FEFEFE'});", visual_effect(:highlight, 'status', :restorecolor => '#500000', :startcolor => '#FEFEFE')
-
- # chop the queue params into a comma separated list
- beginning, ending = 'new Effect.DropOut("dropme",{queue:{', '}});'
- ve = [
- visual_effect(:drop_out, 'dropme', :queue => {:position => "end", :scope => "test", :limit => 2}),
- visual_effect(:drop_out, 'dropme', :queue => {:scope => :list, :limit => 2}),
- visual_effect(:drop_out, 'dropme', :queue => {:position => :end, :scope => :test, :limit => 2})
- ].collect { |v| v[beginning.length..-ending.length-1].split(',') }
-
- assert ve[0].include?("limit:2")
- assert ve[0].include?("scope:'test'")
- assert ve[0].include?("position:'end'")
-
- assert ve[1].include?("limit:2")
- assert ve[1].include?("scope:'list'")
-
- assert ve[2].include?("limit:2")
- assert ve[2].include?("scope:'test'")
- assert ve[2].include?("position:'end'")
- end
-
- def test_toggle_effects
- assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect(:toggle_appear, "posts")
- assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect(:toggle_slide, "posts")
- assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect(:toggle_blind, "posts")
- assert_equal "Effect.toggle(\"posts\",'appear',{});", visual_effect("toggle_appear", "posts")
- assert_equal "Effect.toggle(\"posts\",'slide',{});", visual_effect("toggle_slide", "posts")
- assert_equal "Effect.toggle(\"posts\",'blind',{});", visual_effect("toggle_blind", "posts")
- end
-
-
- def test_sortable_element
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>),
- sortable_element("mylist", :url => { :action => "order" })
- assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}, tag:'div'})\n//]]>\n</script>),
- sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
- assert_dom_equal %|<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>|,
- sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nSortable.create(\"mylist\", {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {asynchronous:true, evalScripts:true, parameters:Sortable.serialize(\"mylist\")})}})\n//]]>\n</script>),
- sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
- end
-
- def test_draggable_element
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {})\n//]]>\n</script>),
- draggable_element("product_13")
- assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable(\"product_13\", {revert:true})\n//]]>\n</script>),
- draggable_element("product_13", :revert => true)
- end
-
- def test_drop_receiving_element
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
- drop_receiving_element("droptarget1")
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
- drop_receiving_element("droptarget1", :accept => 'products')
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
- drop_receiving_element("droptarget1", :accept => 'products', :update => 'infobox')
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add(\"droptarget1\", {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)})}})\n//]]>\n</script>),
- drop_receiving_element("droptarget1", :accept => ['tshirts','mugs'], :update => 'infobox')
- assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nDroppables.add("droptarget1", {hoverclass:'dropready', onDrop:function(element){if (confirm('Are you sure?')) { new Ajax.Request('http://www.example.com/update_drop', {asynchronous:true, evalScripts:true, parameters:'id=' + encodeURIComponent(element.id)}); }}})\n//]]>\n</script>),
- drop_receiving_element('droptarget1', :hoverclass=>'dropready', :url=>{:action=>'update_drop'}, :confirm => 'Are you sure?')
-
- end
- def protect_against_forgery?
- false
- end
-end
diff --git a/actionpack/test/template/sprockets_helper_test.rb b/actionpack/test/template/sprockets_helper_test.rb
new file mode 100644
index 0000000000..8d3be09a4f
--- /dev/null
+++ b/actionpack/test/template/sprockets_helper_test.rb
@@ -0,0 +1,119 @@
+require 'abstract_unit'
+require 'sprockets'
+require 'mocha'
+
+module Rails; end
+
+class SprocketsHelperTest < ActionView::TestCase
+ tests ActionView::Helpers::SprocketsHelper
+
+ attr_accessor :assets
+
+ def setup
+ super
+
+ @controller = BasicController.new
+
+ @request = Class.new do
+ def protocol() 'http://' end
+ def ssl?() false end
+ def host_with_port() 'localhost' end
+ end.new
+
+ @controller.request = @request
+
+ @assets = Sprockets::Environment.new
+ @assets.paths << FIXTURES.join("sprockets/app/javascripts")
+ @assets.paths << FIXTURES.join("sprockets/app/stylesheets")
+ @assets.paths << FIXTURES.join("sprockets/app/images")
+
+ application = Object.new
+ Rails.stubs(:application).returns(application)
+ application.stubs(:config).returns(config)
+ application.stubs(:assets).returns(@assets)
+
+ config.perform_caching = true
+ end
+
+ def url_for(*args)
+ "http://www.example.com"
+ end
+
+ test "asset path" do
+ assert_equal "/assets/logo-9c0a079bdd7701d7e729bd956823d153.png",
+ asset_path("logo.png")
+
+ assert_equal "/images/logo",
+ asset_path("/images/logo")
+ assert_equal "/images/logo.gif",
+ asset_path("/images/logo.gif")
+
+ assert_equal "/dir/audio",
+ asset_path("/dir/audio")
+
+ assert_equal "http://www.example.com/video/play",
+ asset_path("http://www.example.com/video/play")
+ assert_equal "http://www.example.com/video/play.mp4",
+ asset_path("http://www.example.com/video/play.mp4")
+ end
+
+ test "javascript path" do
+ assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.js",
+ asset_path(:application, "js")
+
+ assert_equal "/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
+ asset_path("xmlhr", "js")
+ assert_equal "/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js",
+ asset_path("dir/xmlhr.js", "js")
+
+ assert_equal "/dir/xmlhr.js",
+ asset_path("/dir/xmlhr", "js")
+
+ assert_equal "http://www.example.com/js/xmlhr",
+ asset_path("http://www.example.com/js/xmlhr", "js")
+ assert_equal "http://www.example.com/js/xmlhr.js",
+ asset_path("http://www.example.com/js/xmlhr.js", "js")
+ end
+
+ test "javascript include tag" do
+ assert_equal '<script src="/assets/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag(:application)
+
+ assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("xmlhr")
+ assert_equal '<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("xmlhr.js")
+ assert_equal '<script src="http://www.example.com/xmlhr" type="text/javascript"></script>',
+ sprockets_javascript_include_tag("http://www.example.com/xmlhr")
+ end
+
+ test "stylesheet path" do
+ assert_equal "/assets/application-d41d8cd98f00b204e9800998ecf8427e.css", asset_path(:application, "css")
+
+ assert_equal "/assets/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("style", "css")
+ assert_equal "/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css", asset_path("dir/style.css", "css")
+ assert_equal "/dir/style.css", asset_path("/dir/style.css", "css")
+
+ assert_equal "http://www.example.com/css/style",
+ asset_path("http://www.example.com/css/style", "css")
+ assert_equal "http://www.example.com/css/style.css",
+ asset_path("http://www.example.com/css/style.css", "css")
+ end
+
+ test "stylesheet link tag" do
+ assert_equal '<link href="/assets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag(:application)
+
+ assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style")
+ assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style.css")
+
+ assert_equal '<link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("http://www.example.com/style.css")
+ assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style", :media => "all")
+ assert_equal '<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />',
+ sprockets_stylesheet_link_tag("style", :media => "print")
+ end
+end
diff --git a/actionpack/test/template/streaming_render_test.rb b/actionpack/test/template/streaming_render_test.rb
new file mode 100644
index 0000000000..4d69081570
--- /dev/null
+++ b/actionpack/test/template/streaming_render_test.rb
@@ -0,0 +1,105 @@
+# encoding: utf-8
+require 'abstract_unit'
+require 'controller/fake_models'
+
+class TestController < ActionController::Base
+end
+
+class FiberedTest < ActiveSupport::TestCase
+ def setup
+ view_paths = ActionController::Base.view_paths
+ @assigns = { :secret => 'in the sauce' }
+ @view = ActionView::Base.new(view_paths, @assigns)
+ @controller_view = TestController.new.view_context
+ end
+
+ def buffered_render(options)
+ body = @view.render_body(options)
+ string = ""
+ body.each do |piece|
+ string << piece
+ end
+ string
+ end
+
+ def test_streaming_works
+ content = []
+ body = @view.render_body(:template => "test/hello_world.erb", :layout => "layouts/yield")
+
+ body.each do |piece|
+ content << piece
+ end
+
+ assert_equal "<title>", content[0]
+ assert_equal "", content[1]
+ assert_equal "</title>\n", content[2]
+ assert_equal "Hello world!", content[3]
+ assert_equal "\n", content[4]
+ end
+
+ def test_render_file
+ assert_equal "Hello world!", buffered_render(:file => "test/hello_world.erb")
+ end
+
+ def test_render_file_with_locals
+ locals = { :secret => 'in the sauce' }
+ assert_equal "The secret is in the sauce\n", buffered_render(:file => "test/render_file_with_locals.erb", :locals => locals)
+ end
+
+ def test_render_partial
+ assert_equal "only partial", buffered_render(:partial => "test/partial_only")
+ end
+
+ def test_render_inline
+ assert_equal "Hello, World!", buffered_render(:inline => "Hello, World!")
+ end
+
+ def test_render_without_layout
+ assert_equal "Hello world!", buffered_render(:template => "test/hello_world")
+ end
+
+ def test_render_with_layout
+ assert_equal %(<title></title>\nHello world!\n),
+ buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield")
+ end
+
+ def test_render_with_layout_which_has_render_inline
+ assert_equal %(welcome\nHello world!\n),
+ buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
+ end
+
+ def test_render_with_layout_which_renders_another_partial
+ assert_equal %(partial html\nHello world!\n),
+ buffered_render(:template => "test/hello_world.erb", :layout => "layouts/yield_with_render_partial_inside")
+ end
+
+ def test_render_with_nested_layout
+ assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
+ buffered_render(:template => "test/nested_layout.erb", :layout => "layouts/yield")
+ end
+
+ def test_render_with_file_in_layout
+ assert_equal %(\n<title>title</title>\n\n),
+ buffered_render(:template => "test/layout_render_file.erb")
+ end
+
+ def test_render_with_handler_without_streaming_support
+ assert_match "<p>This is grand!</p>", buffered_render(:template => "test/hello")
+ end
+
+ def test_render_with_streaming_multiple_yields_provide_and_content_for
+ assert_equal "Yes, \nthis works\n like a charm.",
+ buffered_render(:template => "test/streaming", :layout => "layouts/streaming")
+ end
+
+ def test_render_with_streaming_with_fake_yields_and_streaming_buster
+ assert_equal "This won't look\n good.",
+ buffered_render(:template => "test/streaming_buster", :layout => "layouts/streaming")
+ end
+
+ def test_render_with_nested_streaming_multiple_yields_provide_and_content_for
+ assert_equal "?Yes, \n\nthis works\n\n? like a charm.",
+ buffered_render(:template => "test/nested_streaming", :layout => "layouts/streaming")
+ end
+
+end if defined?(Fiber) \ No newline at end of file
diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb
index 3432a02c3c..5c655d5b69 100644
--- a/actionpack/test/template/template_test.rb
+++ b/actionpack/test/template/template_test.rb
@@ -113,44 +113,6 @@ class TestERBTemplate < ActiveSupport::TestCase
end
end
- def test_template_expire_sets_the_timestamp_to_1970
- @template = new_template("Hello", :updated_at => Time.utc(2010))
- assert_equal Time.utc(2010), @template.updated_at
- @template.expire!
- assert_equal Time.utc(1970), @template.updated_at
- end
-
- def test_template_rerender_renders_a_template_like_self
- @template = new_template("Hello", :virtual_path => "test/foo_bar")
- @context.expects(:render).with(:template => "test/foo_bar").returns("template")
- assert_equal "template", @template.rerender(@context)
- end
-
- def test_template_rerender_renders_a_root_template_like_self
- @template = new_template("Hello", :virtual_path => "foo_bar")
- @context.expects(:render).with(:template => "foo_bar").returns("template")
- assert_equal "template", @template.rerender(@context)
- end
-
- def test_template_rerender_renders_a_partial_like_self
- @template = new_template("Hello", :virtual_path => "test/_foo_bar")
- @context.expects(:render).with(:partial => "test/foo_bar").returns("partial")
- assert_equal "partial", @template.rerender(@context)
- end
-
- def test_template_rerender_renders_a_root_partial_like_self
- @template = new_template("Hello", :virtual_path => "_foo_bar")
- @context.expects(:render).with(:partial => "foo_bar").returns("partial")
- assert_equal "partial", @template.rerender(@context)
- end
-
- def test_rerender_raises_an_error_without_virtual_path
- @template = new_template("Hello", :virtual_path => nil)
- assert_raise RuntimeError do
- @template.rerender(@context)
- end
- end
-
if "ruby".encoding_aware?
def test_resulting_string_is_utf8
@template = new_template
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index d0d4286393..a4fcff5167 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -315,14 +315,20 @@ class TextHelperTest < ActionView::TestCase
end
end
- def test_auto_link_should_be_html_safe
+ def test_auto_link_should_not_be_html_safe
email_raw = 'santiago@wyeworks.com'
link_raw = 'http://www.rubyonrails.org'
- assert auto_link(nil).html_safe?
- assert auto_link('').html_safe?
- assert auto_link("#{link_raw} #{link_raw} #{link_raw}").html_safe?
- assert auto_link("hello #{email_raw}").html_safe?
+ assert !auto_link(nil).html_safe?, 'should not be html safe'
+ assert !auto_link('').html_safe?, 'should not be html safe'
+ assert !auto_link("#{link_raw} #{link_raw} #{link_raw}").html_safe?, 'should not be html safe'
+ assert !auto_link("hello #{email_raw}").html_safe?, 'should not be html safe'
+ end
+
+ def test_auto_link_email_address
+ email_raw = 'aaron@tenderlovemaking.com'
+ email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
+ assert !auto_link_email_addresses(email_result).html_safe?, 'should not be html safe'
end
def test_auto_link