Commit 89f92296 authored by azul's avatar azul

fix redirect after deleting post without js

We were redirecting to page_url which failed for
deleting direct personal posts which do not have a page
associated.

Includes test that triggered the exception and is now fixed.
parent d27fda55
......@@ -30,7 +30,17 @@ module Common::Posts
@post.destroy
respond_to do |format|
format.js { render template: 'common/posts/destroy' }
format.html { redirect_to page_url(@page) }
format.html { redirect_to parent_redirect }
end
end
protected
def parent_redirect
if @page.present?
page_url(@page)
else
{action: :index}
end
end
......
......@@ -32,4 +32,15 @@ class Me::PostsControllerTest < ActionController::TestCase
assert_response :success
end
end
def test_delete_post_without_js
me = users(:blue)
you = users(:red)
post = Message.send from: me, to: you, body: 'test message'
login_as me
assert_difference 'Post.count', -1 do
delete :destroy, discussion_id: you.login, id: post
assert_response :redirect
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment