Class: RevisionTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
app/models/revision_test.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'app/models/revision_test.rb', line 20

def setup
  @mock_page = MockPage.new
  @mock_web  = MockWeb.new
  @mock_page.web = @mock_web

  @mock_web.markup = :textile

  @revision = Revision.new(
    @mock_page,
    1,
    "HisWay would be MyWay in kinda ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in that SmartEngineGUI", 
    Time.local(2004, 4, 4, 16, 50),
    "DavidHeinemeierHansson"
  )
  
  @revision_with_auto_links = Revision.new(
    @mock_page,
    1,
    "http://www.loudthinking.com/ points to ThatWay from [email protected]", 
    Time.local(2004, 4, 4, 16, 50),
    "DavidHeinemeierHansson"
  )

	@revision_with_aliased_links = Revision.new(
 @mock_page,
 1,
    "Would a [[SmartEngine|clever motor]] go by any other name?",
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"
	)

	@revision_with_wiki_word_in_em = Revision.new(
 @mock_page,
 1,
    "_should we go ThatWay or ThisWay _",
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"      
  )

	@revision_with_pre_blocks = Revision.new(
 @mock_page,
 1,
    "A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>",
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"
	)

	@revision_with_wikiword_in_tag = Revision.new(
 @mock_page,
 1,
    "That is some <em style=\"WikiWord\">Stylish Emphasis</em>",
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"
	)

	@revision_with_autolink_in_parentheses = Revision.new(
 @mock_page,
    1,
    'The W3C body (http://www.w3c.org) sets web standards',
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"														 
	)

	@revision_with_link_in_parentheses = Revision.new(
 @mock_page,
    1,
    'Instiki is a "Wiki Clone":http://www.c2.com/cgi/wiki?WikiWikiClones ("What is a wiki?":http://wiki.org/wiki.cgi?WhatIsWiki) that\'s so easy to setup',
 Time.local(2004, 4, 4, 16, 50),
    "MarkReid"
  )

	@revision_with_image_link = Revision.new(
 @mock_page,
    1,
    'This !http://hobix.com/sample.jpg! is a Textile image link.',
 Time.local(2004, 4, 4, 16, 50),
    "MarkReid"
  )

	@revision_with_nowiki_text = Revision.new(
 @mock_page,
 1,
 'Do not mark up <nowiki>[[this text]]</nowiki> or <nowiki>http://www.thislink.com</nowiki>.',
 Time.local(2004, 4, 4, 16, 50),
 "MarkReid"
	)

	@revision_with_bracketted_wiki_word = Revision.new(
 @mock_page,
 1,
 'This is a WikiWord and a tricky name [[Sperberg-McQueen]].',
 Time.local(2004, 4, 4, 16, 50),
 "MarkReid"
  )

end

#test_blueclothObject



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'app/models/revision_test.rb', line 133

def test_bluecloth
  @mock_web.markup = :blue_markdown

  @revision = Revision.new(
    @mock_page,
    1,
    "My Headline\n===========\n\n that SmartEngineGUI", 
    Time.local(2004, 4, 4, 16, 50),
    "DavidHeinemeierHansson"
  )

  @revision_with_code_block = Revision.new(
    @mock_page,
    1,
    "This is a code block:\n    def a_method(arg)\n    return ThatWay\n\nNice!",
    Time.local(2004, 4, 4, 16, 50),
    "MarkReid"      
  )

  assert_equal "<h1>My Headline</h1>\n\n<p>that <span class=\"newWikiWord\">Smart Engine GUI<a href=\"../show/SmartEngineGUI\">?</a></span></p>", @revision.display_content

  assert_equal "<p>This is a code block:</p>\n\n<pre><code>def a_method(arg)\nreturn ThatWay\n</code></pre>\n\n<p>Nice!</p>", @revision_with_code_block.display_content
end

#test_content_for_exportObject



212
213
214
# File 'app/models/revision_test.rb', line 212

def test_content_for_export
  assert_equal "<p><span class=\"newWikiWord\">His Way</span> would be <a class=\"existingWikiWord\" href=\"MyWay.html\">My Way</a> in kinda <a class=\"existingWikiWord\" href=\"ThatWay.html\">That Way</a> in <span class=\"newWikiWord\">His Way</span> though <a class=\"existingWikiWord\" href=\"MyWay.html\">My Way</a> OverThere&#8212;see <a class=\"existingWikiWord\" href=\"SmartEngine.html\">Smart Engine</a> in that <span class=\"newWikiWord\">Smart Engine <span class=\"caps\">GUI</span></span></p>", @revision.display_content_for_export
end


175
176
177
# File 'app/models/revision_test.rb', line 175

def test_content_with_aliased_links
	assert_equal "<p>Would a <a class=\"existingWikiWord\" href=\"../show/SmartEngine\">clever motor</a> go by any other name?</p>", @revision_with_aliased_links.display_content
end


171
172
173
# File 'app/models/revision_test.rb', line 171

def test_content_with_auto_links
  assert_equal "<p><a href=\"http://www.loudthinking.com/\">http://www.loudthinking.com/</a> points to <a class=\"existingWikiWord\" href=\"../show/ThatWay\">That Way</a> from <a href=\"mailto:[email protected]\">[email protected]</a></p>", @revision_with_auto_links.display_content
end


191
192
193
# File 'app/models/revision_test.rb', line 191

def test_content_with_autolink_in_parentheses
	assert_equal '<p>The <span class="caps">W3C</span> body (<a href="http://www.w3c.org">http://www.w3c.org</a>) sets web standards</p>', @revision_with_autolink_in_parentheses.display_content
end

#test_content_with_bracketted_wiki_wordObject



207
208
209
210
# File 'app/models/revision_test.rb', line 207

def test_content_with_bracketted_wiki_word
	@mock_web.brackets_only = true
	assert_equal '<p>This is a WikiWord and a tricky name <span class="newWikiWord">Sperberg-McQueen<a href="../show/Sperberg-McQueen">?</a></span>.</p>', @revision_with_bracketted_wiki_word.display_content
end


199
200
201
# File 'app/models/revision_test.rb', line 199

def test_content_with_image_link
	assert_equal '<p>This <img src="http://hobix.com/sample.jpg" alt="" /> is a Textile image link.</p>', @revision_with_image_link.display_content
end


195
196
197
# File 'app/models/revision_test.rb', line 195

def test_content_with_link_in_parentheses
	assert_equal '<p>Instiki is a <a href="http://www.c2.com/cgi/wiki?WikiWikiClones">Wiki Clone</a> (<a href="http://wiki.org/wiki.cgi?WhatIsWiki">What is a wiki?</a>) that&#8217;s so easy to setup</p>', @revision_with_link_in_parentheses.display_content
end

#test_content_with_nowiki_textObject



203
204
205
# File 'app/models/revision_test.rb', line 203

def test_content_with_nowiki_text
	assert_equal '<p>Do not mark up [[this text]] or http://www.thislink.com.</p>', @revision_with_nowiki_text.display_content
end

#test_content_with_pre_blocksObject



187
188
189
# File 'app/models/revision_test.rb', line 187

def test_content_with_pre_blocks
	assert_equal "A <code>class SmartEngine end</code> would not mark up <pre>CodeBlocks</pre>", @revision_with_pre_blocks.display_content
end


129
130
131
# File 'app/models/revision_test.rb', line 129

def test_content_with_wiki_links
  assert_equal "<p><span class=\"newWikiWord\">His Way<a href=\"../show/HisWay\">?</a></span> would be <a class=\"existingWikiWord\" href=\"../show/MyWay\">My Way</a> in kinda <a class=\"existingWikiWord\" href=\"../show/ThatWay\">That Way</a> in <span class=\"newWikiWord\">His Way<a href=\"../show/HisWay\">?</a></span> though <a class=\"existingWikiWord\" href=\"../show/MyWay\">My Way</a> OverThere&#8212;see <a class=\"existingWikiWord\" href=\"../show/SmartEngine\">Smart Engine</a> in that <span class=\"newWikiWord\">Smart Engine <span class=\"caps\">GUI</span><a href=\"../show/SmartEngineGUI\">?</a></span></p>", @revision.display_content
end

#test_content_with_wikiword_in_emObject



179
180
181
# File 'app/models/revision_test.rb', line 179

def test_content_with_wikiword_in_em
	assert_equal "<p><em>should we go <a class=\"existingWikiWord\" href=\"../show/ThatWay\">That Way</a> or <span class=\"newWikiWord\">This Way<a href=\"../show/ThisWay\">?</a></span> </em></p>", @revision_with_wiki_word_in_em.display_content
end

#test_content_with_wikiword_in_tagObject



183
184
185
# File 'app/models/revision_test.rb', line 183

def test_content_with_wikiword_in_tag
  assert_equal "<p>That is some <em style=\"WikiWord\">Stylish Emphasis</em></p>", @revision_with_wikiword_in_tag.display_content
end

#test_difficult_wiki_wordsObject



232
233
234
235
236
237
238
# File 'app/models/revision_test.rb', line 232

def test_difficult_wiki_words
  @revision.content = "[[It's just awesome GUI!]]"
  assert_equal(
    "<p><span class=\"newWikiWord\">It&#8217;s just awesome <span class=\"caps\">GUI</span>!<a href=\"../show/It%27s+just+awesome+GUI%21\">?</a></span></p>", 
    @revision.display_content
  )
end

#test_double_replacingObject



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'app/models/revision_test.rb', line 216

def test_double_replacing
  @revision.content = "VersionHistory\r\n\r\ncry VersionHistory"
  assert_equal(
    "<p><span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\t<p>cry <span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a></span></p>", 
    @revision.display_content
  )

  @revision.clear_display_cache

  @revision.content = "f\r\nVersionHistory\r\n\r\ncry VersionHistory"
  assert_equal(
    "<p>f<br />\n<span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a></span></p>\n\n\t<p>cry <span class=\"newWikiWord\">Version History<a href=\"../show/VersionHistory\">?</a></span></p>", 
    @revision.display_content
  )
end

#test_existing_pagesObject



121
122
123
# File 'app/models/revision_test.rb', line 121

def test_existing_pages
  assert_equal %w( MyWay SmartEngine ThatWay ), @revision.existing_pages.sort
end

#test_rdocObject



157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'app/models/revision_test.rb', line 157

def test_rdoc
  @mock_web.markup = :rdoc

  @revision = Revision.new(
    @mock_page,
    1,
    "+hello+ that SmartEngineGUI", 
    Time.local(2004, 4, 4, 16, 50),
    "DavidHeinemeierHansson"
  )

  assert_equal "<tt>hello</tt> that <span class=\"newWikiWord\">Smart Engine GUI<a href=\"../show/SmartEngineGUI\">?</a></span>\n\n", @revision.display_content
end

#test_revisions_diffObject



240
241
242
243
244
245
246
247
248
249
250
251
# File 'app/models/revision_test.rb', line 240

def test_revisions_diff
  page = MockPage.new
  web  = MockWeb.new
  web.markup = :textile
  page.web = web

  page.revisions = [ 0 ] 
  page.revisions << Revision.new(page, 1, "What a blue and lovely morning", Time.local(2004, 4, 4, 16, 50), "DavidHeinemeierHansson")
  page.revisions << Revision.new(page, 2, "What a red and lovely morning today", Time.local(2004, 4, 4, 16, 50), "DavidHeinemeierHansson")
  
  assert_equal "<p>What a <del class=\"diffmod\">blue </del><ins class=\"diffmod\">red </ins>and lovely <del class=\"diffmod\">morning</del><ins class=\"diffmod\">morning today</ins></p>", page.revisions.last.display_diff
end

#test_unexisting_pagesObject



125
126
127
# File 'app/models/revision_test.rb', line 125

def test_unexisting_pages
  assert_equal %w( HisWay SmartEngineGUI ), @revision.unexisting_pages.sort
end

#test_wiki_wordsObject



117
118
119
# File 'app/models/revision_test.rb', line 117

def test_wiki_words
  assert_equal %w( HisWay MyWay SmartEngine SmartEngineGUI ThatWay ), @revision.wiki_words.sort
end