actionpack 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +309 -16
- data/README +1 -1
- data/lib/action_controller.rb +5 -0
- data/lib/action_controller/assertions.rb +57 -12
- data/lib/action_controller/auto_complete.rb +47 -0
- data/lib/action_controller/base.rb +288 -258
- data/lib/action_controller/benchmarking.rb +8 -3
- data/lib/action_controller/caching.rb +88 -42
- data/lib/action_controller/cgi_ext/cgi_ext.rb +1 -1
- data/lib/action_controller/cgi_ext/cgi_methods.rb +41 -11
- data/lib/action_controller/cgi_ext/multipart_progress.rb +169 -0
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +30 -12
- data/lib/action_controller/cgi_process.rb +39 -11
- data/lib/action_controller/code_generation.rb +235 -0
- data/lib/action_controller/cookies.rb +14 -8
- data/lib/action_controller/deprecated_renders_and_redirects.rb +76 -0
- data/lib/action_controller/filters.rb +8 -7
- data/lib/action_controller/helpers.rb +41 -6
- data/lib/action_controller/layout.rb +45 -16
- data/lib/action_controller/request.rb +86 -23
- data/lib/action_controller/rescue.rb +1 -0
- data/lib/action_controller/response.rb +1 -1
- data/lib/action_controller/routing.rb +536 -272
- data/lib/action_controller/scaffolding.rb +30 -25
- data/lib/action_controller/session/active_record_store.rb +251 -50
- data/lib/action_controller/streaming.rb +133 -0
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/edit.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/layout.rhtml +22 -18
- data/lib/action_controller/templates/scaffolds/list.rhtml +3 -3
- data/lib/action_controller/templates/scaffolds/new.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/show.rhtml +1 -1
- data/lib/action_controller/test_process.rb +68 -47
- data/lib/action_controller/upload_progress.rb +421 -0
- data/lib/action_controller/url_rewriter.rb +8 -11
- data/lib/action_controller/vendor/html-scanner/html/document.rb +6 -5
- data/lib/action_controller/vendor/html-scanner/html/node.rb +70 -14
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +17 -10
- data/lib/action_controller/vendor/html-scanner/html/version.rb +3 -3
- data/lib/action_controller/vendor/xml_simple.rb +1019 -0
- data/lib/action_controller/verification.rb +36 -30
- data/lib/action_view/base.rb +21 -14
- data/lib/action_view/helpers/active_record_helper.rb +15 -13
- data/lib/action_view/helpers/asset_tag_helper.rb +26 -9
- data/lib/action_view/helpers/benchmark_helper.rb +24 -0
- data/lib/action_view/helpers/capture_helper.rb +7 -5
- data/lib/action_view/helpers/date_helper.rb +63 -46
- data/lib/action_view/helpers/form_helper.rb +7 -1
- data/lib/action_view/helpers/form_options_helper.rb +19 -11
- data/lib/action_view/helpers/form_tag_helper.rb +5 -1
- data/lib/action_view/helpers/javascript_helper.rb +403 -35
- data/lib/action_view/helpers/javascripts/controls.js +261 -0
- data/lib/action_view/helpers/javascripts/dragdrop.js +476 -0
- data/lib/action_view/helpers/javascripts/effects.js +570 -0
- data/lib/action_view/helpers/javascripts/prototype.js +633 -371
- data/lib/action_view/helpers/number_helper.rb +11 -13
- data/lib/action_view/helpers/tag_helper.rb +1 -2
- data/lib/action_view/helpers/text_helper.rb +69 -6
- data/lib/action_view/helpers/upload_progress_helper.rb +433 -0
- data/lib/action_view/helpers/url_helper.rb +98 -3
- data/lib/action_view/partials.rb +14 -8
- data/lib/action_view/vendor/builder/xmlmarkup.rb +11 -0
- data/rakefile +13 -5
- data/test/abstract_unit.rb +1 -1
- data/test/controller/action_pack_assertions_test.rb +52 -9
- data/test/controller/active_record_assertions_test.rb +119 -120
- data/test/controller/active_record_store_test.rb +111 -0
- data/test/controller/addresses_render_test.rb +45 -0
- data/test/controller/caching_filestore.rb +92 -0
- data/test/controller/capture_test.rb +39 -0
- data/test/controller/cgi_test.rb +40 -3
- data/test/controller/helper_test.rb +65 -13
- data/test/controller/multipart_progress_testx.rb +365 -0
- data/test/controller/new_render_test.rb +263 -0
- data/test/controller/redirect_test.rb +64 -0
- data/test/controller/render_test.rb +20 -21
- data/test/controller/request_test.rb +83 -3
- data/test/controller/routing_test.rb +702 -0
- data/test/controller/send_file_test.rb +2 -0
- data/test/controller/test_test.rb +44 -8
- data/test/controller/upload_progress_testx.rb +89 -0
- data/test/controller/verification_test.rb +94 -29
- data/test/fixtures/addresses/list.rhtml +1 -0
- data/test/fixtures/test/capturing.rhtml +4 -0
- data/test/fixtures/test/list.rhtml +1 -1
- data/test/fixtures/test/update_element_with_capture.rhtml +9 -0
- data/test/template/active_record_helper_test.rb +30 -15
- data/test/template/asset_tag_helper_test.rb +12 -5
- data/test/template/benchmark_helper_test.rb +72 -0
- data/test/template/date_helper_test.rb +69 -0
- data/test/template/form_helper_test.rb +18 -10
- data/test/template/form_options_helper_test.rb +40 -5
- data/test/template/javascript_helper.rb +149 -2
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +4 -0
- data/test/template/text_helper_test.rb +36 -0
- data/test/template/upload_progress_helper_testx.rb +272 -0
- data/test/template/url_helper_test.rb +30 -0
- metadata +30 -6
- data/test/controller/layout_test.rb +0 -49
- data/test/controller/routing_tests.rb +0 -543
@@ -1,9 +1,156 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
2
|
|
3
|
-
class
|
4
|
-
include ActionView::Helpers::
|
3
|
+
class JavaScriptHelperTest < Test::Unit::TestCase
|
4
|
+
include ActionView::Helpers::JavaScriptHelper
|
5
|
+
|
6
|
+
include ActionView::Helpers::UrlHelper
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
include ActionView::Helpers::TextHelper
|
9
|
+
include ActionView::Helpers::FormHelper
|
10
|
+
include ActionView::Helpers::CaptureHelper
|
11
|
+
|
12
|
+
def setup
|
13
|
+
@controller = Class.new do
|
14
|
+
def url_for(options, *parameters_for_method_reference)
|
15
|
+
url = "http://www.example.com/"
|
16
|
+
url << options[:action].to_s if options and options[:action]
|
17
|
+
url
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@controller = @controller.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_define_javascript_functions
|
24
|
+
# check if prototype.js is included first
|
25
|
+
assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
|
26
|
+
end
|
5
27
|
|
6
28
|
def test_escape_javascript
|
7
29
|
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
8
30
|
end
|
31
|
+
|
32
|
+
def test_link_to_function
|
33
|
+
assert_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
34
|
+
link_to_function("Greeting", "alert('Hello world!')")
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_link_to_remote
|
38
|
+
assert_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {evalScripts:true, asynchronous:true}); return false;\">Remote outpost</a>),
|
39
|
+
link_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
|
40
|
+
assert_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {onComplete:function(request){alert(request.reponseText)}, evalScripts:true, asynchronous:true}); return false;\">Remote outpost</a>),
|
41
|
+
link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_periodically_call_remote
|
45
|
+
assert_equal %(<script>new PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {evalScripts:true, asynchronous:true})}, 10)</script>),
|
46
|
+
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_form_remote_tag
|
50
|
+
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
|
51
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
|
52
|
+
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
|
53
|
+
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast })
|
54
|
+
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
|
55
|
+
form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast })
|
56
|
+
assert_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer',failure:'glass_of_water'}, 'http://www.example.com/fast', {parameters:Form.serialize(this), evalScripts:true, asynchronous:true}); return false;\">),
|
57
|
+
form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast })
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_submit_to_remote
|
61
|
+
assert_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {parameters:Form.serialize(this.form), evalScripts:true, asynchronous:true}); return false;\" type=\"button\" value=\"1000000\" />),
|
62
|
+
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_observe_field
|
66
|
+
assert_equal %(<script type=\"text/javascript\">new Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {evalScripts:true, asynchronous:true})})</script>),
|
67
|
+
observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_observe_form
|
71
|
+
assert_equal %(<script type=\"text/javascript\">new Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {evalScripts:true, asynchronous:true})})</script>),
|
72
|
+
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_auto_complete_field
|
76
|
+
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})</script>),
|
77
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" });
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_auto_complete_result
|
81
|
+
result = [ { :title => 'test1' }, { :title => 'test2' } ]
|
82
|
+
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
|
83
|
+
auto_complete_result(result, :title)
|
84
|
+
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
|
85
|
+
auto_complete_result(result, :title, "est")
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_text_field_with_auto_complete
|
89
|
+
assert_match "<style>",
|
90
|
+
text_field_with_auto_complete(:message, :recipient)
|
91
|
+
assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" value=\"\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})</script>),
|
92
|
+
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_effect
|
96
|
+
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, "posts")
|
97
|
+
assert_equal "new Effect.Highlight('posts',{});", visual_effect("highlight", :posts)
|
98
|
+
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, :posts)
|
99
|
+
assert_equal "new Effect.Fade('fademe',{duration:4.0});", visual_effect(:fade, "fademe", :duration => 4.0)
|
100
|
+
assert_equal "new Effect.Shake(element,{});", visual_effect(:shake)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_sortable_element
|
104
|
+
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
105
|
+
sortable_element("mylist", :url => { :action => "order" })
|
106
|
+
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {tag:'div', constraint:'horizontal', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
107
|
+
sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
|
108
|
+
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:['list1','list2'], onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
109
|
+
sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
|
110
|
+
assert_equal %(<script type=\"text/javascript\">Sortable.create('mylist', {constraint:'horizontal', containment:'list1', onUpdate:function(){new Ajax.Request('http://www.example.com/order', {parameters:Sortable.serialize('mylist'), evalScripts:true, asynchronous:true})}})</script>),
|
111
|
+
sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_draggable_element
|
115
|
+
assert_equal %(<script type=\"text/javascript\">new Draggable('product_13', {})</script>),
|
116
|
+
draggable_element('product_13')
|
117
|
+
assert_equal %(<script type=\"text/javascript\">new Draggable('product_13', {revert:true})</script>),
|
118
|
+
draggable_element('product_13', :revert => true)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_drop_receiving_element
|
122
|
+
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
123
|
+
drop_receiving_element('droptarget1')
|
124
|
+
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Request('http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
125
|
+
drop_receiving_element('droptarget1', :accept => 'products')
|
126
|
+
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:'products', onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
127
|
+
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
|
128
|
+
assert_equal %(<script type=\"text/javascript\">Droppables.add('droptarget1', {accept:['tshirts','mugs'], onDrop:function(element){new Ajax.Updater('infobox', 'http://www.example.com/', {parameters:'id=' + encodeURIComponent(element.id), evalScripts:true, asynchronous:true})}})</script>),
|
129
|
+
drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox')
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_update_element_function
|
133
|
+
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
134
|
+
update_element_function('myelement', :content => 'blub')
|
135
|
+
assert_equal %($('myelement').innerHTML = 'blub';\n),
|
136
|
+
update_element_function('myelement', :action => :update, :content => 'blub')
|
137
|
+
assert_equal %($('myelement').innerHTML = '';\n),
|
138
|
+
update_element_function('myelement', :action => :empty)
|
139
|
+
assert_equal %(Element.remove('myelement');\n),
|
140
|
+
update_element_function('myelement', :action => :remove)
|
141
|
+
|
142
|
+
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
143
|
+
update_element_function('myelement', :position => 'bottom', :content => 'blub')
|
144
|
+
assert_equal %(new Insertion.Bottom('myelement','blub');\n),
|
145
|
+
update_element_function('myelement', :action => :update, :position => :bottom, :content => 'blub')
|
146
|
+
|
147
|
+
_erbout = ""
|
148
|
+
assert_equal %($('myelement').innerHTML = 'test';\n),
|
149
|
+
update_element_function('myelement') { _erbout << "test" }
|
150
|
+
|
151
|
+
_erbout = ""
|
152
|
+
assert_equal %($('myelement').innerHTML = 'blockstuff';\n),
|
153
|
+
update_element_function('myelement', :content => 'paramstuff') { _erbout << "blockstuff" }
|
154
|
+
end
|
155
|
+
|
9
156
|
end
|
@@ -11,6 +11,8 @@ class NumberHelperTest < Test::Unit::TestCase
|
|
11
11
|
assert_equal("123-555-1234", number_to_phone(1235551234))
|
12
12
|
assert_equal("(123) 555-1234", number_to_phone(1235551234, {:area_code => true}))
|
13
13
|
assert_equal("123 555 1234", number_to_phone(1235551234, {:delimiter => " "}))
|
14
|
+
assert_equal("(123) 555-1234 x 555", number_to_phone(1235551234, {:area_code => true, :extension => 555}))
|
15
|
+
assert_equal("123-555-1234", number_to_phone(1235551234, :extension => " "))
|
14
16
|
end
|
15
17
|
|
16
18
|
def test_number_to_currency
|
@@ -12,6 +12,10 @@ class TagHelperTest < Test::Unit::TestCase
|
|
12
12
|
assert_equal tag("p", "class" => "show"), tag("p", :class => "show")
|
13
13
|
end
|
14
14
|
|
15
|
+
def test_tag_options
|
16
|
+
assert_equal "<p class=\"elsewhere\" />", tag("p", "class" => "show", :class => "elsewhere")
|
17
|
+
end
|
18
|
+
|
15
19
|
def test_content_tag
|
16
20
|
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
|
17
21
|
assert_equal content_tag("a", "Create", "href" => "create"),
|
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/cor
|
|
4
4
|
|
5
5
|
class TextHelperTest < Test::Unit::TestCase
|
6
6
|
include ActionView::Helpers::TextHelper
|
7
|
+
include ActionView::Helpers::TagHelper
|
7
8
|
|
8
9
|
def test_simple_format
|
9
10
|
assert_equal "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", simple_format("crazy\r\n cross\r platform linebreaks")
|
@@ -35,6 +36,11 @@ class TextHelperTest < Test::Unit::TestCase
|
|
35
36
|
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
|
36
37
|
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\1</b>')
|
37
38
|
)
|
39
|
+
|
40
|
+
assert_equal(
|
41
|
+
"This text is not changed because we supplied an empty phrase",
|
42
|
+
highlight("This text is not changed because we supplied an empty phrase", nil)
|
43
|
+
)
|
38
44
|
end
|
39
45
|
|
40
46
|
def test_highlighter_with_regexp
|
@@ -61,6 +67,10 @@ class TextHelperTest < Test::Unit::TestCase
|
|
61
67
|
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
|
62
68
|
assert_nil excerpt("This is a beautiful morning", "day")
|
63
69
|
end
|
70
|
+
|
71
|
+
def test_word_wrap
|
72
|
+
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
|
73
|
+
end
|
64
74
|
|
65
75
|
def test_pluralization
|
66
76
|
assert_equal("1 count", pluralize(1, "count"))
|
@@ -72,6 +82,7 @@ class TextHelperTest < Test::Unit::TestCase
|
|
72
82
|
email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
|
73
83
|
link_raw = 'http://www.rubyonrails.com'
|
74
84
|
link_result = %{<a href="#{link_raw}">#{link_raw}</a>}
|
85
|
+
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
|
75
86
|
link2_raw = 'www.rubyonrails.com'
|
76
87
|
link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
|
77
88
|
|
@@ -85,6 +96,31 @@ class TextHelperTest < Test::Unit::TestCase
|
|
85
96
|
assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses)
|
86
97
|
assert_equal %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
|
87
98
|
assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
|
99
|
+
assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_sanitize_form
|
103
|
+
raw = "<form action=\"/foo/bar\" method=\"post\"><input></form>"
|
104
|
+
result = sanitize(raw)
|
105
|
+
assert_equal "<form action='/foo/bar' method='post'><input></form>", result
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_sanitize_script
|
109
|
+
raw = "<script language=\"Javascript\">blah blah blah</script>"
|
110
|
+
result = sanitize(raw)
|
111
|
+
assert_equal "<script language='Javascript'>blah blah blah</script>", result
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_sanitize_js_handlers
|
115
|
+
raw = %{onthis="do that" <a href="#" onclick="hello" name="foo" onbogus="remove me">hello</a>}
|
116
|
+
result = sanitize(raw)
|
117
|
+
assert_equal %{onthis="do that" <a name='foo' href='#'>hello</a>}, result
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_sanitize_javascript_href
|
121
|
+
raw = %{href="javascript:bang" <a href="javascript:bang" name="hello">foo</a>, <span href="javascript:bang">bar</span>}
|
122
|
+
result = sanitize(raw)
|
123
|
+
assert_equal %{href="javascript:bang" <a name='hello'>foo</a>, <span>bar</span>}, result
|
88
124
|
end
|
89
125
|
|
90
126
|
end
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
4
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/number_helper'
|
5
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/asset_tag_helper'
|
6
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
|
7
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
|
8
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/javascript_helper'
|
9
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/upload_progress_helper'
|
10
|
+
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' #for stringify keys
|
11
|
+
|
12
|
+
class MockProgress
|
13
|
+
def initialize(started, finished)
|
14
|
+
@started, @finished = [started, finished]
|
15
|
+
end
|
16
|
+
|
17
|
+
def started?
|
18
|
+
@started
|
19
|
+
end
|
20
|
+
|
21
|
+
def finished?
|
22
|
+
@finished
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
"A message"
|
27
|
+
end
|
28
|
+
|
29
|
+
def method_missing(meth, *args)
|
30
|
+
# Just return some consitant number
|
31
|
+
meth.to_s.hash.to_i.abs + args.hash.to_i.abs
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class UploadProgressHelperTest < Test::Unit::TestCase
|
36
|
+
include ActionView::Helpers::DateHelper
|
37
|
+
include ActionView::Helpers::NumberHelper
|
38
|
+
include ActionView::Helpers::AssetTagHelper
|
39
|
+
include ActionView::Helpers::FormTagHelper
|
40
|
+
include ActionView::Helpers::TagHelper
|
41
|
+
include ActionView::Helpers::UrlHelper
|
42
|
+
include ActionView::Helpers::JavaScriptHelper
|
43
|
+
include ActionView::Helpers::UploadProgressHelper
|
44
|
+
|
45
|
+
def next_upload_id; @upload_id = last_upload_id.succ; end
|
46
|
+
def last_upload_id; @upload_id ||= 0; end
|
47
|
+
def current_upload_id; last_upload_id; end
|
48
|
+
def upload_progress(upload_id = nil); @upload_progress or MockProgress.new(false, true); end
|
49
|
+
|
50
|
+
def setup
|
51
|
+
@controller = Class.new do
|
52
|
+
def url_for(options, *parameters_for_method_reference)
|
53
|
+
"http://www.example.com"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@controller = @controller.new
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_upload_status_tag
|
60
|
+
assert_equal(
|
61
|
+
'<div class="progressBar" id="UploadProgressBar0"><div class="border"><div class="background"><div class="foreground"></div></div></div></div><div class="uploadStatus" id="UploadStatus0"></div>',
|
62
|
+
upload_status_tag
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_upload_status_text_tag
|
67
|
+
assert_equal(
|
68
|
+
'<div class="my-upload" id="my-id">Starting</div>',
|
69
|
+
upload_status_text_tag('Starting', :class => 'my-upload', :id => 'my-id')
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def test_upload_progress_text
|
75
|
+
@upload_progress = MockProgress.new(false, false)
|
76
|
+
assert_equal(
|
77
|
+
"Upload starting...",
|
78
|
+
upload_progress_text
|
79
|
+
)
|
80
|
+
|
81
|
+
@upload_progress = MockProgress.new(true, false)
|
82
|
+
assert_equal(
|
83
|
+
"828.7 MB of 456.2 MB at 990.1 MB/s; 10227 days remaining",
|
84
|
+
upload_progress_text
|
85
|
+
)
|
86
|
+
|
87
|
+
@upload_progress = MockProgress.new(true, true)
|
88
|
+
assert_equal(
|
89
|
+
"Upload finished. A message",
|
90
|
+
upload_progress_text
|
91
|
+
)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_upload_progress_update_bar_js
|
95
|
+
assert_equal(
|
96
|
+
"$('UploadProgressBar0').firstChild.firstChild.style.width='0%';",
|
97
|
+
upload_progress_update_bar_js
|
98
|
+
)
|
99
|
+
|
100
|
+
assert_equal(
|
101
|
+
"$('UploadProgressBar0').firstChild.firstChild.style.width='50%';",
|
102
|
+
upload_progress_update_bar_js(50)
|
103
|
+
)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_finish_upload_status
|
107
|
+
assert_equal(
|
108
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
109
|
+
finish_upload_status
|
110
|
+
)
|
111
|
+
|
112
|
+
assert_equal(
|
113
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop(123);\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
114
|
+
finish_upload_status(:client_js_argument => 123)
|
115
|
+
)
|
116
|
+
|
117
|
+
assert_equal(
|
118
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\nparent.location.replace('/redirected/');\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
119
|
+
finish_upload_status(:redirect_to => '/redirected/')
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_form_tag_with_upload_progress
|
124
|
+
assert_equal(
|
125
|
+
"<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=1'; }this.target = 'UploadTarget1';$('UploadProgressBar1').firstChild.firstChild.style.width='0%';; document.uploadStatus1 = new Ajax.PeriodicalUpdater('UploadStatus1','http://www.example.com',{script:true, onComplete:function(request){$('UploadProgressBar1').firstChild.firstChild.style.width='100%';; }, asynchronous:true}.extend({decay:1.8,frequency:2.0})); return true\"><iframe id=\"UploadTarget1\" name=\"UploadTarget1\" src=\"\" style=\"width:0px;height:0px;border:0\"></iframe>",
|
126
|
+
form_tag_with_upload_progress
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_form_tag_with_upload_progress_custom
|
131
|
+
assert_equal(
|
132
|
+
"<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=5'; }this.target = 'awindow';$('UploadProgressBar0').firstChild.firstChild.style.width='0%';; alert('foo'); document.uploadStatus0 = new Ajax.PeriodicalUpdater('UploadStatus0','http://www.example.com',{script:true, onComplete:function(request){$('UploadProgressBar0').firstChild.firstChild.style.width='100%';; alert('bar'); alert('bar')}, asynchronous:true}.extend({decay:7,frequency:6})); return true\" target=\"awindow\">",
|
133
|
+
form_tag_with_upload_progress({:upload_id => 5}, {:begin => "alert('foo')", :finish => "alert('bar')", :frequency => 6, :decay => 7, :target => 'awindow'})
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
138
|
+
|
139
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/date_helper'
|
140
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/number_helper'
|
141
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/asset_tag_helper'
|
142
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/form_tag_helper'
|
143
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/tag_helper'
|
144
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/javascript_helper'
|
145
|
+
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/upload_progress_helper'
|
146
|
+
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' #for stringify keys
|
147
|
+
|
148
|
+
class MockProgress
|
149
|
+
def initialize(started, finished)
|
150
|
+
@started, @finished = [started, finished]
|
151
|
+
end
|
152
|
+
|
153
|
+
def started?
|
154
|
+
@started
|
155
|
+
end
|
156
|
+
|
157
|
+
def finished?
|
158
|
+
@finished
|
159
|
+
end
|
160
|
+
|
161
|
+
def message
|
162
|
+
"A message"
|
163
|
+
end
|
164
|
+
|
165
|
+
def method_missing(meth, *args)
|
166
|
+
# Just return some consitant number
|
167
|
+
meth.to_s.hash.to_i.abs + args.hash.to_i.abs
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class UploadProgressHelperTest < Test::Unit::TestCase
|
172
|
+
include ActionView::Helpers::DateHelper
|
173
|
+
include ActionView::Helpers::NumberHelper
|
174
|
+
include ActionView::Helpers::AssetTagHelper
|
175
|
+
include ActionView::Helpers::FormTagHelper
|
176
|
+
include ActionView::Helpers::TagHelper
|
177
|
+
include ActionView::Helpers::UrlHelper
|
178
|
+
include ActionView::Helpers::JavaScriptHelper
|
179
|
+
include ActionView::Helpers::UploadProgressHelper
|
180
|
+
|
181
|
+
def next_upload_id; @upload_id = last_upload_id.succ; end
|
182
|
+
def last_upload_id; @upload_id ||= 0; end
|
183
|
+
def current_upload_id; last_upload_id; end
|
184
|
+
def upload_progress(upload_id = nil); @upload_progress ||= MockProgress.new(false, true); end
|
185
|
+
|
186
|
+
def setup
|
187
|
+
@controller = Class.new do
|
188
|
+
def url_for(options, *parameters_for_method_reference)
|
189
|
+
"http://www.example.com"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
@controller = @controller.new
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_upload_status_tag
|
196
|
+
assert_equal(
|
197
|
+
'<div class="progressBar" id="UploadProgressBar0"><div class="border"><div class="background"><div class="foreground"></div></div></div></div><div class="uploadStatus" id="UploadStatus0"></div>',
|
198
|
+
upload_status_tag
|
199
|
+
)
|
200
|
+
end
|
201
|
+
|
202
|
+
def test_upload_status_text_tag
|
203
|
+
assert_equal(
|
204
|
+
'<div class="my-upload" id="my-id">Starting</div>',
|
205
|
+
upload_status_text_tag('Starting', :class => 'my-upload', :id => 'my-id')
|
206
|
+
)
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
def test_upload_progress_text
|
211
|
+
@upload_progress = MockProgress.new(false, false)
|
212
|
+
assert_equal(
|
213
|
+
"Upload starting...",
|
214
|
+
upload_progress_text
|
215
|
+
)
|
216
|
+
|
217
|
+
@upload_progress = MockProgress.new(true, false)
|
218
|
+
assert_equal(
|
219
|
+
"828.7 MB of 456.2 MB at 990.1 MB/s; 10227 days remaining",
|
220
|
+
upload_progress_text
|
221
|
+
)
|
222
|
+
|
223
|
+
@upload_progress = MockProgress.new(true, true)
|
224
|
+
assert_equal(
|
225
|
+
"A message",
|
226
|
+
upload_progress_text
|
227
|
+
)
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_upload_progress_update_bar_js
|
231
|
+
assert_equal(
|
232
|
+
"$('UploadProgressBar0').firstChild.firstChild.style.width='0%'",
|
233
|
+
upload_progress_update_bar_js
|
234
|
+
)
|
235
|
+
|
236
|
+
assert_equal(
|
237
|
+
"$('UploadProgressBar0').firstChild.firstChild.style.width='50%'",
|
238
|
+
upload_progress_update_bar_js(50)
|
239
|
+
)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_finish_upload_status
|
243
|
+
assert_equal(
|
244
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
245
|
+
finish_upload_status
|
246
|
+
)
|
247
|
+
|
248
|
+
assert_equal(
|
249
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop(123);\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
250
|
+
finish_upload_status(:client_js_argument => 123)
|
251
|
+
)
|
252
|
+
|
253
|
+
assert_equal(
|
254
|
+
"<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\nparent.location.replace('/redirected/');\n }\n }</script></head><body onload=\"finish()\"></body></html>",
|
255
|
+
finish_upload_status(:redirect_to => '/redirected/')
|
256
|
+
)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_form_tag_with_upload_progress
|
260
|
+
assert_equal(
|
261
|
+
"<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=1'; }this.target = 'UploadTarget1';$('UploadStatus1').innerHTML='Upload starting...'; $('UploadProgressBar1').firstChild.firstChild.style.width='0%'; if (document.uploadStatus1) { document.uploadStatus1.stop(); }document.uploadStatus1 = new Ajax.PeriodicalUpdater('UploadStatus1','http://www.example.com', {onComplete:function(request){$('UploadStatus1').innerHTML='A message';$('UploadProgressBar1').firstChild.firstChild.style.width='100%';document.uploadStatus1 = null}, evalScripts:true, asynchronous:true}.extend({decay:1.8,frequency:2.0})); return true\"><iframe id=\"UploadTarget1\" name=\"UploadTarget1\" src=\"\" style=\"width:0px;height:0px;border:0\"></iframe>",
|
262
|
+
form_tag_with_upload_progress
|
263
|
+
)
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_form_tag_with_upload_progress_custom
|
267
|
+
assert_equal(
|
268
|
+
"<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=5'; }this.target = 'awindow';$('UploadStatus0').innerHTML='Upload starting...'; $('UploadProgressBar0').firstChild.firstChild.style.width='0%'; alert('foo'); if (document.uploadStatus0) { document.uploadStatus0.stop(); }document.uploadStatus0 = new Ajax.PeriodicalUpdater('UploadStatus0','http://www.example.com', {onComplete:function(request){$('UploadStatus0').innerHTML='A message';$('UploadProgressBar0').firstChild.firstChild.style.width='100%';document.uploadStatus0 = null; alert('bar')}, evalScripts:true, asynchronous:true}.extend({decay:7,frequency:6})); return true\" target=\"awindow\">",
|
269
|
+
form_tag_with_upload_progress({:upload_id => 5}, {:begin => "alert('foo')", :finish => "alert('bar')", :frequency => 6, :decay => 7, :target => 'awindow'})
|
270
|
+
)
|
271
|
+
end
|
272
|
+
end
|