Skip to content

Commit f6a2209

Browse files
committed
Fix undoing a post deletion when the post had comments (thanks amw).
Closes xaviershay#13.
1 parent 8f9e5c4 commit f6a2209

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/models/delete_post_undo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def process!
77
transaction do
88
post = Post.create!(post_attributes)
99
loaded_data[:comments].each do |comment|
10-
post.comments.create!(comment.except('id'))
10+
post.comments.create!(comment.except('id', 'post_id'))
1111
end
1212
self.destroy
1313
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require File.dirname(__FILE__) + '/../spec_helper'
2+
3+
describe DeletePostUndo do
4+
describe '#process!' do
5+
it 'creates a new post with comments based on the attributes stored in #data' do
6+
post = Post.create!(:title => 'a', :body => 'b').tap do |post|
7+
post.comments.create!(:author => 'Don', :author_url => '', :author_email => '', :body => 'comment')
8+
end
9+
item = post.destroy_with_undo
10+
new_post = item.process!
11+
new_post.comments.count.should == 1
12+
end
13+
end
14+
end

0 commit comments

Comments
 (0)