acts_as_markup 0.1.0

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/tasks/test.rake ADDED
@@ -0,0 +1,34 @@
1
+ require 'rake/testtask'
2
+
3
+ namespace :test do
4
+
5
+ Rake::TestTask.new(:run) do |t|
6
+ t.libs = PROJ.libs
7
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
8
+ else PROJ.test.files end
9
+ t.ruby_opts += PROJ.ruby_opts
10
+ t.ruby_opts += PROJ.test.opts
11
+ end
12
+
13
+ if HAVE_RCOV
14
+ desc 'Run rcov on the unit tests'
15
+ task :rcov => :clobber_rcov do
16
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
17
+ opts = opts.join(' ')
18
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
19
+ else PROJ.test.files end
20
+ files = files.join(' ')
21
+ sh "#{RCOV} #{files} #{opts}"
22
+ end
23
+
24
+ task :clobber_rcov do
25
+ rm_r 'coverage' rescue nil
26
+ end
27
+ end
28
+
29
+ end # namespace :test
30
+
31
+ desc 'Alias to test:run'
32
+ task :test => 'test:run'
33
+
34
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
@@ -0,0 +1,305 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsMarkupTest < Test::Unit::TestCase
4
+ def setup
5
+ setup_db
6
+ end
7
+
8
+ context 'acts_as_markdown' do
9
+ setup do
10
+ @markdown_text = '## Markdown Test Text'
11
+ end
12
+
13
+ context 'using RDiscount' do
14
+ setup do
15
+ ActsAsMarkup.markdown_library = :rdiscount
16
+ class ::Post < ActiveRecord::Base
17
+ acts_as_markdown :body
18
+ end
19
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
20
+ end
21
+
22
+ should "have a RDiscount object returned for the column value" do
23
+ assert_kind_of RDiscount, @post.body
24
+ end
25
+
26
+ should "return original markdown text for a `to_s` method call on the column value" do
27
+ assert_equal @markdown_text, @post.body.to_s
28
+ end
29
+
30
+ should "return formated html for a `to_html` method call on the column value" do
31
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
32
+ end
33
+
34
+ context "changing value of markdown field should return new markdown object" do
35
+ setup do
36
+ @old_body = @post.body
37
+ @post.body = "`@count = 20`"
38
+ end
39
+
40
+ should "still have an RDiscount object but not the same object" do
41
+ assert_kind_of RDiscount, @post.body
42
+ assert_not_same @post.body, @old_body
43
+ end
44
+
45
+ should "return correct text for `to_s`" do
46
+ assert_equal "`@count = 20`", @post.body.to_s
47
+ end
48
+
49
+ should "return correct HTML for the `to_html` method" do
50
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
51
+ end
52
+
53
+ teardown do
54
+ @old_body = nil
55
+ end
56
+ end
57
+
58
+ teardown do
59
+ @post = nil
60
+ Post.delete_all
61
+ end
62
+ end
63
+
64
+ context 'using Ruby PEG Markdown' do
65
+ setup do
66
+ ActsAsMarkup.markdown_library = :rpeg
67
+ class ::Post < ActiveRecord::Base
68
+ acts_as_markdown :body
69
+ end
70
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
71
+ end
72
+
73
+ should "have a Ruby PEG Markdown object returned for the column value" do
74
+ assert_kind_of PEGMarkdown, @post.body
75
+ end
76
+
77
+ should "return original markdown text for a `to_s` method call on the column value" do
78
+ assert_equal @markdown_text, @post.body.to_s
79
+ end
80
+
81
+ should "return formated html for a `to_html` method call on the column value" do
82
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
83
+ end
84
+
85
+ context "changing value of markdown field should return new markdown object" do
86
+ setup do
87
+ @old_body = @post.body
88
+ @post.body = "`@count = 20`"
89
+ end
90
+
91
+ should "still have an PEGMarkdown object but not the same object" do
92
+ assert_kind_of PEGMarkdown, @post.body
93
+ assert_not_same @post.body, @old_body
94
+ end
95
+
96
+ should "return correct text for `to_s`" do
97
+ assert_equal "`@count = 20`", @post.body.to_s
98
+ end
99
+
100
+ should "return correct HTML for the `to_html` method" do
101
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
102
+ end
103
+
104
+ teardown do
105
+ @old_body = nil
106
+ end
107
+ end
108
+
109
+ teardown do
110
+ @post = nil
111
+ Post.delete_all
112
+ end
113
+ end
114
+
115
+ context 'using BlueCloth' do
116
+ setup do
117
+ ActsAsMarkup.markdown_library = :bluecloth
118
+ class ::Post < ActiveRecord::Base
119
+ acts_as_markdown :body
120
+ end
121
+ @post = Post.create!(:title => 'Blah', :body => @markdown_text)
122
+ end
123
+
124
+ should "have a BlueCloth object returned for the column value" do
125
+ assert_kind_of BlueCloth, @post.body
126
+ end
127
+
128
+ should "return original markdown text for a `to_s` method call on the column value" do
129
+ assert_equal @markdown_text, @post.body.to_s
130
+ end
131
+
132
+ should "return formated html for a `to_html` method call on the column value" do
133
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @post.body.to_html)
134
+ end
135
+
136
+ context "changing value of markdown field should return new markdown object" do
137
+ setup do
138
+ @old_body = @post.body
139
+ @post.body = "`@count = 20`"
140
+ end
141
+
142
+ should "still have an BlueCloth object but not the same object" do
143
+ assert_kind_of BlueCloth, @post.body
144
+ assert_not_same @post.body, @old_body
145
+ end
146
+
147
+ should "return correct text for `to_s`" do
148
+ assert_equal "`@count = 20`", @post.body.to_s
149
+ end
150
+
151
+ should "return correct HTML for the `to_html` method" do
152
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @post.body.to_html)
153
+ end
154
+
155
+ teardown do
156
+ @old_body = nil
157
+ end
158
+ end
159
+
160
+ teardown do
161
+ @post = nil
162
+ Post.delete_all
163
+ end
164
+ end
165
+
166
+ teardown do
167
+ @markdown_text = nil
168
+ end
169
+ end
170
+
171
+ context 'acts_as_textile' do
172
+ setup do
173
+ @textile_text = "h2. Textile Test Text"
174
+ class ::Post < ActiveRecord::Base
175
+ acts_as_textile :body
176
+ end
177
+ @post = Post.create!(:title => 'Blah', :body => @textile_text)
178
+ end
179
+
180
+ should "have a RedCloth object returned for the column value" do
181
+ assert_kind_of RedCloth::TextileDoc, @post.body
182
+ end
183
+
184
+ should "return original textile text for a `to_s` method call on the column value" do
185
+ assert_equal @textile_text, @post.body.to_s
186
+ end
187
+
188
+ should "return formated html for a `to_html` method call on the column value" do
189
+ assert_match(/<h2>Textile Test Text<\/h2>/, @post.body.to_html)
190
+ end
191
+
192
+ context "changing value of textile field should return new textile object" do
193
+ setup do
194
+ @old_body = @post.body
195
+ @post.body = "@@count = 20@"
196
+ end
197
+
198
+ should "still have an RedCloth object but not the same object" do
199
+ assert_kind_of RedCloth::TextileDoc, @post.body
200
+ assert_not_same @post.body, @old_body
201
+ end
202
+
203
+ should "return correct text for `to_s`" do
204
+ assert_equal "@@count = 20@", @post.body.to_s
205
+ end
206
+
207
+ should "return correct HTML for the `to_html` method" do
208
+ assert_match(/<code>\@count\s\=\s20<\/code>/, @post.body.to_html)
209
+ end
210
+
211
+ teardown do
212
+ @old_body = nil
213
+ end
214
+ end
215
+
216
+ teardown do
217
+ @textile_text, @post = nil
218
+ Post.delete_all
219
+ end
220
+ end
221
+
222
+ context 'acts_as_markup' do
223
+ setup do
224
+ ActsAsMarkup.markdown_library = ActsAsMarkup::DEFAULT_MAKRDOWN_LIB
225
+
226
+ @textile_text = "h2. Textile Test Text"
227
+ class ::TextilePost < ActiveRecord::Base
228
+ acts_as_markup :language => :textile, :columns => [:body]
229
+ end
230
+ @textile_post = TextilePost.create!(:title => 'Blah', :body => @textile_text)
231
+
232
+ @markdown_text = '## Markdown Test Text'
233
+ class ::MarkdownPost < ActiveRecord::Base
234
+ acts_as_markup :language => :markdown, :columns => [:body]
235
+ end
236
+ @markdown_post = MarkdownPost.create!(:title => 'Blah', :body => @markdown_text)
237
+ end
238
+
239
+ should "have a markup object returned for the column value" do
240
+ assert_kind_of RedCloth::TextileDoc, @textile_post.body
241
+ assert_kind_of RDiscount, @markdown_post.body
242
+ end
243
+
244
+ should "return original markup text for a `to_s` method call on the column value" do
245
+ assert_equal @markdown_text, @markdown_post.body.to_s
246
+ assert_equal @textile_text, @textile_post.body.to_s
247
+ end
248
+
249
+ should "return formated html for a `to_html` method call on the column value" do
250
+ assert_match(/<h2>\s*Markdown Test Text\s*<\/h2>/, @markdown_post.body.to_html)
251
+ assert_match(/<h2>Textile Test Text<\/h2>/, @textile_post.body.to_html)
252
+ end
253
+
254
+ context "changing value of markup field should return new markup object" do
255
+ setup do
256
+ @markdown_old_body = @markdown_post.body
257
+ @markdown_post.body = "`@count = 20`"
258
+ @textile_old_body = @textile_post.body
259
+ @textile_post.body = "@@count = 20@"
260
+ end
261
+
262
+ should "still have an markup object but not the same object" do
263
+ assert_kind_of RedCloth::TextileDoc, @textile_post.body
264
+ assert_not_same @markdown_post.body, @markdown_old_body
265
+ assert_kind_of RDiscount, @markdown_post.body
266
+ assert_not_same @textile_post.body, @textile_old_body
267
+ end
268
+
269
+ should "return correct text for `to_s`" do
270
+ assert_equal "`@count = 20`", @markdown_post.body.to_s
271
+ assert_equal "@@count = 20@", @textile_post.body.to_s
272
+ end
273
+
274
+ should "return correct HTML for the `to_html` method" do
275
+ assert_match(/<code>\s*\@count\s\=\s20\s*<\/code>/, @markdown_post.body.to_html)
276
+ assert_match(/<code>\@count\s\=\s20<\/code>/, @textile_post.body.to_html)
277
+ end
278
+
279
+ teardown do
280
+ @markdown_old_body, @textile_old_body = nil
281
+ end
282
+ end
283
+
284
+ teardown do
285
+ @textile_text, @textile_post, @markdown_text, @markdown_post = nil
286
+ TextilePost.delete_all
287
+ MarkdownPost.delete_all
288
+ end
289
+ end
290
+
291
+ context 'acts_as_markup with bad language name' do
292
+ should 'raise exception when a non-supported language is passed to acts_as_markup' do
293
+ assert_raise ActsAsMarkup::UnsportedMarkupLanguage do
294
+ class ::Post < ActiveRecord::Base
295
+ acts_as_markup :language => :wiki, :columns => [:body]
296
+ end
297
+ end
298
+ end
299
+ end
300
+
301
+ def teardown
302
+ teardown_db
303
+ end
304
+ end
305
+
@@ -0,0 +1,33 @@
1
+ require 'test/unit'
2
+ require 'shoulda'
3
+ require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib acts_as_markup]) )
4
+
5
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:")
6
+
7
+ def setup_db
8
+ ActiveRecord::Schema.define(:version => 1) do
9
+ create_table :posts do |t|
10
+ t.column :title, :string
11
+ t.column :body, :text
12
+ t.timestamps
13
+ end
14
+
15
+ create_table :markdown_posts do |t|
16
+ t.column :title, :string
17
+ t.column :body, :text
18
+ t.timestamps
19
+ end
20
+
21
+ create_table :textile_posts do |t|
22
+ t.column :title, :string
23
+ t.column :body, :text
24
+ t.timestamps
25
+ end
26
+ end
27
+ end
28
+
29
+ def teardown_db
30
+ ActiveRecord::Base.connection.tables.each do |table|
31
+ ActiveRecord::Base.connection.drop_table(table)
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_markup
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Landau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-06 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.1.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: activerecord
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rdiscount
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.2.7
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: redcloth
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML.
56
+ email: brian.landau@viget.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE.txt
63
+ - README.rdoc
64
+ files:
65
+ - History.txt
66
+ - LICENSE.txt
67
+ - Manifest.txt
68
+ - README.rdoc
69
+ - Rakefile
70
+ - acts_as_markup.gemspec
71
+ - lib/acts/as_markup.rb
72
+ - lib/acts_as_markup.rb
73
+ - lib/acts_as_markup/exts/rdiscount.rb
74
+ - tasks/bones.rake
75
+ - tasks/gem.rake
76
+ - tasks/git.rake
77
+ - tasks/manifest.rake
78
+ - tasks/post_load.rake
79
+ - tasks/rdoc.rake
80
+ - tasks/rubyforge.rake
81
+ - tasks/setup.rb
82
+ - tasks/test.rake
83
+ - test/acts_as_markup_test.rb
84
+ - test/test_helper.rb
85
+ has_rdoc: true
86
+ homepage: http://viget.rubyforge.com/acts_as_markup
87
+ post_install_message:
88
+ rdoc_options:
89
+ - --main
90
+ - README.rdoc
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: "0"
104
+ version:
105
+ requirements: []
106
+
107
+ rubyforge_project: viget
108
+ rubygems_version: 1.2.0
109
+ signing_key:
110
+ specification_version: 2
111
+ summary: Represent ActiveRecord Markdown or Textile text columns as Markdown or Textile objects using various external libraries to convert to HTML
112
+ test_files:
113
+ - test/acts_as_markup_test.rb