Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Fix issue with object.attribute_plain overwriting the original attr…

…ibute [Thanks, James]

* Fix issue with attributes trying to work on nil values [Thanks again, James]
  • Loading branch information...
commit 00d9c68f045884eb77f50c44c4d3313a40ae289c 1 parent eaca44e
@defunkt authored
Showing with 21 additions and 3 deletions.
  1. +5 −0 CHANGES
  2. +3 −3 lib/acts_as_textiled.rb
  3. +13 −0 test/test_textiled.rb
View
5 CHANGES
@@ -1,3 +1,8 @@
+= 0.2
+
+ * Fix issue with object.attribute_plain overwriting the original attribute [Thanks, James]
+ * Fix issue with attributes trying to work on nil values [Thanks again, James]
+
= 0.1
* Initial import
View
6 lib/acts_as_textiled.rb
@@ -12,9 +12,9 @@ def acts_as_textiled(*attrs)
attrs.each do |attr|
define_method(attr) do
- textiled[attr.to_s] ||= RedCloth.new(read_attribute(attr), Array(ruled[attr])).to_html
+ textiled[attr.to_s] ||= RedCloth.new(read_attribute(attr), Array(ruled[attr])).to_html if read_attribute(attr)
end
- define_method("#{attr}_plain", proc { strip_redcloth_html(__send__(attr)) } )
+ define_method("#{attr}_plain", proc { strip_redcloth_html(__send__(attr)) if __send__(attr) } )
define_method("#{attr}_source", proc { __send__("#{attr}_before_type_cast") } )
end
@@ -51,7 +51,7 @@ def write_attribute(attr_name, value)
private
def strip_redcloth_html(html)
- html.gsub!(html_regexp, '')
+ html = html.dup.gsub!(html_regexp, '')
redcloth_glyphs.each do |(entity, char)|
html.gsub!(entity, char)
end
View
13 test/test_textiled.rb
@@ -3,6 +3,14 @@
class TestTextiled < Test::Unit::TestCase
fixtures :stories, :authors
+ def test_empty_fields
+ story = Story.new
+
+ assert_equal nil, story.description
+ assert_equal nil, story.description_source
+ assert_equal nil, story.description_plain
+ end
+
def test_desc_is_html
story = Story.find(1)
@@ -13,6 +21,11 @@ def test_desc_is_html
assert_equal desc_html, story.description
assert_equal desc_textile, story.description_source
assert_equal desc_plain, story.description_plain
+
+ # make sure we don't overwrite anything - thanks James
+ assert_equal desc_html, story.description
+ assert_equal desc_textile, story.description_source
+ assert_equal desc_plain, story.description_plain
end
def test_desc_after_save
Please sign in to comment.
Something went wrong with that request. Please try again.