tristandunn-acts_as_markup 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +47 -0
- data/LICENSE +22 -0
- data/README.rdoc +170 -0
- data/Rakefile +33 -0
- data/lib/acts/.as_markup.rb.swp +0 -0
- data/lib/acts/as_markup.rb +209 -0
- data/lib/acts_as_markup.rb +75 -0
- data/lib/acts_as_markup/exts/maruku.rb +70 -0
- data/lib/acts_as_markup/exts/object.rb +5 -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 +100 -0
- data/lib/acts_as_markup/exts/simple_format.rb +18 -0
- data/lib/acts_as_markup/exts/wikitext.rb +20 -0
- data/lib/acts_as_markup/stringlike.rb +7 -0
- data/tasks/bones.rake +21 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +41 -0
- data/tasks/post_load.rake +32 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +249 -0
- data/tasks/test.rake +29 -0
- data/test/.acts_as_markup_test.rb.swp +0 -0
- data/test/acts_as_markdown_test.rb +298 -0
- data/test/acts_as_markup_test.rb +636 -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/test_helper.rb +69 -0
- data/tristandunn-acts_as_markup.gemspec +52 -0
- metadata +162 -0
Binary file
|
@@ -0,0 +1,298 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
2
|
+
|
3
|
+
class ActsAsMarkdownTest < ActsAsMarkupTestCase
|
4
|
+
context 'acts_as_markdown' do
|
5
|
+
setup do
|
6
|
+
@markdown_text = '## Markdown Test Text'
|
7
|
+
end
|
8
|
+
|
9
|
+
context 'using RDiscount' do
|
10
|
+
setup do
|
11
|
+
ActsAsMarkup.markdown_library = :rdiscount
|
12
|
+
class ::Post < ActiveRecord::Base
|
13
|
+
acts_as_markdown :body
|
14
|
+
end
|
15
|
+
@post = Post.create!(:title => 'Blah', :body => @markdown_text)
|
16
|
+
end
|
17
|
+
|
18
|
+
should_act_like_a_string
|
19
|
+
|
20
|
+
should "have a RDiscount object returned for the column value" do
|
21
|
+
assert_kind_of RDiscount, @post.body
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
25
|
+
assert_equal @markdown_text, @post.body.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'return false for .blank?' do
|
29
|
+
assert !@post.body.blank?
|
30
|
+
end
|
31
|
+
|
32
|
+
should "return formatted html for a `to_html` method call on the column value" do
|
33
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
34
|
+
end
|
35
|
+
|
36
|
+
should "not return escaped html" do
|
37
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
38
|
+
assert_match(/<i>Test<\/i>/, @post.body.to_html)
|
39
|
+
end
|
40
|
+
|
41
|
+
context "changing value of markdown field should return new markdown object" do
|
42
|
+
setup do
|
43
|
+
@old_body = @post.body
|
44
|
+
@post.body = "`@count = 20`"
|
45
|
+
end
|
46
|
+
|
47
|
+
should "still have an RDiscount object but not the same object" do
|
48
|
+
assert_kind_of RDiscount, @post.body
|
49
|
+
assert_not_same @post.body, @old_body
|
50
|
+
end
|
51
|
+
|
52
|
+
should "return correct text for `to_s`" do
|
53
|
+
assert_equal "`@count = 20`", @post.body.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
should "return correct HTML for the `to_html` method" do
|
57
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
|
58
|
+
end
|
59
|
+
|
60
|
+
teardown do
|
61
|
+
@old_body = nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
teardown do
|
66
|
+
@post = nil
|
67
|
+
Post.delete_all
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'using RDiscount with options' do
|
72
|
+
setup do
|
73
|
+
class ::Post
|
74
|
+
acts_as_markdown :body, :markdown_options => [ :filter_html ]
|
75
|
+
end
|
76
|
+
@post = Post.new(:title => 'Blah')
|
77
|
+
end
|
78
|
+
|
79
|
+
should "return escaped html because of :filter_html" do
|
80
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
81
|
+
assert_match(/<i>Test<\/i>/, @post.body.to_html)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'using Ruby PEG Markdown' do
|
86
|
+
setup do
|
87
|
+
ActsAsMarkup.markdown_library = :rpeg
|
88
|
+
class ::Post < ActiveRecord::Base
|
89
|
+
acts_as_markdown :body
|
90
|
+
end
|
91
|
+
@post = Post.create!(:title => 'Blah', :body => @markdown_text)
|
92
|
+
end
|
93
|
+
|
94
|
+
should_act_like_a_string
|
95
|
+
|
96
|
+
should "have a Ruby PEG Markdown object returned for the column value" do
|
97
|
+
assert_kind_of PEGMarkdown, @post.body
|
98
|
+
end
|
99
|
+
|
100
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
101
|
+
assert_equal @markdown_text, @post.body.to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
should 'return false for .blank?' do
|
105
|
+
assert !@post.body.blank?
|
106
|
+
end
|
107
|
+
|
108
|
+
should "return formated html for a `to_html` method call on the column value" do
|
109
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
110
|
+
end
|
111
|
+
|
112
|
+
should "not return escaped html" do
|
113
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
114
|
+
assert_match(/<i>Test<\/i>/, @post.body.to_html)
|
115
|
+
end
|
116
|
+
|
117
|
+
context "changing value of markdown field should return new markdown object" do
|
118
|
+
setup do
|
119
|
+
@old_body = @post.body
|
120
|
+
@post.body = "`@count = 20`"
|
121
|
+
end
|
122
|
+
|
123
|
+
should "still have an PEGMarkdown object but not the same object" do
|
124
|
+
assert_kind_of PEGMarkdown, @post.body
|
125
|
+
assert_not_same @post.body, @old_body
|
126
|
+
end
|
127
|
+
|
128
|
+
should "return correct text for `to_s`" do
|
129
|
+
assert_equal "`@count = 20`", @post.body.to_s
|
130
|
+
end
|
131
|
+
|
132
|
+
should "return correct HTML for the `to_html` method" do
|
133
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
|
134
|
+
end
|
135
|
+
|
136
|
+
teardown do
|
137
|
+
@old_body = nil
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
teardown do
|
142
|
+
@post = nil
|
143
|
+
Post.delete_all
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'using Ruby PEG Markdown with options' do
|
148
|
+
setup do
|
149
|
+
class ::Post
|
150
|
+
acts_as_markdown :body, :markdown_options => [ :filter_html ]
|
151
|
+
end
|
152
|
+
@post = Post.new(:title => 'Blah')
|
153
|
+
end
|
154
|
+
|
155
|
+
should "return no html because of :filter_html" do
|
156
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
157
|
+
assert_match(/Markdown Test Text/, @post.body.to_html)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'using BlueCloth' do
|
162
|
+
setup do
|
163
|
+
ActsAsMarkup.markdown_library = :bluecloth
|
164
|
+
class ::Post < ActiveRecord::Base
|
165
|
+
acts_as_markdown :body
|
166
|
+
end
|
167
|
+
@post = Post.create!(:title => 'Blah', :body => @markdown_text)
|
168
|
+
end
|
169
|
+
|
170
|
+
should_act_like_a_string
|
171
|
+
|
172
|
+
should "have a BlueCloth object returned for the column value" do
|
173
|
+
assert_kind_of BlueCloth, @post.body
|
174
|
+
end
|
175
|
+
|
176
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
177
|
+
assert_equal @markdown_text, @post.body.to_s
|
178
|
+
end
|
179
|
+
|
180
|
+
should 'return false for .blank?' do
|
181
|
+
assert !@post.body.blank?
|
182
|
+
end
|
183
|
+
|
184
|
+
should "return formated html for a `to_html` method call on the column value" do
|
185
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
186
|
+
end
|
187
|
+
|
188
|
+
should "not return escaped html" do
|
189
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
190
|
+
assert_match(/<i>Test<\/i>/, @post.body.to_html)
|
191
|
+
end
|
192
|
+
|
193
|
+
context "changing value of markdown field should return new markdown object" do
|
194
|
+
setup do
|
195
|
+
@old_body = @post.body
|
196
|
+
@post.body = "`@count = 20`"
|
197
|
+
end
|
198
|
+
|
199
|
+
should "still have an BlueCloth object but not the same object" do
|
200
|
+
assert_kind_of BlueCloth, @post.body
|
201
|
+
assert_not_same @post.body, @old_body
|
202
|
+
end
|
203
|
+
|
204
|
+
should "return correct text for `to_s`" do
|
205
|
+
assert_equal "`@count = 20`", @post.body.to_s
|
206
|
+
end
|
207
|
+
|
208
|
+
should "return correct HTML for the `to_html` method" do
|
209
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
|
210
|
+
end
|
211
|
+
|
212
|
+
teardown do
|
213
|
+
@old_body = nil
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
teardown do
|
218
|
+
@post = nil
|
219
|
+
Post.delete_all
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'using BlueCloth with options' do
|
224
|
+
setup do
|
225
|
+
class ::Post
|
226
|
+
acts_as_markdown :body, :markdown_options => [ :filter_html ]
|
227
|
+
end
|
228
|
+
@post = Post.new(:title => 'Blah')
|
229
|
+
end
|
230
|
+
|
231
|
+
should "return escaped html because of :filter_html" do
|
232
|
+
@post.body = "## Markdown <i>Test</i> Text"
|
233
|
+
assert_match(/<i>Test<\/i>/, @post.body.to_html)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context 'using Maruku' do
|
238
|
+
setup do
|
239
|
+
ActsAsMarkup.markdown_library = :maruku
|
240
|
+
class ::Post < ActiveRecord::Base
|
241
|
+
acts_as_markdown :body
|
242
|
+
end
|
243
|
+
@post = Post.create!(:title => 'Blah', :body => @markdown_text)
|
244
|
+
end
|
245
|
+
|
246
|
+
should_act_like_a_string
|
247
|
+
|
248
|
+
should "have a Maruku object returned for the column value" do
|
249
|
+
assert_kind_of Maruku, @post.body
|
250
|
+
end
|
251
|
+
|
252
|
+
should "return original markdown text for a `to_s` method call on the column value" do
|
253
|
+
assert_equal @markdown_text, @post.body.to_s
|
254
|
+
end
|
255
|
+
|
256
|
+
should 'return false for .blank?' do
|
257
|
+
assert !@post.body.blank?
|
258
|
+
end
|
259
|
+
|
260
|
+
should "return formated html for a `to_html` method call on the column value" do
|
261
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
|
262
|
+
end
|
263
|
+
|
264
|
+
context "changing value of markdown field should return new markdown object" do
|
265
|
+
setup do
|
266
|
+
@old_body = @post.body
|
267
|
+
@post.body = "`@count = 20`"
|
268
|
+
end
|
269
|
+
|
270
|
+
should "still have an Maruku object but not the same object" do
|
271
|
+
assert_kind_of Maruku, @post.body
|
272
|
+
assert_not_same @post.body, @old_body
|
273
|
+
end
|
274
|
+
|
275
|
+
should "return correct text for `to_s`" do
|
276
|
+
assert_equal "`@count = 20`", @post.body.to_s
|
277
|
+
end
|
278
|
+
|
279
|
+
should "return correct HTML for the `to_html` method" do
|
280
|
+
assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
|
281
|
+
end
|
282
|
+
|
283
|
+
teardown do
|
284
|
+
@old_body = nil
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
teardown do
|
289
|
+
@post = nil
|
290
|
+
Post.delete_all
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
teardown do
|
295
|
+
@markdown_text = nil
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,636 @@
|
|
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(/<tt>\@count\s\=\s20<\/tt>/, @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 raw post" do
|
276
|
+
setup do
|
277
|
+
@raw_text = "Hahaha!!!"
|
278
|
+
@raw_text_post = VariablePost.create!(:title => 'Blah', :body => @raw_text, :markup_language => 'text')
|
279
|
+
end
|
280
|
+
|
281
|
+
should "have a string object returned for the column value" do
|
282
|
+
assert_kind_of String, @raw_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 @raw_text, @raw_text_post.body.to_s
|
287
|
+
end
|
288
|
+
|
289
|
+
should "return the original string with a `to_html` method call on the column value" do
|
290
|
+
assert_equal @raw_text, @raw_text_post.body.to_html
|
291
|
+
end
|
292
|
+
|
293
|
+
context "changing value of markup field should return new markup object" do
|
294
|
+
setup do
|
295
|
+
@raw_old_body = @raw_text_post.body
|
296
|
+
@raw_text_post.body = "Lorem ipsum dolor sit amet"
|
297
|
+
end
|
298
|
+
|
299
|
+
should "still have an markup object but not the same object" do
|
300
|
+
assert_kind_of String, @raw_text_post.body
|
301
|
+
assert_not_same @raw_text_post.body, @raw_old_body
|
302
|
+
end
|
303
|
+
|
304
|
+
should "return correct text for `to_s`" do
|
305
|
+
assert_equal "Lorem ipsum dolor sit amet", @raw_text_post.body.to_s
|
306
|
+
end
|
307
|
+
|
308
|
+
teardown do
|
309
|
+
@raw_old_body = nil
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
teardown do
|
314
|
+
@raw_text, @raw_post = nil
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context "with a simple format post" do
|
319
|
+
setup do
|
320
|
+
@simple_text = "Hello,\nWorld!\n\nHow are you?"
|
321
|
+
@simple_text_post = VariablePost.create!(:title => 'Blah', :body => @simple_text, :markup_language => 'simple_format')
|
322
|
+
end
|
323
|
+
|
324
|
+
should "have a string object returned for the column value" do
|
325
|
+
assert_kind_of SimpleFormat, @simple_text_post.body
|
326
|
+
end
|
327
|
+
|
328
|
+
should "return the original string with a `to_s` method call on the column value" do
|
329
|
+
assert_equal @simple_text, @simple_text_post.body.to_s
|
330
|
+
end
|
331
|
+
|
332
|
+
should "return the original string with a `to_html` method call on the column value" do
|
333
|
+
assert_equal "<p>Hello,\n<br />World!</p>\n\n<p>How are you?</p>", @simple_text_post.body.to_html
|
334
|
+
end
|
335
|
+
|
336
|
+
context "changing value of markup field should return new markup object" do
|
337
|
+
setup do
|
338
|
+
@simple_old_body = @simple_text_post.body
|
339
|
+
@simple_text_post.body = "Lorem ipsum dolor sit amet"
|
340
|
+
end
|
341
|
+
|
342
|
+
should "still have an markup object but not the same object" do
|
343
|
+
assert_kind_of SimpleFormat, @simple_text_post.body
|
344
|
+
assert_not_same @simple_text_post.body, @simple_old_body
|
345
|
+
end
|
346
|
+
|
347
|
+
should "return correct text for `to_s`" do
|
348
|
+
assert_equal "Lorem ipsum dolor sit amet", @simple_text_post.body.to_s
|
349
|
+
end
|
350
|
+
|
351
|
+
should "return correct text for `to_html`" do
|
352
|
+
assert_equal "<p>Lorem ipsum dolor sit amet</p>", @simple_text_post.body.to_html
|
353
|
+
end
|
354
|
+
|
355
|
+
teardown do
|
356
|
+
@simple_old_body = nil
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
teardown do
|
361
|
+
@simple_text, @simple_post = nil
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
teardown do
|
366
|
+
VariablePost.delete_all
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
context 'acts_as_markup with variable language setting the language column' do
|
371
|
+
setup do
|
372
|
+
ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MARKDOWN_LIB
|
373
|
+
class ::VariableLanguagePost < ActiveRecord::Base
|
374
|
+
acts_as_markup :language => :variable, :columns => [:body], :language_column => :language_name
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
should "use the correct language column" do
|
379
|
+
markdown_text = '## Markdown Test Text'
|
380
|
+
markdown_post = VariableLanguagePost.create!(:title => 'Blah', :body => markdown_text, :language_name => 'Markdown')
|
381
|
+
|
382
|
+
assert_kind_of RDiscount, markdown_post.body
|
383
|
+
assert_equal markdown_text, markdown_post.body.to_s
|
384
|
+
assert_match(/<h2(\s\w+\=['"]\w*['"])*\s*>\s*Markdown Test Text\s*<\/h2>/, markdown_post.body.to_html)
|
385
|
+
end
|
386
|
+
|
387
|
+
teardown do
|
388
|
+
VariableLanguagePost.delete_all
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
context 'with a nil value for the text' do
|
393
|
+
setup do
|
394
|
+
@text = nil
|
395
|
+
end
|
396
|
+
|
397
|
+
context 'with textile' do
|
398
|
+
setup do
|
399
|
+
class ::Post < ActiveRecord::Base
|
400
|
+
acts_as_textile :body
|
401
|
+
end
|
402
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
403
|
+
end
|
404
|
+
|
405
|
+
should 'return a blank string for `to_s` method' do
|
406
|
+
assert_equal @post.body.to_s, ''
|
407
|
+
end
|
408
|
+
|
409
|
+
should 'return true for .blank?' do
|
410
|
+
assert @post.body.blank?
|
411
|
+
end
|
412
|
+
|
413
|
+
should 'return a blank string for `to_html` method' do
|
414
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
415
|
+
end
|
416
|
+
|
417
|
+
should "have a RedCloth object returned for the column value" do
|
418
|
+
assert_kind_of RedCloth::TextileDoc, @post.body
|
419
|
+
end
|
420
|
+
|
421
|
+
teardown do
|
422
|
+
@post = nil
|
423
|
+
Post.delete_all
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
context 'with wikitext' do
|
428
|
+
setup do
|
429
|
+
class ::Post < ActiveRecord::Base
|
430
|
+
acts_as_wikitext :body
|
431
|
+
end
|
432
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
433
|
+
end
|
434
|
+
|
435
|
+
should 'return a blank string for `to_s` method' do
|
436
|
+
assert_equal @post.body.to_s, ''
|
437
|
+
end
|
438
|
+
|
439
|
+
should 'return true for .blank?' do
|
440
|
+
assert @post.body.blank?
|
441
|
+
end
|
442
|
+
|
443
|
+
should 'return a blank string for `to_html` method' do
|
444
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
445
|
+
end
|
446
|
+
|
447
|
+
should "have a WikitextString object returned for the column value" do
|
448
|
+
assert_kind_of WikitextString, @post.body
|
449
|
+
end
|
450
|
+
|
451
|
+
teardown do
|
452
|
+
@post = nil
|
453
|
+
Post.delete_all
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
context 'with RDoc' do
|
458
|
+
setup do
|
459
|
+
class ::Post < ActiveRecord::Base
|
460
|
+
acts_as_rdoc :body
|
461
|
+
end
|
462
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
463
|
+
end
|
464
|
+
|
465
|
+
should 'return a blank string for `to_s` method' do
|
466
|
+
assert_equal @post.body.to_s, ''
|
467
|
+
end
|
468
|
+
|
469
|
+
should 'return true for .blank?' do
|
470
|
+
assert @post.body.blank?
|
471
|
+
end
|
472
|
+
|
473
|
+
should 'return a blank string for `to_html` method' do
|
474
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
475
|
+
end
|
476
|
+
|
477
|
+
should "have a RDocText object returned for the column value" do
|
478
|
+
assert_kind_of RDocText, @post.body
|
479
|
+
end
|
480
|
+
|
481
|
+
teardown do
|
482
|
+
@post = nil
|
483
|
+
Post.delete_all
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context 'with RDiscount Markdown' do
|
488
|
+
setup do
|
489
|
+
ActsAsMarkup.markdown_library = :rdiscount
|
490
|
+
class ::Post < ActiveRecord::Base
|
491
|
+
acts_as_markdown :body
|
492
|
+
end
|
493
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
494
|
+
end
|
495
|
+
|
496
|
+
should 'return a blank string for `to_s` method' do
|
497
|
+
assert_equal @post.body.to_s, ''
|
498
|
+
end
|
499
|
+
|
500
|
+
should 'return true for .blank?' do
|
501
|
+
assert @post.body.blank?
|
502
|
+
end
|
503
|
+
|
504
|
+
should 'return a blank string for `to_html` method' do
|
505
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
506
|
+
end
|
507
|
+
|
508
|
+
should "have a RDiscount object returned for the column value" do
|
509
|
+
assert_kind_of RDiscount, @post.body
|
510
|
+
end
|
511
|
+
|
512
|
+
teardown do
|
513
|
+
@post = nil
|
514
|
+
Post.delete_all
|
515
|
+
end
|
516
|
+
end
|
517
|
+
|
518
|
+
context 'with BlueCloth Markdown' do
|
519
|
+
setup do
|
520
|
+
ActsAsMarkup.markdown_library = :bluecloth
|
521
|
+
class ::Post < ActiveRecord::Base
|
522
|
+
acts_as_markdown :body
|
523
|
+
end
|
524
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
525
|
+
end
|
526
|
+
|
527
|
+
should 'return a blank string for `to_s` method' do
|
528
|
+
assert_equal @post.body.to_s, ''
|
529
|
+
end
|
530
|
+
|
531
|
+
should 'return true for .blank?' do
|
532
|
+
assert @post.body.blank?
|
533
|
+
end
|
534
|
+
|
535
|
+
should 'return a blank string for `to_html` method' do
|
536
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
537
|
+
end
|
538
|
+
|
539
|
+
should "have a BlueCloth object returned for the column value" do
|
540
|
+
assert_kind_of BlueCloth, @post.body
|
541
|
+
end
|
542
|
+
|
543
|
+
teardown do
|
544
|
+
@post = nil
|
545
|
+
Post.delete_all
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
context 'with Ruby PEG Markdown' do
|
550
|
+
setup do
|
551
|
+
ActsAsMarkup.markdown_library = :rpeg
|
552
|
+
class ::Post < ActiveRecord::Base
|
553
|
+
acts_as_markdown :body
|
554
|
+
end
|
555
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
556
|
+
end
|
557
|
+
|
558
|
+
should 'return a blank string for `to_s` method' do
|
559
|
+
assert_equal @post.body.to_s, ''
|
560
|
+
end
|
561
|
+
|
562
|
+
should 'return true for .blank?' do
|
563
|
+
assert @post.body.blank?
|
564
|
+
end
|
565
|
+
|
566
|
+
should 'return a blank string for `to_html` method' do
|
567
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
568
|
+
end
|
569
|
+
|
570
|
+
should "have a PEGMarkdown object returned for the column value" do
|
571
|
+
assert_kind_of PEGMarkdown, @post.body
|
572
|
+
end
|
573
|
+
|
574
|
+
teardown do
|
575
|
+
@post = nil
|
576
|
+
Post.delete_all
|
577
|
+
end
|
578
|
+
end
|
579
|
+
|
580
|
+
context 'with Maruku Markdown' do
|
581
|
+
setup do
|
582
|
+
ActsAsMarkup.markdown_library = :maruku
|
583
|
+
class ::Post < ActiveRecord::Base
|
584
|
+
acts_as_markdown :body
|
585
|
+
end
|
586
|
+
@post = Post.create!(:title => 'Blah', :body => @text)
|
587
|
+
end
|
588
|
+
|
589
|
+
should 'return a blank string for `to_s` method' do
|
590
|
+
assert_equal @post.body.to_s, ''
|
591
|
+
end
|
592
|
+
|
593
|
+
should 'return true for .blank?' do
|
594
|
+
assert @post.body.blank?
|
595
|
+
end
|
596
|
+
|
597
|
+
should 'return a blank string for `to_html` method' do
|
598
|
+
assert_match(/[\n\s]*/, @post.body.to_html)
|
599
|
+
end
|
600
|
+
|
601
|
+
should "have a Maruku object returned for the column value" do
|
602
|
+
assert_kind_of Maruku, @post.body
|
603
|
+
end
|
604
|
+
|
605
|
+
teardown do
|
606
|
+
@post = nil
|
607
|
+
Post.delete_all
|
608
|
+
end
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
context 'acts_as_markup with bad language name' do
|
613
|
+
should 'raise exception when a non-supported language is passed to acts_as_markup' do
|
614
|
+
assert_raise ActsAsMarkup::UnsupportedMarkupLanguage do
|
615
|
+
class ::Post < ActiveRecord::Base
|
616
|
+
acts_as_markup :language => :fake, :columns => [:body]
|
617
|
+
end
|
618
|
+
end
|
619
|
+
end
|
620
|
+
end
|
621
|
+
|
622
|
+
context 'acts_as_markup with bad markdown library' do
|
623
|
+
should 'raise exception when a non-supported library is set as the markdown library attribute on ActsAsMarkup' do
|
624
|
+
assert_raise ActsAsMarkup::UnsportedMarkdownLibrary do
|
625
|
+
ActsAsMarkup.markdown_library = :fake
|
626
|
+
class ::Post < ActiveRecord::Base
|
627
|
+
acts_as_markup :language => :markdown, :columns => [:body]
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|
631
|
+
end
|
632
|
+
|
633
|
+
def teardown
|
634
|
+
teardown_db
|
635
|
+
end
|
636
|
+
end
|