Permalink
Browse files

fix exception when field is nil

  • Loading branch information...
1 parent d7f702d commit bd4990dd21f011c78ec9ef04102b078c41e720be Ryan Sonnek committed Jun 15, 2010
Showing with 9 additions and 1 deletion.
  1. +1 −1 lib/acts_as_stripped.rb
  2. +8 −0 test/acts_as_stripped_test.rb
View
@@ -22,7 +22,7 @@ module InstanceMethods
private
def strip_fields
strippable_attributes.each do |attr|
- self[attr.to_s].strip!
+ self[attr.to_s].strip! unless self[attr.to_s].nil?
end
end
def strippable_attributes
@@ -53,6 +53,14 @@ class ActsAsStrippedTest < Test::Unit::TestCase
setup do
@post = Post.new
end
+ should 'not fail if title is nil' do
+ @post.title = nil
+ assert_nothing_raised do
+ @post.save!
+ end
+ assert_nil @post.title
+ end
+
should 'strip whitespace only from title' do
@post.title = ' hello world '
@post.body = ' awesome '

0 comments on commit bd4990d

Please sign in to comment.