Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correctly handle invalid published at when editing a post.

Closes #38.
  • Loading branch information...
commit a0077587186a93275b9605b2f53ab244e7d50551 1 parent e33ea8d
@xaviershay authored
Showing with 11 additions and 1 deletion.
  1. +3 −1 app/models/post.rb
  2. +8 −0 spec/models/post_spec.rb
View
4 app/models/post.rb
@@ -105,7 +105,9 @@ def apply_filter
def set_dates
self.edited_at = Time.now if self.edited_at.nil? || !minor_edit?
- self.published_at = Chronic.parse(self.published_at_natural)
+ if new_published_at = Chronic.parse(self.published_at_natural)
+ self.published_at = new_published_at
+ end
end
def denormalize_comments_count!
View
8 spec/models/post_spec.rb
@@ -124,6 +124,14 @@
post.set_dates
post.published_at.should == now
end
+
+ it 'does not set published_at if published_at_natural is invalid' do
+ now = Time.now
+ post = Post.new(:published_at_natural => 'bogus', :published_at => now)
+ Chronic.should_receive(:parse).with('bogus').and_return(nil)
+ post.set_dates
+ post.published_at.should == now
+ end
end
describe Post, "#minor_edit" do
Please sign in to comment.
Something went wrong with that request. Please try again.