post versions: fix undo action.
This commit is contained in:
@@ -24,7 +24,7 @@ class PostVersionsController < ApplicationController
|
|||||||
@post_version = authorize PostVersion.find(params[:id])
|
@post_version = authorize PostVersion.find(params[:id])
|
||||||
@post_version.undo!
|
@post_version.undo!
|
||||||
|
|
||||||
respond_with(@post_version)
|
respond_with(@post_version, location: post_versions_path(search: { post_id: @post_version.post_id }))
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% t.column do |post_version| %>
|
<% t.column do |post_version| %>
|
||||||
<% if policy(post_version).can_undo? %>
|
<% if policy(post_version).undo? %>
|
||||||
<%= link_to "Undo", undo_post_version_path(post_version), method: :put, remote: true, class: "post-version-undo-link" %>
|
<%= link_to "Undo", undo_post_version_path(post_version), method: :put, remote: true, class: "post-version-undo-link" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if listing_type(:post_id) == :revert && policy(post_version.post).revert? %>
|
<% if listing_type(:post_id) == :revert && policy(post_version.post).revert? %>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class PostVersionsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
@user = create(:user)
|
@user = create(:user)
|
||||||
|
|
||||||
as(@user) do
|
as(@user) do
|
||||||
@post = create(:post, tag_string: "tagme", rating: "s")
|
@post = create(:post, tag_string: "tagme", rating: "s", source: "blah")
|
||||||
travel(2.hours) { @post.update(tag_string: "1 2", source: "xxx") }
|
travel(2.hours) { @post.update(tag_string: "1 2", source: "xxx") }
|
||||||
travel(4.hours) { @post.update(tag_string: "2 3", rating: "e") }
|
travel(4.hours) { @post.update(tag_string: "2 3", rating: "e") }
|
||||||
@post2 = create(:post)
|
@post2 = create(:post)
|
||||||
@@ -45,10 +45,11 @@ class PostVersionsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "undo action" do
|
context "undo action" do
|
||||||
should "undo the edit" do
|
should "undo the edit" do
|
||||||
put_auth undo_post_version_path(@post.versions.first), @user
|
put_auth undo_post_version_path(@post.versions.second), @user
|
||||||
assert_response :success
|
assert_response :redirect
|
||||||
assert_equal("s", @post.reload.rating)
|
assert_equal("e", @post.reload.rating)
|
||||||
assert_equal("tagme", @post.reload.tag_string)
|
assert_equal("3 tagme", @post.tag_string)
|
||||||
|
assert_equal("blah", @post.source)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "not allow non-members to undo edits" do
|
should "not allow non-members to undo edits" do
|
||||||
|
|||||||
Reference in New Issue
Block a user