def test_destroy_with_comment(client): topic = Topic.create({ 'title': 'title1', 'body': 'body1' }) comment1 = Comment.create({ 'topic_id': topic.id(), 'body': 'body1' }) comment2 = Comment.create({ 'topic_id': topic.id(), 'body': 'body2' }) topic.destroy() assert(not Topic.is_exists(topic.id())) assert(not Comment.is_exists(comment1.id())) assert(not Comment.is_exists(comment2.id()))
def new_comment(id): topic = Topic.find(id) if request.method == 'POST': Comment.create({ 'topic_id': topic.id(), 'body': request.form['comment_body'] }) return redirect(url_for('topic.show', id=id)) else: return render_template('comments/new.html', topic=topic)
def test_destroy(client): topic = Topic.create({'title': 'title1', 'body': 'body1'}) comment = Comment.create({'topic_id': topic.id(), 'body': 'body1'}) comment.destroy() assert (Topic.is_exists(topic.id())) assert (not Comment.is_exists(comment.id()))