acts_as_markup_on 1.0.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.
@@ -0,0 +1,152 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsMediawikiTest < ActsAsMarkupOnTestCase
4
+ context 'acts_as_mediawiki_on' do
5
+ setup do
6
+ @wikitext = "== Wikitext Test Text =="
7
+ end
8
+
9
+ context 'using Wikitext' do
10
+ setup do
11
+ ActsAsMarkupOn.mediawiki_library = :wikitext
12
+ class ::Post < ActiveRecord::Base
13
+ acts_as_mediawiki_on :body
14
+ end
15
+ @post = Post.create!(:title => 'Blah', :body => @wikitext)
16
+ end
17
+
18
+ should "have a WikitextString object returned for the column value" do
19
+ assert_kind_of WikitextString, @post.body
20
+ end
21
+
22
+ should "return original wikitext text for a `to_s` method call on the column value" do
23
+ assert_equal @wikitext, @post.body.to_s
24
+ end
25
+
26
+ should 'return false for .blank?' do
27
+ assert !@post.body.blank?
28
+ end
29
+
30
+ should "return formated html for a `to_html` method call on the column value" do
31
+ assert_match(/<h2>Wikitext Test Text<\/h2>/, @post.body.to_html)
32
+ end
33
+
34
+ should "underscore spaces in URLs" do
35
+ @post.body = "[[foo bar]]"
36
+ assert_match(/<a href="\/wiki\/foo_bar">foo bar<\/a>/, @post.body.to_html)
37
+ end
38
+
39
+ context "changing value of wikitext field should return new wikitext object" do
40
+ setup do
41
+ @old_body = @post.body
42
+ @post.body = "`@count = 20`"
43
+ end
44
+
45
+ should "still have an WikitextString object but not the same object" do
46
+ assert_kind_of WikitextString, @post.body
47
+ assert_not_same @post.body, @old_body
48
+ end
49
+
50
+ should "return correct text for `to_s`" do
51
+ assert_equal "`@count = 20`", @post.body.to_s
52
+ end
53
+
54
+ should "return correct HTML for the `to_html` method" do
55
+ assert_match(/<p><code>\@count\s\=\s20<\/code><\/p>/, @post.body.to_html)
56
+ end
57
+
58
+ teardown do
59
+ @old_body = nil
60
+ end
61
+ end
62
+
63
+ teardown do
64
+ @post = nil
65
+ Post.delete_all
66
+ end
67
+ end
68
+
69
+ context 'using Wikitext with options' do
70
+ setup do
71
+ ActsAsMarkupOn.mediawiki_library = :wikitext
72
+ class ::Post
73
+ acts_as_mediawiki_on :body, :mediawiki_options => [ { :space_to_underscore => false } ]
74
+ end
75
+ @post = Post.new(:title => 'Blah')
76
+ end
77
+
78
+ should "not underscore spaces in URLs because of :space_to_underscore option" do
79
+ @post.body = "[[foo bar]]"
80
+ assert_match(/<a href="\/wiki\/foo%20bar">foo bar<\/a>/, @post.body.to_html)
81
+ end
82
+
83
+ teardown do
84
+ @post = nil
85
+ end
86
+ end
87
+
88
+ context 'using WikiCloth' do
89
+ setup do
90
+ ActsAsMarkupOn.mediawiki_library = :wikicloth
91
+ class ::Post < ActiveRecord::Base
92
+ acts_as_mediawiki_on :body
93
+ end
94
+ @post = Post.create!(:title => 'Blah', :body => @wikitext)
95
+ end
96
+
97
+ should "have a WikitextString object returned for the column value" do
98
+ assert_kind_of WikiClothText, @post.body
99
+ end
100
+
101
+ should "return original wikitext text for a `to_s` method call on the column value" do
102
+ assert_equal @wikitext, @post.body.to_s
103
+ end
104
+
105
+ should 'return false for .blank?' do
106
+ assert !@post.body.blank?
107
+ end
108
+
109
+ should "return formated html for a `to_html` method call on the column value" do
110
+ assert_match(/<h2>.*Wikitext Test Text.*<\/h2>/, @post.body.to_html)
111
+ end
112
+
113
+ should "render a link" do
114
+ @post.body = "[http://www.example.com/ Test]"
115
+ assert_match(%r[<a href="http://www.example.com/" target="_blank">Test</a>], @post.body.to_html)
116
+ end
117
+
118
+ context "changing value of wikitext field should return new wikitext object" do
119
+ setup do
120
+ @old_body = @post.body
121
+ @post.body = "'''This is very important'''"
122
+ end
123
+
124
+ should "still have an WikitextString object but not the same object" do
125
+ assert_kind_of WikiClothText, @post.body
126
+ assert_not_same @post.body, @old_body
127
+ end
128
+
129
+ should "return correct text for `to_s`" do
130
+ assert_equal "'''This is very important'''", @post.body.to_s
131
+ end
132
+
133
+ should "return correct HTML for the `to_html` method" do
134
+ assert_match(/<p><b>This is very important<\/b><\/p>/, @post.body.to_html)
135
+ end
136
+
137
+ teardown do
138
+ @old_body = nil
139
+ end
140
+ end
141
+
142
+ teardown do
143
+ @post = nil
144
+ Post.delete_all
145
+ end
146
+ end
147
+
148
+ teardown do
149
+ @wikitext = nil
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsRDocTest < ActsAsMarkupOnTestCase
4
+ context 'acts_as_rdoc' do
5
+ setup do
6
+ @rdoctext = "== RDoc Test Text"
7
+ class ::Post < ActiveRecord::Base
8
+ acts_as_rdoc_on :body
9
+ end
10
+ @post = Post.create!(:title => 'Blah', :body => @rdoctext)
11
+ end
12
+
13
+ should "have a RDocText object returned for the column value" do
14
+ assert_kind_of RDocText, @post.body
15
+ end
16
+
17
+ should "return original RDoc text for a `to_s` method call on the column value" do
18
+ assert_equal @rdoctext, @post.body.to_s
19
+ end
20
+
21
+ should 'return false for .blank?' do
22
+ assert !@post.body.blank?
23
+ end
24
+
25
+ should "return formated html for a `to_html` method call on the column value" do
26
+ assert_match(/<h2[^>]*>\s*RDoc Test Text\s*<\/h2>/, @post.body.to_html)
27
+ end
28
+
29
+ context "changing value of RDoc field should return new RDoc object" do
30
+ setup do
31
+ @old_body = @post.body
32
+ @post.body = "http://www.example.com/"
33
+ end
34
+
35
+ should "still have an RDocText object but not the same object" do
36
+ assert_kind_of RDocText, @post.body
37
+ assert_not_same @post.body, @old_body
38
+ end
39
+
40
+ should "return correct text for `to_s`" do
41
+ assert_equal "http://www.example.com/", @post.body.to_s
42
+ end
43
+
44
+ should "return correct HTML for the `to_html` method" do
45
+ assert_match(/<a href="http:\/\/www.example.com">www.example.com<\/a>/, @post.body.to_html)
46
+ end
47
+
48
+ teardown do
49
+ @old_body = nil
50
+ end
51
+ end
52
+
53
+ teardown do
54
+ @rdoctext, @post = nil
55
+ Post.delete_all
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class ActsAsTextileTest < ActsAsMarkupOnTestCase
4
+ context 'acts_as_textile_on' do
5
+ setup do
6
+ @textile_text = "h2. Textile Test Text"
7
+ class ::Post < ActiveRecord::Base
8
+ acts_as_textile_on :body
9
+ end
10
+ @post = Post.create!(:title => 'Blah', :body => @textile_text)
11
+ end
12
+
13
+ should "have a RedCloth object returned for the column value" do
14
+ assert_kind_of RedCloth::TextileDoc, @post.body
15
+ end
16
+
17
+ should "return original textile text for a `to_s` method call on the column value" do
18
+ assert_equal @textile_text, @post.body.to_s
19
+ end
20
+
21
+ should 'return false for .blank?' do
22
+ assert !@post.body.blank?
23
+ end
24
+
25
+ should "return formated html for a `to_html` method call on the column value" do
26
+ assert_match(/<h2>Textile Test Text<\/h2>/, @post.body.to_html)
27
+ end
28
+
29
+ should "not return escaped html" do
30
+ @post.body = "h2. Textile <i>Test</i> Text"
31
+ assert_match(/<i>Test<\/i>/, @post.body.to_html)
32
+ end
33
+
34
+ context "changing value of textile field should return new textile object" do
35
+ setup do
36
+ @old_body = @post.body
37
+ @post.body = "@@count = 20@"
38
+ end
39
+
40
+ should "still have an RedCloth object but not the same object" do
41
+ assert_kind_of RedCloth::TextileDoc, @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>\@count\s\=\s20<\/code>/, @post.body.to_html)
51
+ end
52
+
53
+ teardown do
54
+ @old_body = nil
55
+ end
56
+ end
57
+
58
+ teardown do
59
+ @textile_text, @post = nil
60
+ Post.delete_all
61
+ end
62
+ end
63
+
64
+ context 'acts_as_textile with options' do
65
+ setup do
66
+ class ::Post
67
+ acts_as_textile_on :body, :textile_options => [ [ :filter_html ] ]
68
+ end
69
+ @post = Post.new(:title => 'Blah')
70
+ end
71
+
72
+ should "return escaped html because of :filter_html" do
73
+ @post.body = "h2. Textile <i>Test</i> Text"
74
+ assert_match(/&lt;i&gt;Test&lt;\/i&gt;/, @post.body.to_html)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,84 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+
16
+ require 'acts_as_markup_on'
17
+ require 'acts_as_markup_on/exts/object'
18
+ require 'acts_as_markup_on/stringlike'
19
+ require 'acts_as_markup_on/active_record_extension'
20
+ require 'active_record'
21
+
22
+ ActiveRecord::Schema.verbose = false
23
+ ActiveRecord::Base.send :include, ActsAsMarkupOn::ActiveRecordExtension
24
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
25
+ ActsAsMarkupOn.markdown_library = :rdiscount
26
+
27
+ def setup_db
28
+ ActiveRecord::Schema.define(:version => 1) do
29
+ create_table :posts do |t|
30
+ t.column :title, :string
31
+ t.column :body, :text
32
+ t.timestamps
33
+ end
34
+
35
+ create_table :markdown_posts do |t|
36
+ t.column :title, :string
37
+ t.column :body, :text
38
+ t.timestamps
39
+ end
40
+
41
+ create_table :textile_posts do |t|
42
+ t.column :title, :string
43
+ t.column :body, :text
44
+ t.timestamps
45
+ end
46
+
47
+ create_table :variable_posts do |t|
48
+ t.column :title, :string
49
+ t.column :body, :text
50
+ t.column :markup_language, :string
51
+ t.timestamps
52
+ end
53
+
54
+ create_table :variable_language_posts do |t|
55
+ t.column :title, :string
56
+ t.column :body, :text
57
+ t.column :language_name, :string
58
+ t.timestamps
59
+ end
60
+ end
61
+ end
62
+
63
+ def teardown_db
64
+ ActiveRecord::Base.connection.tables.each do |table|
65
+ ActiveRecord::Base.connection.drop_table(table)
66
+ end
67
+ end
68
+
69
+ class ActsAsMarkupOnTestCase < Test::Unit::TestCase
70
+ def setup
71
+ setup_db
72
+ end
73
+
74
+ def teardown
75
+ teardown_db
76
+ end
77
+
78
+ def self.should_act_like_a_string
79
+ should "act like a string" do
80
+ assert_equal @post.body.split(' '), ['##', 'Markdown', 'Test', 'Text']
81
+ assert @post.body.match(/Te[sx]t/)
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,258 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_markup_on
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brian Landau
8
+ - Iskander Haziev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 4.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 4.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: activesupport
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 4.0.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: 4.0.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: wikicloth
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rdiscount
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.1.7
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.1.7
70
+ - !ruby/object:Gem::Dependency
71
+ name: wikitext
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 4.0.2
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 4.0.2
84
+ - !ruby/object:Gem::Dependency
85
+ name: RedCloth
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ~>
89
+ - !ruby/object:Gem::Version
90
+ version: '4.2'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ~>
96
+ - !ruby/object:Gem::Version
97
+ version: '4.2'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rake
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '='
103
+ - !ruby/object:Gem::Version
104
+ version: 10.1.0
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '='
110
+ - !ruby/object:Gem::Version
111
+ version: 10.1.0
112
+ - !ruby/object:Gem::Dependency
113
+ name: shoulda
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: sqlite3
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: rpeg-markdown
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: bluecloth
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: maruku
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: redcarpet
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - '>='
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - '>='
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ description: Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as
197
+ Markdown, Textile Wikitext, RDoc objects using various external libraries to convert
198
+ to HTML.
199
+ email: 0@droidlabs.pro
200
+ executables: []
201
+ extensions: []
202
+ extra_rdoc_files:
203
+ - LICENSE
204
+ - README.rdoc
205
+ files:
206
+ - CHANGELOG
207
+ - Gemfile
208
+ - Gemfile.lock
209
+ - LICENSE
210
+ - README.rdoc
211
+ - Rakefile
212
+ - acts_as_markup_on.gemspec
213
+ - lib/acts_as_markup_on.rb
214
+ - lib/acts_as_markup_on/active_record_extension.rb
215
+ - lib/acts_as_markup_on/exts/bluecloth.rb
216
+ - lib/acts_as_markup_on/exts/maruku.rb
217
+ - lib/acts_as_markup_on/exts/object.rb
218
+ - lib/acts_as_markup_on/exts/peg_markdown.rb
219
+ - lib/acts_as_markup_on/exts/rdiscount.rb
220
+ - lib/acts_as_markup_on/exts/rdoc.rb
221
+ - lib/acts_as_markup_on/exts/redcarpet.rb
222
+ - lib/acts_as_markup_on/exts/wikicloth.rb
223
+ - lib/acts_as_markup_on/exts/wikitext.rb
224
+ - lib/acts_as_markup_on/railtie.rb
225
+ - lib/acts_as_markup_on/stringlike.rb
226
+ - lib/acts_as_markup_on/version.rb
227
+ - test/acts_as_markdown_test.rb
228
+ - test/acts_as_markup_test.rb
229
+ - test/acts_as_mediawiki_test.rb
230
+ - test/acts_as_rdoc_test.rb
231
+ - test/acts_as_textile_test.rb
232
+ - test/test_helper.rb
233
+ homepage: http://github.com/gvalmon/acts_as_markup_on/
234
+ licenses:
235
+ - MIT
236
+ metadata: {}
237
+ post_install_message:
238
+ rdoc_options: []
239
+ require_paths:
240
+ - lib
241
+ required_ruby_version: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - '>='
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ required_rubygems_version: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - '>='
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ requirements: []
252
+ rubyforge_project:
253
+ rubygems_version: 2.1.8
254
+ signing_key:
255
+ specification_version: 4
256
+ summary: Represent ActiveRecord Markdown, Textile, Wiki text, RDoc columns as Markdown,
257
+ Textile Wikitext, RDoc objects using various external libraries to convert to HTML.
258
+ test_files: []