acts_as_markup_extended 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +4 -0
- data/LICENSE +22 -0
- data/README.rdoc +198 -0
- data/Rakefile +35 -0
- data/lib/acts/as_markup.rb +251 -0
- data/lib/acts_as_markup/exts/maruku.rb +70 -0
- data/lib/acts_as_markup/exts/object.rb +1 -0
- data/lib/acts_as_markup/exts/peg_markdown.rb +10 -0
- data/lib/acts_as_markup/exts/rdiscount.rb +15 -0
- data/lib/acts_as_markup/exts/rdoc.rb +101 -0
- data/lib/acts_as_markup/exts/wikitext.rb +20 -0
- data/lib/acts_as_markup/stringlike.rb +7 -0
- data/lib/acts_as_markup_extended.rb +79 -0
- data/lib/markup_extensions.rb +24 -0
- data/lib/markup_methods/ahttp.rb +27 -0
- data/lib/markup_methods/checklist.rb +30 -0
- data/lib/markup_methods/logo.rb +27 -0
- data/test/acts_as_markdown_test.rb +298 -0
- data/test/acts_as_markup_extended.rb +90 -0
- data/test/acts_as_markup_test.rb +593 -0
- data/test/acts_as_rdoc_test.rb +58 -0
- data/test/acts_as_textile_test.rb +77 -0
- data/test/acts_as_wikitext_test.rb +77 -0
- data/test/markup_methods_test.rb +95 -0
- data/test/test_helper.rb +69 -0
- metadata +166 -0
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
include MarkupExtensionMethods
|
4
|
+
|
5
|
+
class ActsAsMarkupExtendedTest < ActsAsMarkupTestCase
|
6
|
+
|
7
|
+
context 'simple acts_as..' do
|
8
|
+
setup do
|
9
|
+
@textile_text = %Q~* x item1~
|
10
|
+
@markdown_text = %Q~- x item1~
|
11
|
+
# each markup language puts out slightly different text
|
12
|
+
# with spaces, tabs and newlines
|
13
|
+
@regex_out = /^<ul>\s*<li><strong>\(X\) <\/strong>item1\s*<\/li>\s*<\/ul>\s*/
|
14
|
+
@regex_fail_out = /<ul>\s*<li>x item1\s*<\/li>\s*<\/ul>\s*/
|
15
|
+
end
|
16
|
+
|
17
|
+
should "invoke textile extension method when :extension => [:method] " do
|
18
|
+
class Post < ActiveRecord::Base
|
19
|
+
acts_as_textile :body, :extensions => [:checklist]
|
20
|
+
end
|
21
|
+
@post = Post.create!(:title => 'textile', :body => @textile_text)
|
22
|
+
assert_match @regex_out, @post.body.to_html
|
23
|
+
end
|
24
|
+
|
25
|
+
should "invoke markdown extension method when :extension => [:method] " do
|
26
|
+
class Post < ActiveRecord::Base
|
27
|
+
acts_as_markdown :body, :extensions => [:checklist]
|
28
|
+
end
|
29
|
+
@post = Post.create!(:title => 'Blah1', :body => @markdown_text)
|
30
|
+
assert_match @regex_out, @post.body.to_html
|
31
|
+
end
|
32
|
+
|
33
|
+
should "invoke rdoc extension method when :extension => [:method] " do
|
34
|
+
class Post < ActiveRecord::Base
|
35
|
+
acts_as_rdoc :body, :extensions => [:checklist]
|
36
|
+
end
|
37
|
+
@post = Post.create!(:title => 'Blah2', :body => @textile_text)
|
38
|
+
assert_match @regex_out, @post.body.to_html
|
39
|
+
end
|
40
|
+
|
41
|
+
should "invoke wikitext extension method when :extension => [:method] " do
|
42
|
+
class Post < ActiveRecord::Base
|
43
|
+
acts_as_wikitext :body, :extensions => [:checklist]
|
44
|
+
end
|
45
|
+
@post = Post.create!(:title => 'Blah3', :body => @textile_text)
|
46
|
+
assert_match @regex_out, @post.body.to_html
|
47
|
+
end
|
48
|
+
|
49
|
+
should "invoke extension method when :extension => :all specified " do
|
50
|
+
class Post < ActiveRecord::Base
|
51
|
+
acts_as_textile :body, :extensions => :all
|
52
|
+
end
|
53
|
+
@post = Post.create!(:title => 'textile', :body => @textile_text)
|
54
|
+
assert_match @regex_out, @post.body.to_html
|
55
|
+
end
|
56
|
+
|
57
|
+
should "invoke extension method when acts_as_markup :extension => :all specified " do
|
58
|
+
class Post < ActiveRecord::Base
|
59
|
+
acts_as_markup :language => 'textile', :columns => [:body], :extensions => :all
|
60
|
+
end
|
61
|
+
@post = Post.create!(:title => 'textile', :body => @textile_text)
|
62
|
+
assert_match @regex_out, @post.body.to_html
|
63
|
+
end
|
64
|
+
|
65
|
+
should "invoke extension method when acts_as_markup :language_column, " +
|
66
|
+
":extension => :all specified " do
|
67
|
+
class VariableLanguagePost < ActiveRecord::Base
|
68
|
+
acts_as_markup :language => :variable, :columns => [:body],
|
69
|
+
:language_column => 'language_name', :extensions => :all
|
70
|
+
end
|
71
|
+
@post = VariableLanguagePost.create!(:title => 'textile', :body => @textile_text,
|
72
|
+
:language_name => 'textile')
|
73
|
+
assert_match @regex_out, @post.body.to_html
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'raise exception when a non-existent extension method is named' do
|
77
|
+
class Post < ActiveRecord::Base
|
78
|
+
acts_as_textile :body, :extensions => [:non_existent]
|
79
|
+
end
|
80
|
+
@post = Post.create!(:title => 'textile1', :body => @textile_text)
|
81
|
+
assert_raise ActsAsMarkup::UnknownExtensionMethod do
|
82
|
+
@post.body.to_html
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
teardown do
|
87
|
+
Post.delete_all
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,593 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ActsAsMarkupTest < ActsAsMarkupTestCase
|
4
|
+
def setup
|
5
|
+
setup_db
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'acts_as_markup' do
|
9
|
+
setup do
|
10
|
+
ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MARKDOWN_LIB
|
11
|
+
|
12
|
+
@textile_text = "h2. Textile Test Text"
|
13
|
+
class ::TextilePost < ActiveRecord::Base
|
14
|
+
acts_as_markup :language => :textile, :columns => [:body]
|
15
|
+
end
|
16
|
+
@textile_post = TextilePost.create!(:title => 'Blah', :body => @textile_text)
|
17
|
+
|
18
|
+
@markdown_text = '## Markdown Test Text'
|
19
|
+
class ::MarkdownPost < ActiveRecord::Base
|
20
|
+
acts_as_markup :language => :markdown, :columns => [:body]
|
21
|
+
end
|
22
|
+
@markdown_post = MarkdownPost.create!(:title => 'Blah', :body => @markdown_text)
|
23
|
+
end
|
24
|
+
|
25
|
+
should "have a markup object returned for the column value" do
|
26
|
+
assert_kind_of RedCloth::TextileDoc, @textile_post.body
|
27
|
+
assert_kind_of RDiscount, @markdown_post.body
|
28
|
+
end
|
29
|
+
|
30
|
+
should "return original markup text for a `to_s` method call on the column value" do
|
31
|
+
assert_equal @markdown_text, @markdown_post.body.to_s
|
32
|
+
assert_equal @textile_text, @textile_post.body.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
should "return formated html for a `to_html` method call on the column value" do
|
36
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
|
37
|
+
assert_match(/<h2>Textile Test Text<\/h2>/, @textile_post.body.to_html)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "changing value of markup field should return new markup object" do
|
41
|
+
setup do
|
42
|
+
@markdown_old_body = @markdown_post.body
|
43
|
+
@markdown_post.body = "`@count = 20`"
|
44
|
+
@textile_old_body = @textile_post.body
|
45
|
+
@textile_post.body = "@@count = 20@"
|
46
|
+
end
|
47
|
+
|
48
|
+
should "still have an markup object but not the same object" do
|
49
|
+
assert_kind_of RedCloth::TextileDoc, @textile_post.body
|
50
|
+
assert_not_same @markdown_post.body, @markdown_old_body
|
51
|
+
assert_kind_of RDiscount, @markdown_post.body
|
52
|
+
assert_not_same @textile_post.body, @textile_old_body
|
53
|
+
end
|
54
|
+
|
55
|
+
should "return correct text for `to_s`" do
|
56
|
+
assert_equal "`@count = 20`", @markdown_post.body.to_s
|
57
|
+
assert_equal "@@count = 20@", @textile_post.body.to_s
|
58
|
+
end
|
59
|
+
|
60
|
+
should "return correct HTML for the `to_html` method" do
|
61
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @markdown_post.body.to_html)
|
62
|
+
assert_match(/<code>\@count\s\=\s20<\/code>/, @textile_post.body.to_html)
|
63
|
+
end
|
64
|
+
|
65
|
+
teardown do
|
66
|
+
@markdown_old_body, @textile_old_body = nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
teardown do
|
71
|
+
@textile_text, @textile_post, @markdown_text, @markdown_post = nil
|
72
|
+
TextilePost.delete_all
|
73
|
+
MarkdownPost.delete_all
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'acts_as_markup with variable language' do
|
78
|
+
setup do
|
79
|
+
ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MARKDOWN_LIB
|
80
|
+
class ::VariablePost < ActiveRecord::Base
|
81
|
+
acts_as_markup :language => :variable, :columns => [:body]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "with a Markdown post" do
|
86
|
+
setup do
|
87
|
+
@markdown_text = '## Markdown Test Text'
|
88
|
+
@markdown_post = VariablePost.create!(:title => 'Blah', :body => @markdown_text, :markup_language => 'Markdown')
|
89
|
+
end
|
90
|
+
|
91
|
+
should "have a markup object returned for the column value" do
|
92
|
+
assert_kind_of RDiscount, @markdown_post.body
|
93
|
+
end
|
94
|
+
|
95
|
+
should "return original markup text for a `to_s` method call on the column value" do
|
96
|
+
assert_equal @markdown_text, @markdown_post.body.to_s
|
97
|
+
end
|
98
|
+
|
99
|
+
should "return formated html for a `to_html` method call on the column value" do
|
100
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
|
101
|
+
end
|
102
|
+
|
103
|
+
context "changing value of markup field should return new markup object" do
|
104
|
+
setup do
|
105
|
+
@markdown_old_body = @markdown_post.body
|
106
|
+
@markdown_post.body = "`@count = 20`"
|
107
|
+
end
|
108
|
+
|
109
|
+
should "still have an markup object but not the same object" do
|
110
|
+
assert_not_same @markdown_post.body, @markdown_old_body
|
111
|
+
assert_kind_of RDiscount, @markdown_post.body
|
112
|
+
end
|
113
|
+
|
114
|
+
should "return correct text for `to_s`" do
|
115
|
+
assert_equal "`@count = 20`", @markdown_post.body.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
should "return correct HTML for the `to_html` method" do
|
119
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @markdown_post.body.to_html)
|
120
|
+
end
|
121
|
+
|
122
|
+
teardown do
|
123
|
+
@markdown_old_body = nil
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
teardown do
|
128
|
+
@markdown_text, @markup_post = nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
context "with a Textile post" do
|
133
|
+
setup do
|
134
|
+
@textile_text = "h2. Textile Test Text"
|
135
|
+
@textile_post = VariablePost.create!(:title => 'Blah', :body => @textile_text, :markup_language => 'Textile')
|
136
|
+
end
|
137
|
+
|
138
|
+
should "have a markup object returned for the column value" do
|
139
|
+
assert_kind_of RedCloth::TextileDoc, @textile_post.body
|
140
|
+
end
|
141
|
+
|
142
|
+
should "return original markup text for a `to_s` method call on the column value" do
|
143
|
+
assert_equal @textile_text, @textile_post.body.to_s
|
144
|
+
end
|
145
|
+
|
146
|
+
should "return formated html for a `to_html` method call on the column value" do
|
147
|
+
assert_match(/<h2>Textile Test Text<\/h2>/, @textile_post.body.to_html)
|
148
|
+
end
|
149
|
+
|
150
|
+
context "changing value of markup field should return new markup object" do
|
151
|
+
setup do
|
152
|
+
@textile_old_body = @textile_post.body
|
153
|
+
@textile_post.body = "@@count = 20@"
|
154
|
+
end
|
155
|
+
|
156
|
+
should "still have an markup object but not the same object" do
|
157
|
+
assert_kind_of RedCloth::TextileDoc, @textile_post.body
|
158
|
+
assert_not_same @textile_post.body, @textile_old_body
|
159
|
+
end
|
160
|
+
|
161
|
+
should "return correct text for `to_s`" do
|
162
|
+
assert_equal "@@count = 20@", @textile_post.body.to_s
|
163
|
+
end
|
164
|
+
|
165
|
+
should "return correct HTML for the `to_html` method" do
|
166
|
+
assert_match(/<code>\@count\s\=\s20<\/code>/, @textile_post.body.to_html)
|
167
|
+
end
|
168
|
+
|
169
|
+
teardown do
|
170
|
+
@textile_old_body = nil
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
teardown do
|
175
|
+
@textile_text, @textile_post = nil
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context 'with a Wikitext post' do
|
180
|
+
setup do
|
181
|
+
@wikitext = "== Wikitext Test Text =="
|
182
|
+
@wikitext_post = VariablePost.create!(:title => 'Blah', :body => @wikitext, :markup_language => 'Wikitext')
|
183
|
+
end
|
184
|
+
|
185
|
+
should "have a WikitextString object returned for the column value" do
|
186
|
+
assert_kind_of WikitextString, @wikitext_post.body
|
187
|
+
end
|
188
|
+
|
189
|
+
should "return original wikitext text for a `to_s` method call on the column value" do
|
190
|
+
assert_equal @wikitext, @wikitext_post.body.to_s
|
191
|
+
end
|
192
|
+
|
193
|
+
should "return formated html for a `to_html` method call on the column value" do
|
194
|
+
assert_match(/<h2>Wikitext Test Text<\/h2>/, @wikitext_post.body.to_html)
|
195
|
+
end
|
196
|
+
|
197
|
+
context "changing value of wikitext field should return new wikitext object" do
|
198
|
+
setup do
|
199
|
+
@old_body = @wikitext_post.body
|
200
|
+
@wikitext_post.body = "`@count = 20`"
|
201
|
+
end
|
202
|
+
|
203
|
+
should "still have an WikitextString object but not the same object" do
|
204
|
+
assert_kind_of WikitextString, @wikitext_post.body
|
205
|
+
assert_not_same @wikitext_post.body, @old_body
|
206
|
+
end
|
207
|
+
|
208
|
+
should "return correct text for `to_s`" do
|
209
|
+
assert_equal "`@count = 20`", @wikitext_post.body.to_s
|
210
|
+
end
|
211
|
+
|
212
|
+
should "return correct HTML for the `to_html` method" do
|
213
|
+
assert_match(/<p><code>\@count\s\=\s20<\/code><\/p>/, @wikitext_post.body.to_html)
|
214
|
+
end
|
215
|
+
|
216
|
+
teardown do
|
217
|
+
@old_body = nil
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
teardown do
|
222
|
+
@wikitext, @wikitext_post = nil
|
223
|
+
Post.delete_all
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'with a RDoc post' do
|
228
|
+
setup do
|
229
|
+
@rdoctext = "== RDoc Test Text"
|
230
|
+
@rdoc_post = VariablePost.create!(:title => 'Blah', :body => @rdoctext, :markup_language => 'RDoc')
|
231
|
+
end
|
232
|
+
|
233
|
+
should "have a RDocText object returned for the column value" do
|
234
|
+
assert_kind_of RDocText, @rdoc_post.body
|
235
|
+
end
|
236
|
+
|
237
|
+
should "return original RDoc text for a `to_s` method call on the column value" do
|
238
|
+
assert_equal @rdoctext, @rdoc_post.body.to_s
|
239
|
+
end
|
240
|
+
|
241
|
+
should "return formated html for a `to_html` method call on the column value" do
|
242
|
+
assert_match(/<h2>\s*RDoc Test Text\s*<\/h2>/, @rdoc_post.body.to_html)
|
243
|
+
end
|
244
|
+
|
245
|
+
context "changing value of RDoc field should return new RDoc object" do
|
246
|
+
setup do
|
247
|
+
@old_body = @rdoc_post.body
|
248
|
+
@rdoc_post.body = "http://www.example.com/"
|
249
|
+
end
|
250
|
+
|
251
|
+
should "still have an RDocText object but not the same object" do
|
252
|
+
assert_kind_of RDocText, @rdoc_post.body
|
253
|
+
assert_not_same @rdoc_post.body, @old_body
|
254
|
+
end
|
255
|
+
|
256
|
+
should "return correct text for `to_s`" do
|
257
|
+
assert_equal "http://www.example.com/", @rdoc_post.body.to_s
|
258
|
+
end
|
259
|
+
|
260
|
+
should "return correct HTML for the `to_html` method" do
|
261
|
+
assert_match(/<a href="http:\/\/www.example.com">www.example.com<\/a>/, @rdoc_post.body.to_html)
|
262
|
+
end
|
263
|
+
|
264
|
+
teardown do
|
265
|
+
@old_body = nil
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
teardown do
|
270
|
+
@rdoctext, @rdoc_post = nil
|
271
|
+
Post.delete_all
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
context "with a plain text post" do
|
276
|
+
setup do
|
277
|
+
@plain_text = "Hahaha!!!"
|
278
|
+
@plain_text_post = VariablePost.create!(:title => 'Blah', :body => @plain_text, :markup_language => 'text')
|
279
|
+
end
|
280
|
+
|
281
|
+
should "have a string object returned for the column value" do
|
282
|
+
assert_kind_of String, @plain_text_post.body
|
283
|
+
end
|
284
|
+
|
285
|
+
should "return the original string with a `to_s` method call on the column value" do
|
286
|
+
assert_equal @plain_text, @plain_text_post.body.to_s
|
287
|
+
end
|
288
|
+
|
289
|
+
# FIXME: why is this failing??? both objects are String, both have EXACTLY the same value when output
|
290
|
+
# in failure message. assert_equal does not require same object. This is very odd!
|
291
|
+
should "return the original string with a `to_html` method call on the column value" do
|
292
|
+
assert_equal @plain_text, @plain_text_post.body.to_html
|
293
|
+
end
|
294
|
+
|
295
|
+
context "changing value of markup field should return new markup object" do
|
296
|
+
setup do
|
297
|
+
@plaintext_old_body = @plain_text_post.body
|
298
|
+
@plain_text_post.body = "Lorem ipsum dolor sit amet"
|
299
|
+
end
|
300
|
+
|
301
|
+
should "still have an markup object but not the same object" do
|
302
|
+
assert_kind_of String, @plain_text_post.body
|
303
|
+
assert_not_same @plain_text_post.body, @plaintext_old_body
|
304
|
+
end
|
305
|
+
|
306
|
+
should "return correct text for `to_s`" do
|
307
|
+
assert_equal "Lorem ipsum dolor sit amet", @plain_text_post.body.to_s
|
308
|
+
end
|
309
|
+
|
310
|
+
teardown do
|
311
|
+
@textile_old_body = nil
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
teardown do
|
316
|
+
@textile_text, @textile_post = nil
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
|
321
|
+
teardown do
|
322
|
+
VariablePost.delete_all
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
context 'acts_as_markup with variable language setting the language column' do
|
327
|
+
setup do
|
328
|
+
ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MARKDOWN_LIB
|
329
|
+
class ::VariableLanguagePost < ActiveRecord::Base
|
330
|
+
acts_as_markup :language => :variable, :columns => [:body], :language_column => :language_name
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
should "use the correct language column" do
|
335
|
+
markdown_text = '## Markdown Test Text'
|
336
|
+
markdown_post = VariableLanguagePost.create!(:title => 'Blah', :body => markdown_text, :language_name => 'Markdown')
|
337
|
+
|
338
|
+
assert_kind_of RDiscount, markdown_post.body
|
339
|
+
assert_equal markdown_text, markdown_post.body.to_s
|
340
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, markdown_post.body.to_html)
|
341
|
+
end
|
342
|
+
|
343
|
+
teardown do
|
344
|
+
VariableLanguagePost.delete_all
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
context 'with a nil value for the text' do
|
349
|
+
setup do
|
350
|
+
@text = nil
|
351
|
+
end
|
352
|
+
|
353
|
+
context 'with textile' do
|
354
|
+
setup do
|
355
|
+
class ::Post < ActiveRecord::Base
|
356
|
+
acts_as_textile :body
|
357
|
+
end
|
358
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
359
|
+
end
|
360
|
+
|
361
|
+
should 'return a blank string for `to_s` method' do
|
362
|
+
assert_equal @post.body.to_s, ''
|
363
|
+
end
|
364
|
+
|
365
|
+
should 'return true for .blank?' do
|
366
|
+
assert @post.body.blank?
|
367
|
+
end
|
368
|
+
|
369
|
+
should 'return a blank string for `to_html` method' do
|
370
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
371
|
+
end
|
372
|
+
|
373
|
+
should "have a RedCloth object returned for the column value" do
|
374
|
+
assert_kind_of RedCloth::TextileDoc, @post.body
|
375
|
+
end
|
376
|
+
|
377
|
+
teardown do
|
378
|
+
@post = nil
|
379
|
+
Post.delete_all
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'with wikitext' do
|
384
|
+
setup do
|
385
|
+
class ::Post < ActiveRecord::Base
|
386
|
+
acts_as_wikitext :body
|
387
|
+
end
|
388
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
389
|
+
end
|
390
|
+
|
391
|
+
should 'return a blank string for `to_s` method' do
|
392
|
+
assert_equal @post.body.to_s, ''
|
393
|
+
end
|
394
|
+
|
395
|
+
should 'return true for .blank?' do
|
396
|
+
assert @post.body.blank?
|
397
|
+
end
|
398
|
+
|
399
|
+
should 'return a blank string for `to_html` method' do
|
400
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
401
|
+
end
|
402
|
+
|
403
|
+
should "have a WikitextString object returned for the column value" do
|
404
|
+
assert_kind_of WikitextString, @post.body
|
405
|
+
end
|
406
|
+
|
407
|
+
teardown do
|
408
|
+
@post = nil
|
409
|
+
Post.delete_all
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
context 'with RDoc' do
|
414
|
+
setup do
|
415
|
+
class ::Post < ActiveRecord::Base
|
416
|
+
acts_as_rdoc :body
|
417
|
+
end
|
418
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
419
|
+
end
|
420
|
+
|
421
|
+
should 'return a blank string for `to_s` method' do
|
422
|
+
assert_equal @post.body.to_s, ''
|
423
|
+
end
|
424
|
+
|
425
|
+
should 'return true for .blank?' do
|
426
|
+
assert @post.body.blank?
|
427
|
+
end
|
428
|
+
|
429
|
+
should 'return a blank string for `to_html` method' do
|
430
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
431
|
+
end
|
432
|
+
|
433
|
+
should "have a RDocText object returned for the column value" do
|
434
|
+
assert_kind_of RDocText, @post.body
|
435
|
+
end
|
436
|
+
|
437
|
+
teardown do
|
438
|
+
@post = nil
|
439
|
+
Post.delete_all
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
context 'with RDiscount Markdown' do
|
444
|
+
setup do
|
445
|
+
ActsAsMarkup.markdown_library = :rdiscount
|
446
|
+
class ::Post < ActiveRecord::Base
|
447
|
+
acts_as_markdown :body
|
448
|
+
end
|
449
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
450
|
+
end
|
451
|
+
|
452
|
+
should 'return a blank string for `to_s` method' do
|
453
|
+
assert_equal @post.body.to_s, ''
|
454
|
+
end
|
455
|
+
|
456
|
+
should 'return true for .blank?' do
|
457
|
+
assert @post.body.blank?
|
458
|
+
end
|
459
|
+
|
460
|
+
should 'return a blank string for `to_html` method' do
|
461
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
462
|
+
end
|
463
|
+
|
464
|
+
should "have a RDiscount object returned for the column value" do
|
465
|
+
assert_kind_of RDiscount, @post.body
|
466
|
+
end
|
467
|
+
|
468
|
+
teardown do
|
469
|
+
@post = nil
|
470
|
+
Post.delete_all
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
context 'with BlueCloth Markdown' do
|
475
|
+
setup do
|
476
|
+
ActsAsMarkup.markdown_library = :bluecloth
|
477
|
+
class ::Post < ActiveRecord::Base
|
478
|
+
acts_as_markdown :body
|
479
|
+
end
|
480
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
481
|
+
end
|
482
|
+
|
483
|
+
should 'return a blank string for `to_s` method' do
|
484
|
+
assert_equal @post.body.to_s, ''
|
485
|
+
end
|
486
|
+
|
487
|
+
should 'return true for .blank?' do
|
488
|
+
assert @post.body.blank?
|
489
|
+
end
|
490
|
+
|
491
|
+
should 'return a blank string for `to_html` method' do
|
492
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
493
|
+
end
|
494
|
+
|
495
|
+
should "have a BlueCloth object returned for the column value" do
|
496
|
+
assert_kind_of BlueCloth, @post.body
|
497
|
+
end
|
498
|
+
|
499
|
+
teardown do
|
500
|
+
@post = nil
|
501
|
+
Post.delete_all
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
context 'with Ruby PEG Markdown' do
|
506
|
+
setup do
|
507
|
+
ActsAsMarkup.markdown_library = :rpeg
|
508
|
+
class ::Post < ActiveRecord::Base
|
509
|
+
acts_as_markdown :body
|
510
|
+
end
|
511
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
512
|
+
end
|
513
|
+
|
514
|
+
should 'return a blank string for `to_s` method' do
|
515
|
+
assert_equal @post.body.to_s, ''
|
516
|
+
end
|
517
|
+
|
518
|
+
should 'return true for .blank?' do
|
519
|
+
assert @post.body.blank?
|
520
|
+
end
|
521
|
+
|
522
|
+
should 'return a blank string for `to_html` method' do
|
523
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
524
|
+
end
|
525
|
+
|
526
|
+
should "have a PEGMarkdown object returned for the column value" do
|
527
|
+
assert_kind_of PEGMarkdown, @post.body
|
528
|
+
end
|
529
|
+
|
530
|
+
teardown do
|
531
|
+
@post = nil
|
532
|
+
Post.delete_all
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
context 'with Maruku Markdown' do
|
537
|
+
setup do
|
538
|
+
ActsAsMarkup.markdown_library = :maruku
|
539
|
+
class ::Post < ActiveRecord::Base
|
540
|
+
acts_as_markdown :body
|
541
|
+
end
|
542
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
543
|
+
end
|
544
|
+
|
545
|
+
should 'return a blank string for `to_s` method' do
|
546
|
+
assert_equal @post.body.to_s, ''
|
547
|
+
end
|
548
|
+
|
549
|
+
should 'return true for .blank?' do
|
550
|
+
assert @post.body.blank?
|
551
|
+
end
|
552
|
+
|
553
|
+
should 'return a blank string for `to_html` method' do
|
554
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
555
|
+
end
|
556
|
+
|
557
|
+
should "have a Maruku object returned for the column value" do
|
558
|
+
assert_kind_of Maruku, @post.body
|
559
|
+
end
|
560
|
+
|
561
|
+
teardown do
|
562
|
+
@post = nil
|
563
|
+
Post.delete_all
|
564
|
+
end
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
context 'acts_as_markup with bad language name' do
|
569
|
+
should 'raise exception when a non-supported language is passed to acts_as_markup' do
|
570
|
+
assert_raise ActsAsMarkup::UnsupportedMarkupLanguage do
|
571
|
+
class ::Post < ActiveRecord::Base
|
572
|
+
acts_as_markup :language => :fake, :columns => [:body]
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
end
|
577
|
+
|
578
|
+
context 'acts_as_markup with bad markdown library' do
|
579
|
+
should 'raise exception when a non-supported library is set as the markdown library attribute on ActsAsMarkup' do
|
580
|
+
assert_raise ActsAsMarkup::UnsportedMarkdownLibrary do
|
581
|
+
ActsAsMarkup.markdown_library = :fake
|
582
|
+
class ::Post < ActiveRecord::Base
|
583
|
+
acts_as_markup :language => :markdown, :columns => [:body]
|
584
|
+
end
|
585
|
+
end
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
def teardown
|
590
|
+
teardown_db
|
591
|
+
end
|
592
|
+
end
|
593
|
+
|