Skip to content

Commit

Permalink
fix exception when field is nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Sonnek committed Jun 15, 2010
1 parent d7f702d commit bd4990d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/acts_as_stripped.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/acts_as_stripped_test.rb
Expand Up @@ -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 '
Expand Down

0 comments on commit bd4990d

Please sign in to comment.