actionpack 1.9.1 → 1.10.1
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 +237 -0
- data/README +12 -12
- data/lib/action_controller.rb +17 -12
- data/lib/action_controller/assertions.rb +119 -67
- data/lib/action_controller/base.rb +184 -102
- data/lib/action_controller/benchmarking.rb +35 -6
- data/lib/action_controller/caching.rb +115 -58
- data/lib/action_controller/cgi_ext/cgi_methods.rb +54 -21
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +39 -35
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +34 -21
- data/lib/action_controller/cgi_process.rb +23 -20
- data/lib/action_controller/components.rb +11 -2
- data/lib/action_controller/dependencies.rb +0 -5
- data/lib/action_controller/deprecated_redirects.rb +17 -0
- data/lib/action_controller/filters.rb +13 -9
- data/lib/action_controller/flash.rb +7 -7
- data/lib/action_controller/helpers.rb +1 -14
- data/lib/action_controller/layout.rb +40 -29
- data/lib/action_controller/macros/auto_complete.rb +52 -0
- data/lib/action_controller/macros/in_place_editing.rb +32 -0
- data/lib/action_controller/pagination.rb +44 -28
- data/lib/action_controller/request.rb +54 -40
- data/lib/action_controller/rescue.rb +8 -6
- data/lib/action_controller/routing.rb +77 -28
- data/lib/action_controller/scaffolding.rb +10 -14
- data/lib/action_controller/session/active_record_store.rb +36 -7
- data/lib/action_controller/session_management.rb +126 -0
- data/lib/action_controller/streaming.rb +14 -5
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +1 -1
- data/lib/action_controller/templates/rescues/_trace.rhtml +24 -0
- data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -13
- data/lib/action_controller/templates/rescues/template_error.rhtml +4 -2
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +35 -17
- data/lib/action_controller/upload_progress.rb +52 -0
- data/lib/action_controller/url_rewriter.rb +21 -16
- data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
- data/lib/action_controller/vendor/html-scanner/html/node.rb +30 -3
- data/lib/action_pack/version.rb +9 -0
- data/lib/action_view.rb +1 -1
- data/lib/action_view/base.rb +204 -60
- data/lib/action_view/compiled_templates.rb +70 -0
- data/lib/action_view/helpers/active_record_helper.rb +7 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +22 -12
- data/lib/action_view/helpers/capture_helper.rb +2 -10
- data/lib/action_view/helpers/date_helper.rb +21 -13
- data/lib/action_view/helpers/form_helper.rb +14 -10
- data/lib/action_view/helpers/form_options_helper.rb +4 -4
- data/lib/action_view/helpers/form_tag_helper.rb +59 -25
- data/lib/action_view/helpers/java_script_macros_helper.rb +188 -0
- data/lib/action_view/helpers/javascript_helper.rb +68 -133
- data/lib/action_view/helpers/javascripts/controls.js +427 -165
- data/lib/action_view/helpers/javascripts/dragdrop.js +256 -277
- data/lib/action_view/helpers/javascripts/effects.js +766 -277
- data/lib/action_view/helpers/javascripts/prototype.js +906 -218
- data/lib/action_view/helpers/javascripts/slider.js +258 -0
- data/lib/action_view/helpers/number_helper.rb +4 -3
- data/lib/action_view/helpers/pagination_helper.rb +42 -27
- data/lib/action_view/helpers/tag_helper.rb +25 -11
- data/lib/action_view/helpers/text_helper.rb +119 -13
- data/lib/action_view/helpers/upload_progress_helper.rb +2 -2
- data/lib/action_view/helpers/url_helper.rb +68 -21
- data/lib/action_view/partials.rb +17 -6
- data/lib/action_view/template_error.rb +19 -24
- data/rakefile +4 -3
- data/test/abstract_unit.rb +2 -1
- data/test/controller/action_pack_assertions_test.rb +62 -2
- data/test/controller/active_record_assertions_test.rb +5 -6
- data/test/controller/active_record_store_test.rb +23 -1
- data/test/controller/addresses_render_test.rb +4 -0
- data/test/controller/{base_tests.rb → base_test.rb} +4 -3
- data/test/controller/benchmark_test.rb +36 -0
- data/test/controller/caching_filestore.rb +22 -40
- data/test/controller/capture_test.rb +10 -1
- data/test/controller/cgi_test.rb +145 -23
- data/test/controller/components_test.rb +50 -0
- data/test/controller/custom_handler_test.rb +3 -3
- data/test/controller/fake_controllers.rb +24 -0
- data/test/controller/filters_test.rb +6 -6
- data/test/controller/flash_test.rb +6 -6
- data/test/controller/fragment_store_setting_test.rb +45 -0
- data/test/controller/helper_test.rb +1 -3
- data/test/controller/new_render_test.rb +119 -7
- data/test/controller/redirect_test.rb +11 -1
- data/test/controller/render_test.rb +34 -1
- data/test/controller/request_test.rb +14 -5
- data/test/controller/routing_test.rb +238 -42
- data/test/controller/send_file_test.rb +11 -10
- data/test/controller/session_management_test.rb +94 -0
- data/test/controller/test_test.rb +194 -5
- data/test/controller/url_rewriter_test.rb +46 -0
- data/test/fixtures/layouts/talk_from_action.rhtml +2 -0
- data/test/fixtures/layouts/yield.rhtml +2 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/large_text_file +10 -0
- data/test/fixtures/multipart/mixed_files +0 -0
- data/test/fixtures/multipart/single_parameter +5 -0
- data/test/fixtures/multipart/text_file +10 -0
- data/test/fixtures/test/_customer_greeting.rhtml +1 -0
- data/test/fixtures/test/_hash_object.rhtml +1 -0
- data/test/fixtures/test/_person.rhtml +2 -0
- data/test/fixtures/test/action_talk_to_layout.rhtml +2 -0
- data/test/fixtures/test/content_for.rhtml +2 -0
- data/test/fixtures/test/potential_conflicts.rhtml +4 -0
- data/test/template/active_record_helper_test.rb +15 -8
- data/test/template/asset_tag_helper_test.rb +40 -16
- data/test/template/compiled_templates_tests.rb +63 -0
- data/test/template/date_helper_test.rb +80 -4
- data/test/template/form_helper_test.rb +48 -42
- data/test/template/form_options_helper_test.rb +40 -40
- data/test/template/form_tag_helper_test.rb +21 -15
- data/test/template/java_script_macros_helper_test.rb +56 -0
- data/test/template/javascript_helper_test.rb +70 -47
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +9 -0
- data/test/template/text_helper_test.rb +146 -1
- data/test/template/upload_progress_helper_testx.rb +11 -147
- data/test/template/url_helper_test.rb +90 -22
- data/test/testing_sandbox.rb +26 -0
- metadata +37 -7
- data/lib/action_controller/auto_complete.rb +0 -47
- data/lib/action_controller/deprecated_renders_and_redirects.rb +0 -76
- data/lib/action_controller/session.rb +0 -14
@@ -18,74 +18,80 @@ class FormTagHelperTest < Test::Unit::TestCase
|
|
18
18
|
def test_check_box_tag
|
19
19
|
actual = check_box_tag "admin"
|
20
20
|
expected = %(<input id="admin" name="admin" type="checkbox" value="1" />)
|
21
|
-
|
21
|
+
assert_dom_equal expected, actual
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_form_tag
|
25
25
|
actual = form_tag
|
26
26
|
expected = %(<form action="http://www.example.com" method="post">)
|
27
|
-
|
27
|
+
assert_dom_equal expected, actual
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_form_tag_multipart
|
31
31
|
actual = form_tag({}, { 'multipart' => true })
|
32
32
|
expected = %(<form action="http://www.example.com" enctype="multipart/form-data" method="post">)
|
33
|
-
|
33
|
+
assert_dom_equal expected, actual
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_hidden_field_tag
|
37
37
|
actual = hidden_field_tag "id", 3
|
38
38
|
expected = %(<input id="id" name="id" type="hidden" value="3" />)
|
39
|
-
|
39
|
+
assert_dom_equal expected, actual
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_password_field_tag
|
43
43
|
actual = password_field_tag
|
44
44
|
expected = %(<input id="password" name="password" type="password" />)
|
45
|
-
|
45
|
+
assert_dom_equal expected, actual
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_radio_button_tag
|
49
49
|
actual = radio_button_tag "people", "david"
|
50
50
|
expected = %(<input id="people" name="people" type="radio" value="david" />)
|
51
|
-
|
51
|
+
assert_dom_equal expected, actual
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_select_tag
|
55
55
|
actual = select_tag "people", "<option>david</option>"
|
56
56
|
expected = %(<select id="people" name="people"><option>david</option></select>)
|
57
|
-
|
57
|
+
assert_dom_equal expected, actual
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_text_area_tag_size_string
|
61
61
|
actual = text_area_tag "body", "hello world", "size" => "20x40"
|
62
62
|
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
|
63
|
-
|
63
|
+
assert_dom_equal expected, actual
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_text_area_tag_size_symbol
|
67
67
|
actual = text_area_tag "body", "hello world", :size => "20x40"
|
68
68
|
expected = %(<textarea cols="20" id="body" name="body" rows="40">hello world</textarea>)
|
69
|
-
|
69
|
+
assert_dom_equal expected, actual
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_text_field_tag
|
73
73
|
actual = text_field_tag "title", "Hello!"
|
74
74
|
expected = %(<input id="title" name="title" type="text" value="Hello!" />)
|
75
|
-
|
75
|
+
assert_dom_equal expected, actual
|
76
76
|
end
|
77
77
|
|
78
78
|
def test_text_field_tag_class_string
|
79
79
|
actual = text_field_tag "title", "Hello!", "class" => "admin"
|
80
80
|
expected = %(<input class="admin" id="title" name="title" type="text" value="Hello!" />)
|
81
|
-
|
81
|
+
assert_dom_equal expected, actual
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_boolean_optios
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
assert_dom_equal %(<input checked="checked" disabled="disabled" id="admin" name="admin" readonly="readonly" type="checkbox" value="1" />), check_box_tag("admin", 1, true, 'disabled' => true, :readonly => "yes")
|
86
|
+
assert_dom_equal %(<input checked="checked" id="admin" name="admin" type="checkbox" value="1" />), check_box_tag("admin", 1, true, :disabled => false, :readonly => nil)
|
87
|
+
assert_dom_equal %(<select id="people" multiple="multiple" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => true)
|
88
|
+
assert_dom_equal %(<select id="people" name="people"><option>david</option></select>), select_tag("people", "<option>david</option>", :multiple => nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_stringify_symbol_keys
|
92
|
+
actual = text_field_tag "title", "Hello!", :id => "admin"
|
93
|
+
expected = %(<input id="admin" name="title" type="text" value="Hello!" />)
|
94
|
+
assert_dom_equal expected, actual
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
|
3
|
+
class JavaScriptMacrosHelperTest < Test::Unit::TestCase
|
4
|
+
include ActionView::Helpers::JavaScriptHelper
|
5
|
+
include ActionView::Helpers::JavaScriptMacrosHelper
|
6
|
+
|
7
|
+
include ActionView::Helpers::UrlHelper
|
8
|
+
include ActionView::Helpers::TagHelper
|
9
|
+
include ActionView::Helpers::TextHelper
|
10
|
+
include ActionView::Helpers::FormHelper
|
11
|
+
include ActionView::Helpers::CaptureHelper
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@controller = Class.new do
|
15
|
+
def url_for(options, *parameters_for_method_reference)
|
16
|
+
url = "http://www.example.com/"
|
17
|
+
url << options[:action].to_s if options and options[:action]
|
18
|
+
url
|
19
|
+
end
|
20
|
+
end
|
21
|
+
@controller = @controller.new
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_auto_complete_field
|
26
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {})\n//]]>\n</script>),
|
27
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" });
|
28
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})\n//]]>\n</script>),
|
29
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
|
30
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})\n//]]>\n</script>),
|
31
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
|
32
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {min_chars:3})\n//]]>\n</script>),
|
33
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :min_chars => 3);
|
34
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {onHide:function(element, update){Alert('me');}})\n//]]>\n</script>),
|
35
|
+
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :on_hide => "function(element, update){Alert('me');}");
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_auto_complete_result
|
39
|
+
result = [ { :title => 'test1' }, { :title => 'test2' } ]
|
40
|
+
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
|
41
|
+
auto_complete_result(result, :title)
|
42
|
+
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
|
43
|
+
auto_complete_result(result, :title, "est")
|
44
|
+
|
45
|
+
resultuniq = [ { :title => 'test1' }, { :title => 'test1' } ]
|
46
|
+
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li></ul>),
|
47
|
+
auto_complete_result(resultuniq, :title, "est")
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_text_field_with_auto_complete
|
51
|
+
assert_match "<style>",
|
52
|
+
text_field_with_auto_complete(:message, :recipient)
|
53
|
+
assert_dom_equal %(<input id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">\n//<![CDATA[\nnew Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})\n//]]>\n</script>),
|
54
|
+
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
55
|
+
end
|
56
|
+
end
|
@@ -23,79 +23,102 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
|
23
23
|
def test_define_javascript_functions
|
24
24
|
# check if prototype.js is included first
|
25
25
|
assert_not_nil define_javascript_functions.split("\n")[1].match(/Prototype JavaScript framework/)
|
26
|
+
|
27
|
+
# check that scriptaculous.js is not in here, only needed if loaded remotely
|
28
|
+
assert_nil define_javascript_functions.split("\n")[1].match(/var Scriptaculous = \{/)
|
26
29
|
end
|
27
30
|
|
28
31
|
def test_escape_javascript
|
29
32
|
assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos'))
|
30
33
|
end
|
31
|
-
|
34
|
+
|
32
35
|
def test_link_to_function
|
33
|
-
|
36
|
+
assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); return false;">Greeting</a>),
|
34
37
|
link_to_function("Greeting", "alert('Hello world!')")
|
35
38
|
end
|
36
39
|
|
37
40
|
def test_link_to_remote
|
38
|
-
|
41
|
+
assert_dom_equal %(<a class=\"fine\" href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true}); return false;\">Remote outpost</a>),
|
39
42
|
link_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
|
40
|
-
|
41
|
-
link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
43
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onComplete:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
44
|
+
link_to_remote("Remote outpost", :complete => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
45
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onSuccess:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
46
|
+
link_to_remote("Remote outpost", :success => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
47
|
+
assert_dom_equal %(<a href=\"#\" onclick=\"new Ajax.Request('http://www.example.com/whatnot', {asynchronous:true, evalScripts:true, onFailure:function(request){alert(request.reponseText)}}); return false;\">Remote outpost</a>),
|
48
|
+
link_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot" })
|
42
49
|
end
|
43
50
|
|
44
51
|
def test_periodically_call_remote
|
45
|
-
|
52
|
+
assert_dom_equal %(<script type="text/javascript">\n//<![CDATA[\nnew PeriodicalExecuter(function() {new Ajax.Updater('schremser_bier', 'http://www.example.com/mehr_bier', {asynchronous:true, evalScripts:true})}, 10)\n//]]>\n</script>),
|
46
53
|
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })
|
47
54
|
end
|
48
55
|
|
49
56
|
def test_form_remote_tag
|
50
|
-
|
57
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
51
58
|
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast })
|
52
|
-
|
59
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
53
60
|
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast })
|
54
|
-
|
61
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_water'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
55
62
|
form_remote_tag(:update => { :failure => "glass_of_water" }, :url => { :action => :fast })
|
56
|
-
|
63
|
+
assert_dom_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', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\">),
|
57
64
|
form_remote_tag(:update => { :success => 'glass_of_beer', :failure => "glass_of_water" }, :url => { :action => :fast })
|
58
65
|
end
|
59
66
|
|
67
|
+
def test_on_callbacks
|
68
|
+
callbacks = [:uninitialized, :loading, :loaded, :interactive, :complete, :success, :failure]
|
69
|
+
callbacks.each do |callback|
|
70
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
71
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
72
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({success:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
73
|
+
form_remote_tag(:update => { :success => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
74
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater({failure:'glass_of_beer'}, 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
75
|
+
form_remote_tag(:update => { :failure => "glass_of_beer" }, :url => { :action => :fast }, callback=>"monkeys();")
|
76
|
+
assert_dom_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', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
77
|
+
form_remote_tag(:update => { :success => "glass_of_beer", :failure => "glass_of_water" }, :url => { :action => :fast }, callback=>"monkeys();")
|
78
|
+
end
|
79
|
+
|
80
|
+
#HTTP status codes 200 up to 599 have callbacks
|
81
|
+
#these should work
|
82
|
+
100.upto(599) do |callback|
|
83
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on#{callback.to_s.capitalize}:function(request){monkeys();}, parameters:Form.serialize(this)}); return false;">),
|
84
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
85
|
+
end
|
86
|
+
|
87
|
+
#test 200 and 404
|
88
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, parameters:Form.serialize(this)}); return false;">),
|
89
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, 200=>"monkeys();", 404=>"bananas();")
|
90
|
+
|
91
|
+
#these shouldn't
|
92
|
+
1.upto(99) do |callback|
|
93
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
94
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
95
|
+
end
|
96
|
+
600.upto(999) do |callback|
|
97
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">),
|
98
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, callback=>"monkeys();")
|
99
|
+
end
|
100
|
+
|
101
|
+
#test ultimate combo
|
102
|
+
assert_dom_equal %(<form action=\"http://www.example.com/fast\" method=\"post\" onsubmit=\"new Ajax.Updater('glass_of_beer', 'http://www.example.com/fast', {asynchronous:true, evalScripts:true, on200:function(request){monkeys();}, on404:function(request){bananas();}, onComplete:function(request){c();}, onFailure:function(request){f();}, onLoading:function(request){c1()}, onSuccess:function(request){s()}, parameters:Form.serialize(this)}); return false;\">),
|
103
|
+
form_remote_tag(:update => "glass_of_beer", :url => { :action => :fast }, :loading => "c1()", :success => "s()", :failure => "f();", :complete => "c();", 200=>"monkeys();", 404=>"bananas();")
|
104
|
+
|
105
|
+
end
|
106
|
+
|
60
107
|
def test_submit_to_remote
|
61
|
-
|
108
|
+
assert_dom_equal %(<input name=\"More beer!\" onclick=\"new Ajax.Updater('empty_bottle', 'http://www.example.com/', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this.form)}); return false;\" type=\"button\" value=\"1000000\" />),
|
62
109
|
submit_to_remote("More beer!", 1_000_000, :update => "empty_bottle")
|
63
110
|
end
|
64
111
|
|
65
112
|
def test_observe_field
|
66
|
-
|
113
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Element.Observer('glass', 300, function(element, value) {new Ajax.Request('http://www.example.com/reorder_if_empty', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>),
|
67
114
|
observe_field("glass", :frequency => 5.minutes, :url => { :action => "reorder_if_empty" })
|
68
115
|
end
|
69
116
|
|
70
117
|
def test_observe_form
|
71
|
-
|
118
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Form.Observer('cart', 2, function(element, value) {new Ajax.Request('http://www.example.com/cart_changed', {asynchronous:true, evalScripts:true})})\n//]]>\n</script>),
|
72
119
|
observe_form("cart", :frequency => 2, :url => { :action => "cart_changed" })
|
73
120
|
end
|
74
121
|
|
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
|
-
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:','})</script>),
|
79
|
-
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => ',');
|
80
|
-
assert_equal %(<script type=\"text/javascript\">new Ajax.Autocompleter('some_input', 'some_input_auto_complete', 'http://www.example.com/autocomplete', {tokens:[',']})</script>),
|
81
|
-
auto_complete_field("some_input", :url => { :action => "autocomplete" }, :tokens => [',']);
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_auto_complete_result
|
85
|
-
result = [ { :title => 'test1' }, { :title => 'test2' } ]
|
86
|
-
assert_equal %(<ul><li>test1</li><li>test2</li></ul>),
|
87
|
-
auto_complete_result(result, :title)
|
88
|
-
assert_equal %(<ul><li>t<strong class=\"highlight\">est</strong>1</li><li>t<strong class=\"highlight\">est</strong>2</li></ul>),
|
89
|
-
auto_complete_result(result, :title, "est")
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_text_field_with_auto_complete
|
93
|
-
assert_match "<style>",
|
94
|
-
text_field_with_auto_complete(:message, :recipient)
|
95
|
-
assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><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>),
|
96
|
-
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
|
97
|
-
end
|
98
|
-
|
99
122
|
def test_effect
|
100
123
|
assert_equal "new Effect.Highlight('posts',{});", visual_effect(:highlight, "posts")
|
101
124
|
assert_equal "new Effect.Highlight('posts',{});", visual_effect("highlight", :posts)
|
@@ -105,31 +128,31 @@ class JavaScriptHelperTest < Test::Unit::TestCase
|
|
105
128
|
end
|
106
129
|
|
107
130
|
def test_sortable_element
|
108
|
-
|
131
|
+
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>),
|
109
132
|
sortable_element("mylist", :url => { :action => "order" })
|
110
|
-
assert_equal %(<script type=\"text/javascript\"
|
133
|
+
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>),
|
111
134
|
sortable_element("mylist", :tag => "div", :constraint => "horizontal", :url => { :action => "order" })
|
112
|
-
|
135
|
+
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>|,
|
113
136
|
sortable_element("mylist", :containment => ['list1','list2'], :constraint => "horizontal", :url => { :action => "order" })
|
114
|
-
|
137
|
+
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>),
|
115
138
|
sortable_element("mylist", :containment => 'list1', :constraint => "horizontal", :url => { :action => "order" })
|
116
139
|
end
|
117
140
|
|
118
141
|
def test_draggable_element
|
119
|
-
|
142
|
+
assert_dom_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable('product_13', {})\n//]]>\n</script>),
|
120
143
|
draggable_element('product_13')
|
121
|
-
assert_equal %(<script type=\"text/javascript\"
|
144
|
+
assert_equal %(<script type=\"text/javascript\">\n//<![CDATA[\nnew Draggable('product_13', {revert:true})\n//]]>\n</script>),
|
122
145
|
draggable_element('product_13', :revert => true)
|
123
146
|
end
|
124
147
|
|
125
148
|
def test_drop_receiving_element
|
126
|
-
|
149
|
+
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>),
|
127
150
|
drop_receiving_element('droptarget1')
|
128
|
-
|
151
|
+
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>),
|
129
152
|
drop_receiving_element('droptarget1', :accept => 'products')
|
130
|
-
|
153
|
+
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>),
|
131
154
|
drop_receiving_element('droptarget1', :accept => 'products', :update => 'infobox')
|
132
|
-
|
155
|
+
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>),
|
133
156
|
drop_receiving_element('droptarget1', :accept => ['tshirts','mugs'], :update => 'infobox')
|
134
157
|
end
|
135
158
|
|
@@ -18,6 +18,8 @@ class NumberHelperTest < Test::Unit::TestCase
|
|
18
18
|
def test_number_to_currency
|
19
19
|
assert_equal("$1,234,567,890.50", number_to_currency(1234567890.50))
|
20
20
|
assert_equal("$1,234,567,890.51", number_to_currency(1234567890.506))
|
21
|
+
assert_equal("$1,234,567,890", number_to_currency(1234567890.50, {:precision => 0}))
|
22
|
+
assert_equal("$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1}))
|
21
23
|
assert_equal("£1234567890,50", number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}))
|
22
24
|
end
|
23
25
|
|
@@ -24,9 +24,18 @@ class TagHelperTest < Test::Unit::TestCase
|
|
24
24
|
assert_equal "<p included=\"\" />", tag("p", :included => '')
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_tag_options_converts_boolean_option
|
28
|
+
assert_equal '<p disabled="disabled" multiple="multiple" readonly="readonly" />',
|
29
|
+
tag("p", :disabled => true, :multiple => true, :readonly => true)
|
30
|
+
end
|
31
|
+
|
27
32
|
def test_content_tag
|
28
33
|
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
|
29
34
|
assert_equal content_tag("a", "Create", "href" => "create"),
|
30
35
|
content_tag("a", "Create", :href => "create")
|
31
36
|
end
|
37
|
+
|
38
|
+
def test_cdata_section
|
39
|
+
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
|
40
|
+
end
|
32
41
|
end
|
@@ -1,10 +1,20 @@
|
|
1
1
|
require 'test/unit'
|
2
|
+
require "#{File.dirname(__FILE__)}/../testing_sandbox"
|
2
3
|
require File.dirname(__FILE__) + '/../../lib/action_view/helpers/text_helper'
|
3
4
|
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/numeric' # for human_size
|
5
|
+
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/hash' # for stringify_keys
|
6
|
+
require File.dirname(__FILE__) + '/../../../activesupport/lib/active_support/core_ext/object_and_class.rb' # for blank?
|
4
7
|
|
5
8
|
class TextHelperTest < Test::Unit::TestCase
|
6
9
|
include ActionView::Helpers::TextHelper
|
7
10
|
include ActionView::Helpers::TagHelper
|
11
|
+
include TestingSandbox
|
12
|
+
|
13
|
+
def setup
|
14
|
+
# This simulates the fact that instance variables are reset every time
|
15
|
+
# a view is rendered. The cycle helper depends on this behavior.
|
16
|
+
@_cycles = nil if (defined? @_cycles)
|
17
|
+
end
|
8
18
|
|
9
19
|
def test_simple_format
|
10
20
|
assert_equal "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", simple_format("crazy\r\n cross\r platform linebreaks")
|
@@ -17,6 +27,29 @@ class TextHelperTest < Test::Unit::TestCase
|
|
17
27
|
assert_equal "Hello Worl...", truncate("Hello World!!", 12)
|
18
28
|
end
|
19
29
|
|
30
|
+
def test_truncate_multibyte_without_kcode
|
31
|
+
result = execute_in_sandbox(<<-'CODE')
|
32
|
+
require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper"
|
33
|
+
include ActionView::Helpers::TextHelper
|
34
|
+
truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
|
35
|
+
CODE
|
36
|
+
|
37
|
+
assert_equal "\354\225\210\353\205\225\355\225...", result
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_truncate_multibyte_with_kcode
|
41
|
+
result = execute_in_sandbox(<<-'CODE')
|
42
|
+
$KCODE = "u"
|
43
|
+
require 'jcode'
|
44
|
+
|
45
|
+
require "#{File.dirname(__FILE__)}/../lib/action_view/helpers/text_helper"
|
46
|
+
include ActionView::Helpers::TextHelper
|
47
|
+
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204\353\235\274\353\246\254\354\230\244", 10)
|
48
|
+
CODE
|
49
|
+
|
50
|
+
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254\353\236 \354\225\204...", result
|
51
|
+
end
|
52
|
+
|
20
53
|
def test_strip_links
|
21
54
|
assert_equal "on my mind", strip_links("<a href='almost'>on my mind</a>")
|
22
55
|
end
|
@@ -67,7 +100,13 @@ class TextHelperTest < Test::Unit::TestCase
|
|
67
100
|
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
|
68
101
|
assert_nil excerpt("This is a beautiful morning", "day")
|
69
102
|
end
|
103
|
+
|
104
|
+
def test_excerpt_with_regex
|
105
|
+
assert_equal('...is a beautiful! morn...', excerpt('This is a beautiful! morning', 'beautiful', 5))
|
106
|
+
assert_equal('...is a beautiful? morn...', excerpt('This is a beautiful? morning', 'beautiful', 5))
|
107
|
+
end
|
70
108
|
|
109
|
+
|
71
110
|
def test_word_wrap
|
72
111
|
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
|
73
112
|
end
|
@@ -85,6 +124,10 @@ class TextHelperTest < Test::Unit::TestCase
|
|
85
124
|
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
|
86
125
|
link2_raw = 'www.rubyonrails.com'
|
87
126
|
link2_result = %{<a href="http://#{link2_raw}">#{link2_raw}</a>}
|
127
|
+
link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
|
128
|
+
link3_result = %{<a href="#{link3_raw}">#{link3_raw}</a>}
|
129
|
+
link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
|
130
|
+
link4_result = %{<a href="#{link4_raw}">#{link4_raw}</a>}
|
88
131
|
|
89
132
|
assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
|
90
133
|
assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
|
@@ -92,11 +135,30 @@ class TextHelperTest < Test::Unit::TestCase
|
|
92
135
|
assert_equal %(Go to #{link_result} and say hello to #{email_result}), auto_link("Go to #{link_raw} and say hello to #{email_raw}")
|
93
136
|
assert_equal %(<p>Link #{link_result}</p>), auto_link("<p>Link #{link_raw}</p>")
|
94
137
|
assert_equal %(<p>#{link_result} Link</p>), auto_link("<p>#{link_raw} Link</p>")
|
138
|
+
assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
|
139
|
+
assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
|
140
|
+
assert_equal %(<p>Go to #{link_result}, then say hello to #{email_result}.</p>), auto_link(%(<p>Go to #{link_raw}, then say hello to #{email_raw}.</p>))
|
95
141
|
assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
|
96
142
|
assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses)
|
97
143
|
assert_equal %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
|
98
144
|
assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
|
99
|
-
assert_equal %(
|
145
|
+
assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.))
|
146
|
+
assert_equal %(<p>Say hello to #{email_result}, then go to #{link2_result}.</p>), auto_link(%(<p>Say hello to #{email_raw}, then go to #{link2_raw}.</p>))
|
147
|
+
assert_equal %(Go to #{link3_result}), auto_link("Go to #{link3_raw}", :urls)
|
148
|
+
assert_equal %(Go to #{link3_raw}), auto_link("Go to #{link3_raw}", :email_addresses)
|
149
|
+
assert_equal %(<p>Link #{link3_result}</p>), auto_link("<p>Link #{link3_raw}</p>")
|
150
|
+
assert_equal %(<p>#{link3_result} Link</p>), auto_link("<p>#{link3_raw} Link</p>")
|
151
|
+
assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.))
|
152
|
+
assert_equal %(<p>Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.</p>), auto_link(%(<p>Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.</p>))
|
153
|
+
assert_equal %(<p>Link #{link4_result}</p>), auto_link("<p>Link #{link4_raw}</p>")
|
154
|
+
assert_equal %(<p>#{link4_result} Link</p>), auto_link("<p>#{link4_raw} Link</p>")
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_auto_link_at_eol
|
158
|
+
url1 = "http://api.rubyonrails.com/Foo.html"
|
159
|
+
url2 = "http://www.ruby-doc.org/core/Bar.html"
|
160
|
+
|
161
|
+
assert_equal %(<p><a href="#{url1}">#{url1}</a><br /><a href="#{url2}">#{url2}</a><br /></p>), auto_link("<p>#{url1}<br />#{url2}<br /></p>")
|
100
162
|
end
|
101
163
|
|
102
164
|
def test_sanitize_form
|
@@ -123,4 +185,87 @@ class TextHelperTest < Test::Unit::TestCase
|
|
123
185
|
assert_equal %{href="javascript:bang" <a name='hello'>foo</a>, <span>bar</span>}, result
|
124
186
|
end
|
125
187
|
|
188
|
+
def test_cycle_class
|
189
|
+
value = Cycle.new("one", 2, "3")
|
190
|
+
assert_equal("one", value.to_s)
|
191
|
+
assert_equal("2", value.to_s)
|
192
|
+
assert_equal("3", value.to_s)
|
193
|
+
assert_equal("one", value.to_s)
|
194
|
+
value.reset
|
195
|
+
assert_equal("one", value.to_s)
|
196
|
+
assert_equal("2", value.to_s)
|
197
|
+
assert_equal("3", value.to_s)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_cycle_class_with_no_arguments
|
201
|
+
assert_raise(ArgumentError) { value = Cycle.new() }
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_cycle
|
205
|
+
assert_equal("one", cycle("one", 2, "3"))
|
206
|
+
assert_equal("2", cycle("one", 2, "3"))
|
207
|
+
assert_equal("3", cycle("one", 2, "3"))
|
208
|
+
assert_equal("one", cycle("one", 2, "3"))
|
209
|
+
assert_equal("2", cycle("one", 2, "3"))
|
210
|
+
assert_equal("3", cycle("one", 2, "3"))
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_cycle_with_no_arguments
|
214
|
+
assert_raise(ArgumentError) { value = cycle() }
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_cycle_resets_with_new_values
|
218
|
+
assert_equal("even", cycle("even", "odd"))
|
219
|
+
assert_equal("odd", cycle("even", "odd"))
|
220
|
+
assert_equal("even", cycle("even", "odd"))
|
221
|
+
assert_equal("1", cycle(1, 2, 3))
|
222
|
+
assert_equal("2", cycle(1, 2, 3))
|
223
|
+
assert_equal("3", cycle(1, 2, 3))
|
224
|
+
assert_equal("1", cycle(1, 2, 3))
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_named_cycles
|
228
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
229
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
230
|
+
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
231
|
+
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
232
|
+
assert_equal("3", cycle(1, 2, 3, :name => "numbers"))
|
233
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_default_named_cycle
|
237
|
+
assert_equal("1", cycle(1, 2, 3))
|
238
|
+
assert_equal("2", cycle(1, 2, 3, :name => "default"))
|
239
|
+
assert_equal("3", cycle(1, 2, 3))
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_reset_cycle
|
243
|
+
assert_equal("1", cycle(1, 2, 3))
|
244
|
+
assert_equal("2", cycle(1, 2, 3))
|
245
|
+
reset_cycle
|
246
|
+
assert_equal("1", cycle(1, 2, 3))
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_reset_unknown_cycle
|
250
|
+
reset_cycle("colors")
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_recet_named_cycle
|
254
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
255
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
256
|
+
reset_cycle("numbers")
|
257
|
+
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
|
258
|
+
assert_equal("blue", cycle("red", "blue", :name => "colors"))
|
259
|
+
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
|
260
|
+
assert_equal("red", cycle("red", "blue", :name => "colors"))
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_cycle_no_instance_variable_clashes
|
264
|
+
@cycles = %w{Specialized Fuji Giant}
|
265
|
+
assert_equal("red", cycle("red", "blue"))
|
266
|
+
assert_equal("blue", cycle("red", "blue"))
|
267
|
+
assert_equal("red", cycle("red", "blue"))
|
268
|
+
assert_equal(%w{Specialized Fuji Giant}, @cycles)
|
269
|
+
end
|
270
|
+
|
126
271
|
end
|