1
require 'abstract_unit'
2
require 'testing_sandbox'
6
$stderr.puts "Skipping textilize tests. `gem install RedCloth` to enable."
9
class TextHelperTest < ActionView::TestCase
10
tests ActionView::Helpers::TextHelper
11
include TestingSandbox
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)
20
self.output_buffer = 'foo'
21
assert_equal 'foobar', concat('bar')
22
assert_equal 'foobar', output_buffer
25
def test_simple_format
26
assert_equal "<p></p>", simple_format(nil)
28
assert_equal "<p>crazy\n<br /> cross\n<br /> platform linebreaks</p>", simple_format("crazy\r\n cross\r platform linebreaks")
29
assert_equal "<p>A paragraph</p>\n\n<p>and another one!</p>", simple_format("A paragraph\n\nand another one!")
30
assert_equal "<p>A paragraph\n<br /> With a newline</p>", simple_format("A paragraph\n With a newline")
32
text = "A\nB\nC\nD".freeze
33
assert_equal "<p>A\n<br />B\n<br />C\n<br />D</p>", simple_format(text)
35
text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze
36
assert_equal "<p>A\n<br /> \n<br />B</p>\n\n<p>\t\n<br />C\n<br />D</p>", simple_format(text)
38
assert_equal %q(<p class="test">This is a classy test</p>), simple_format("This is a classy test", :class => 'test')
39
assert_equal %Q(<p class="test">para 1</p>\n\n<p class="test">para 2</p>), simple_format("para 1\n\npara 2", :class => 'test')
43
assert_equal "Hello World!", truncate("Hello World!", :length => 12)
44
assert_equal "Hello Wor...", truncate("Hello World!!", :length => 12)
47
def test_truncate_should_use_default_length_of_30
48
str = "This is a string that will go longer then the default truncate length of 30"
49
assert_equal str[0...27] + "...", truncate(str)
52
def test_truncate_with_options_hash
53
assert_equal "This is a string that wil[...]", truncate("This is a string that will go longer then the default truncate length of 30", :omission => "[...]")
54
assert_equal "Hello W...", truncate("Hello World!", :length => 10)
55
assert_equal "Hello[...]", truncate("Hello World!", :omission => "[...]", :length => 10)
58
if RUBY_VERSION < '1.9.0'
59
def test_truncate_multibyte
61
assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10)
64
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
65
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244", :length => 10)
69
def test_truncate_multibyte
70
assert_equal "\354\225\210\353\205\225\355...",
71
truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", :length => 10)
73
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
74
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10)
80
"This is a <strong class=\"highlight\">beautiful</strong> morning",
81
highlight("This is a beautiful morning", "beautiful")
85
"This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day",
86
highlight("This is a beautiful morning, but also a beautiful day", "beautiful")
90
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
91
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", '<b>\1</b>')
95
"This text is not changed because we supplied an empty phrase",
96
highlight("This text is not changed because we supplied an empty phrase", nil)
99
assert_equal ' ', highlight(' ', 'blank text is returned verbatim')
102
def test_highlight_with_regexp
104
"This is a <strong class=\"highlight\">beautiful!</strong> morning",
105
highlight("This is a beautiful! morning", "beautiful!")
109
"This is a <strong class=\"highlight\">beautiful! morning</strong>",
110
highlight("This is a beautiful! morning", "beautiful! morning")
114
"This is a <strong class=\"highlight\">beautiful? morning</strong>",
115
highlight("This is a beautiful? morning", "beautiful? morning")
119
def test_highlight_with_multiple_phrases_in_one_pass
120
assert_equal %(<em>wow</em> <em>em</em>), highlight('wow em', %w(wow em), '<em>\1</em>')
123
def test_highlight_with_options_hash
125
"This is a <b>beautiful</b> morning, but also a <b>beautiful</b> day",
126
highlight("This is a beautiful morning, but also a beautiful day", "beautiful", :highlighter => '<b>\1</b>')
130
def test_highlight_with_html
132
"<p>This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
133
highlight("<p>This is a beautiful morning, but also a beautiful day</p>", "beautiful")
136
"<p>This is a <em><strong class=\"highlight\">beautiful</strong></em> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
137
highlight("<p>This is a <em>beautiful</em> morning, but also a beautiful day</p>", "beautiful")
140
"<p>This is a <em class=\"error\"><strong class=\"highlight\">beautiful</strong></em> morning, but also a <strong class=\"highlight\">beautiful</strong> <span class=\"last\">day</span></p>",
141
highlight("<p>This is a <em class=\"error\">beautiful</em> morning, but also a beautiful <span class=\"last\">day</span></p>", "beautiful")
144
"<p class=\"beautiful\">This is a <strong class=\"highlight\">beautiful</strong> morning, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
145
highlight("<p class=\"beautiful\">This is a beautiful morning, but also a beautiful day</p>", "beautiful")
148
"<p>This is a <strong class=\"highlight\">beautiful</strong> <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a <strong class=\"highlight\">beautiful</strong> day</p>",
149
highlight("<p>This is a beautiful <a href=\"http://example.com/beautiful\#top?what=beautiful%20morning&when=now+then\">morning</a>, but also a beautiful day</p>", "beautiful")
154
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", 5))
155
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", 5))
156
assert_equal("...iful morning", excerpt("This is a beautiful morning", "morning", 5))
157
assert_nil excerpt("This is a beautiful morning", "day")
160
def test_excerpt_in_borderline_cases
161
assert_equal("", excerpt("", "", 0))
162
assert_equal("a", excerpt("a", "a", 0))
163
assert_equal("...b...", excerpt("abc", "b", 0))
164
assert_equal("abc", excerpt("abc", "b", 1))
165
assert_equal("abc...", excerpt("abcd", "b", 1))
166
assert_equal("...abc", excerpt("zabc", "b", 1))
167
assert_equal("...abc...", excerpt("zabcd", "b", 1))
168
assert_equal("zabcd", excerpt("zabcd", "b", 2))
170
# excerpt strips the resulting string before ap-/prepending excerpt_string.
171
# whether this behavior is meaningful when excerpt_string is not to be
172
# appended is questionable.
173
assert_equal("zabcd", excerpt(" zabcd ", "b", 4))
174
assert_equal("...abc...", excerpt("z abc d", "b", 1))
177
def test_excerpt_with_regex
178
assert_equal('...is a beautiful! mor...', excerpt('This is a beautiful! morning', 'beautiful', 5))
179
assert_equal('...is a beautiful? mor...', excerpt('This is a beautiful? morning', 'beautiful', 5))
182
def test_excerpt_with_options_hash
183
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
184
assert_equal("[...]is a beautiful morn[...]", excerpt("This is a beautiful morning", "beautiful", :omission => "[...]",:radius => 5))
186
"This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome tempera[...]",
187
excerpt("This is the ultimate supercalifragilisticexpialidoceous very looooooooooooooooooong looooooooooooong beautiful morning with amazing sunshine and awesome temperatures. So what are you gonna do about it?", "very",
188
:omission => "[...]")
192
if RUBY_VERSION < '1.9'
193
def test_excerpt_with_utf8
195
assert_equal("...\357\254\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
197
with_kcode('none') do
198
assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
202
def test_excerpt_with_utf8
203
assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', 8))
204
assert_equal("...\203ciency could not be...", excerpt("That's why e\357\254\203ciency could not be helped", 'could', 8))
209
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
212
def test_word_wrap_with_extra_newlines
213
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", 15))
216
def test_word_wrap_with_options_hash
217
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
220
def test_pluralization
221
assert_equal("1 count", pluralize(1, "count"))
222
assert_equal("2 counts", pluralize(2, "count"))
223
assert_equal("1 count", pluralize('1', "count"))
224
assert_equal("2 counts", pluralize('2', "count"))
225
assert_equal("1,066 counts", pluralize('1,066', "count"))
226
assert_equal("1.25 counts", pluralize('1.25', "count"))
227
assert_equal("2 counters", pluralize(2, "count", "counters"))
228
assert_equal("0 counters", pluralize(nil, "count", "counters"))
229
assert_equal("2 people", pluralize(2, "person"))
230
assert_equal("10 buffaloes", pluralize(10, "buffalo"))
231
assert_equal("1 berry", pluralize(1, "berry"))
232
assert_equal("12 berries", pluralize(12, "berry"))
235
def test_auto_link_parsing
237
http://www.rubyonrails.com
238
http://www.rubyonrails.com:80
239
http://www.rubyonrails.com/~minam
240
https://www.rubyonrails.com/~minam
241
http://www.rubyonrails.com/~minam/url%20with%20spaces
242
http://www.rubyonrails.com/foo.cgi?something=here
243
http://www.rubyonrails.com/foo.cgi?something=here&and=here
244
http://www.rubyonrails.com/contact;new
245
http://www.rubyonrails.com/contact;new%20with%20spaces
246
http://www.rubyonrails.com/contact;new?with=query&string=params
247
http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
248
http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
249
http://www.mail-archive.com/rails@lists.rubyonrails.org/
250
http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
251
http://en.wikipedia.org/wiki/Texas_hold'em
252
https://www.google.com/doku.php?id=gps:resource:scs:start
253
http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group
254
http://of.openfoundry.org/projects/492/download#4th.Release.3
255
http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
259
assert_equal generate_result(url), auto_link(url)
263
def generate_result(link_text, href = nil)
265
%{<a href="#{CGI::escapeHTML href}">#{CGI::escapeHTML link_text}</a>}
268
def test_auto_linking
269
email_raw = 'david@loudthinking.com'
270
email_result = %{<a href="mailto:#{email_raw}">#{email_raw}</a>}
271
link_raw = 'http://www.rubyonrails.com'
272
link_result = generate_result(link_raw)
273
link_result_with_options = %{<a href="#{link_raw}" target="_blank">#{link_raw}</a>}
275
assert_equal '', auto_link(nil)
276
assert_equal '', auto_link('')
277
assert_equal "#{link_result} #{link_result} #{link_result}", auto_link("#{link_raw} #{link_raw} #{link_raw}")
279
assert_equal %(hello #{email_result}), auto_link("hello #{email_raw}", :email_addresses)
280
assert_equal %(Go to #{link_result}), auto_link("Go to #{link_raw}", :urls)
281
assert_equal %(Go to #{link_raw}), auto_link("Go to #{link_raw}", :email_addresses)
282
assert_equal %(Go to #{link_result} and say hello to #{email_result}), auto_link("Go to #{link_raw} and say hello to #{email_raw}")
283
assert_equal %(<p>Link #{link_result}</p>), auto_link("<p>Link #{link_raw}</p>")
284
assert_equal %(<p>#{link_result} Link</p>), auto_link("<p>#{link_raw} Link</p>")
285
assert_equal %(<p>Link #{link_result_with_options}</p>), auto_link("<p>Link #{link_raw}</p>", :all, {:target => "_blank"})
286
assert_equal %(Go to #{link_result}.), auto_link(%(Go to #{link_raw}.))
287
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>))
289
email2_raw = '+david@loudthinking.com'
290
email2_result = %{<a href="mailto:#{email2_raw}">#{email2_raw}</a>}
291
assert_equal email2_result, auto_link(email2_raw)
293
email3_raw = '+david@loudthinking.com'
294
email3_result = %{<a href="mailto:+%64%61%76%69%64@%6c%6f%75%64%74%68%69%6e%6b%69%6e%67.%63%6f%6d">#{email3_raw}</a>}
295
assert_equal email3_result, auto_link(email3_raw, :all, :encode => :hex)
296
assert_equal email3_result, auto_link(email3_raw, :email_addresses, :encode => :hex)
298
link2_raw = 'www.rubyonrails.com'
299
link2_result = generate_result(link2_raw, "http://#{link2_raw}")
300
assert_equal %(Go to #{link2_result}), auto_link("Go to #{link2_raw}", :urls)
301
assert_equal %(Go to #{link2_raw}), auto_link("Go to #{link2_raw}", :email_addresses)
302
assert_equal %(<p>Link #{link2_result}</p>), auto_link("<p>Link #{link2_raw}</p>")
303
assert_equal %(<p>#{link2_result} Link</p>), auto_link("<p>#{link2_raw} Link</p>")
304
assert_equal %(Go to #{link2_result}.), auto_link(%(Go to #{link2_raw}.))
305
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>))
307
link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
308
link3_result = generate_result(link3_raw)
309
assert_equal %(Go to #{link3_result}), auto_link("Go to #{link3_raw}", :urls)
310
assert_equal %(Go to #{link3_raw}), auto_link("Go to #{link3_raw}", :email_addresses)
311
assert_equal %(<p>Link #{link3_result}</p>), auto_link("<p>Link #{link3_raw}</p>")
312
assert_equal %(<p>#{link3_result} Link</p>), auto_link("<p>#{link3_raw} Link</p>")
313
assert_equal %(Go to #{link3_result}.), auto_link(%(Go to #{link3_raw}.))
314
assert_equal %(<p>Go to #{link3_result}. Seriously, #{link3_result}? I think I'll say hello to #{email_result}. Instead.</p>),
315
auto_link(%(<p>Go to #{link3_raw}. Seriously, #{link3_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
317
link4_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
318
link4_result = generate_result(link4_raw)
319
assert_equal %(<p>Link #{link4_result}</p>), auto_link("<p>Link #{link4_raw}</p>")
320
assert_equal %(<p>#{link4_result} Link</p>), auto_link("<p>#{link4_raw} Link</p>")
322
link5_raw = 'http://foo.example.com:3000/controller/action'
323
link5_result = generate_result(link5_raw)
324
assert_equal %(<p>#{link5_result} Link</p>), auto_link("<p>#{link5_raw} Link</p>")
326
link6_raw = 'http://foo.example.com:3000/controller/action+pack'
327
link6_result = generate_result(link6_raw)
328
assert_equal %(<p>#{link6_result} Link</p>), auto_link("<p>#{link6_raw} Link</p>")
330
link7_raw = 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
331
link7_result = generate_result(link7_raw)
332
assert_equal %(<p>#{link7_result} Link</p>), auto_link("<p>#{link7_raw} Link</p>")
334
link8_raw = 'http://foo.example.com:3000/controller/action.html'
335
link8_result = generate_result(link8_raw)
336
assert_equal %(Go to #{link8_result}), auto_link("Go to #{link8_raw}", :urls)
337
assert_equal %(Go to #{link8_raw}), auto_link("Go to #{link8_raw}", :email_addresses)
338
assert_equal %(<p>Link #{link8_result}</p>), auto_link("<p>Link #{link8_raw}</p>")
339
assert_equal %(<p>#{link8_result} Link</p>), auto_link("<p>#{link8_raw} Link</p>")
340
assert_equal %(Go to #{link8_result}.), auto_link(%(Go to #{link8_raw}.))
341
assert_equal %(<p>Go to #{link8_result}. Seriously, #{link8_result}? I think I'll say hello to #{email_result}. Instead.</p>),
342
auto_link(%(<p>Go to #{link8_raw}. Seriously, #{link8_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
344
link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
345
link9_result = generate_result(link9_raw)
346
assert_equal %(Go to #{link9_result}), auto_link("Go to #{link9_raw}", :urls)
347
assert_equal %(Go to #{link9_raw}), auto_link("Go to #{link9_raw}", :email_addresses)
348
assert_equal %(<p>Link #{link9_result}</p>), auto_link("<p>Link #{link9_raw}</p>")
349
assert_equal %(<p>#{link9_result} Link</p>), auto_link("<p>#{link9_raw} Link</p>")
350
assert_equal %(Go to #{link9_result}.), auto_link(%(Go to #{link9_raw}.))
351
assert_equal %(<p>Go to #{link9_result}. Seriously, #{link9_result}? I think I'll say hello to #{email_result}. Instead.</p>),
352
auto_link(%(<p>Go to #{link9_raw}. Seriously, #{link9_raw}? I think I'll say hello to #{email_raw}. Instead.</p>))
354
link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
355
link10_result = generate_result(link10_raw)
356
assert_equal %(<p>#{link10_result} Link</p>), auto_link("<p>#{link10_raw} Link</p>")
359
def test_auto_link_already_linked
360
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
361
linked2 = generate_result('www.rubyonrails.com', 'http://www.rubyonrails.com')
362
assert_equal linked1, auto_link(linked1)
363
assert_equal linked2, auto_link(linked2)
366
def test_auto_link_with_brackets
367
link1_raw = 'http://en.wikipedia.org/wiki/Sprite_(computer_graphics)'
368
link1_result = generate_result(link1_raw)
369
assert_equal link1_result, auto_link(link1_raw)
370
assert_equal "(link: #{link1_result})", auto_link("(link: #{link1_raw})")
372
link2_raw = 'http://en.wikipedia.org/wiki/Sprite_[computer_graphics]'
373
link2_result = generate_result(link2_raw)
374
assert_equal link2_result, auto_link(link2_raw)
375
assert_equal "[link: #{link2_result}]", auto_link("[link: #{link2_raw}]")
377
link3_raw = 'http://en.wikipedia.org/wiki/Sprite_{computer_graphics}'
378
link3_result = generate_result(link3_raw)
379
assert_equal link3_result, auto_link(link3_raw)
380
assert_equal "{link: #{link3_result}}", auto_link("{link: #{link3_raw}}")
383
def test_auto_link_in_tags
384
link_raw = 'http://www.rubyonrails.org/images/rails.png'
385
link_result = %Q(<img src="#{link_raw}" />)
386
assert_equal link_result, auto_link(link_result)
389
def test_auto_link_at_eol
390
url1 = "http://api.rubyonrails.com/Foo.html"
391
url2 = "http://www.ruby-doc.org/core/Bar.html"
393
assert_equal %(<p><a href="#{url1}">#{url1}</a><br /><a href="#{url2}">#{url2}</a><br /></p>), auto_link("<p>#{url1}<br />#{url2}<br /></p>")
396
def test_auto_link_with_block
397
url = "http://api.rubyonrails.com/Foo.html"
398
email = "fantabulous@shiznadel.ic"
400
assert_equal %(<p><a href="#{url}">#{url[0...7]}...</a><br /><a href="mailto:#{email}">#{email[0...7]}...</a><br /></p>), auto_link("<p>#{url}<br />#{email}<br /></p>") { |url| truncate(url, :length => 10) }
403
def test_auto_link_with_options_hash
404
assert_dom_equal 'Welcome to my new blog at <a href="http://www.myblog.com/" class="menu" target="_blank">http://www.myblog.com/</a>. Please e-mail me at <a href="mailto:me@email.com" class="menu" target="_blank">me@email.com</a>.',
405
auto_link("Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com.",
406
:link => :all, :html => { :class => "menu", :target => "_blank" })
410
value = Cycle.new("one", 2, "3")
411
assert_equal("one", value.to_s)
412
assert_equal("2", value.to_s)
413
assert_equal("3", value.to_s)
414
assert_equal("one", value.to_s)
416
assert_equal("one", value.to_s)
417
assert_equal("2", value.to_s)
418
assert_equal("3", value.to_s)
421
def test_cycle_class_with_no_arguments
422
assert_raise(ArgumentError) { value = Cycle.new() }
426
assert_equal("one", cycle("one", 2, "3"))
427
assert_equal("2", cycle("one", 2, "3"))
428
assert_equal("3", cycle("one", 2, "3"))
429
assert_equal("one", cycle("one", 2, "3"))
430
assert_equal("2", cycle("one", 2, "3"))
431
assert_equal("3", cycle("one", 2, "3"))
434
def test_cycle_with_no_arguments
435
assert_raise(ArgumentError) { value = cycle() }
438
def test_cycle_resets_with_new_values
439
assert_equal("even", cycle("even", "odd"))
440
assert_equal("odd", cycle("even", "odd"))
441
assert_equal("even", cycle("even", "odd"))
442
assert_equal("1", cycle(1, 2, 3))
443
assert_equal("2", cycle(1, 2, 3))
444
assert_equal("3", cycle(1, 2, 3))
445
assert_equal("1", cycle(1, 2, 3))
448
def test_named_cycles
449
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
450
assert_equal("red", cycle("red", "blue", :name => "colors"))
451
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
452
assert_equal("blue", cycle("red", "blue", :name => "colors"))
453
assert_equal("3", cycle(1, 2, 3, :name => "numbers"))
454
assert_equal("red", cycle("red", "blue", :name => "colors"))
457
def test_current_cycle_with_default_name
459
assert_equal "even", current_cycle
461
assert_equal "odd", current_cycle
463
assert_equal "even", current_cycle
466
def test_current_cycle_with_named_cycles
467
cycle("red", "blue", :name => "colors")
468
assert_equal "red", current_cycle("colors")
469
cycle("red", "blue", :name => "colors")
470
assert_equal "blue", current_cycle("colors")
471
cycle("red", "blue", :name => "colors")
472
assert_equal "red", current_cycle("colors")
475
def test_current_cycle_safe_call
476
assert_nothing_raised { current_cycle }
477
assert_nothing_raised { current_cycle("colors") }
480
def test_current_cycle_with_more_than_two_names
482
assert_equal "1", current_cycle
484
assert_equal "2", current_cycle
486
assert_equal "3", current_cycle
488
assert_equal "1", current_cycle
491
def test_default_named_cycle
492
assert_equal("1", cycle(1, 2, 3))
493
assert_equal("2", cycle(1, 2, 3, :name => "default"))
494
assert_equal("3", cycle(1, 2, 3))
498
assert_equal("1", cycle(1, 2, 3))
499
assert_equal("2", cycle(1, 2, 3))
501
assert_equal("1", cycle(1, 2, 3))
504
def test_reset_unknown_cycle
505
reset_cycle("colors")
508
def test_recet_named_cycle
509
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
510
assert_equal("red", cycle("red", "blue", :name => "colors"))
511
reset_cycle("numbers")
512
assert_equal("1", cycle(1, 2, 3, :name => "numbers"))
513
assert_equal("blue", cycle("red", "blue", :name => "colors"))
514
assert_equal("2", cycle(1, 2, 3, :name => "numbers"))
515
assert_equal("red", cycle("red", "blue", :name => "colors"))
518
def test_cycle_no_instance_variable_clashes
519
@cycles = %w{Specialized Fuji Giant}
520
assert_equal("red", cycle("red", "blue"))
521
assert_equal("blue", cycle("red", "blue"))
522
assert_equal("red", cycle("red", "blue"))
523
assert_equal(%w{Specialized Fuji Giant}, @cycles)
528
assert_equal("<p><strong>This is Textile!</strong> Rejoice!</p>", textilize("*This is Textile!* Rejoice!"))
531
def test_textilize_with_blank
532
assert_equal("", textilize(""))
535
def test_textilize_with_options
536
assert_equal("<p>This is worded <strong>strongly</strong></p>", textilize("This is worded <strong>strongly</strong>", :filter_html))
539
def test_textilize_with_hard_breaks
540
assert_equal("<p>This is one scary world.<br />\n True.</p>", textilize("This is one scary world.\n True."))