Fix #5231: "Reason is too long" notice does not appear when editing an appeal
This commit is contained in:
@@ -42,8 +42,7 @@ class PostAppealsController < ApplicationController
|
||||
def update
|
||||
@post_appeal = authorize PostAppeal.find(params[:id])
|
||||
@post_appeal.update(permitted_attributes(@post_appeal))
|
||||
respond_with(@post_appeal) do |fmt|
|
||||
fmt.html { redirect_to post_path(@post_appeal.post) }
|
||||
end
|
||||
|
||||
respond_with(@post_appeal, location: @post_appeal.post)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,8 +42,7 @@ class PostFlagsController < ApplicationController
|
||||
def update
|
||||
@post_flag = authorize PostFlag.find(params[:id])
|
||||
@post_flag.update(permitted_attributes(@post_flag))
|
||||
respond_with(@post_flag) do |fmt|
|
||||
fmt.html { redirect_to post_path(@post_flag.post) }
|
||||
end
|
||||
|
||||
respond_with(@post_flag, location: @post_flag.post)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</p>
|
||||
|
||||
<%= edit_form_for(@post_appeal) do |f| %>
|
||||
<%= f.input :reason, as: :dtext, inline: true %>
|
||||
<%= f.input :reason, as: :dtext %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= dtext_preview_button "post_appeal_reason" %>
|
||||
<% end %>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</p>
|
||||
|
||||
<%= edit_form_for(@post_flag) do |f| %>
|
||||
<%= f.input :reason, as: :dtext, inline: true %>
|
||||
<%= f.input :reason, as: :dtext %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<%= dtext_preview_button "post_flag_reason" %>
|
||||
<% end %>
|
||||
|
||||
@@ -99,5 +99,42 @@ class PostAppealsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
should "allow the appealer to update the appeal" do
|
||||
@appealer = create(:user)
|
||||
@post_appeal = create(:post_appeal, creator: @appealer, reason: "xxx")
|
||||
put_auth post_appeal_path(@post_appeal), @appealer, params: { post_appeal: { reason: "yes" }}
|
||||
|
||||
assert_redirected_to @post_appeal.post
|
||||
assert_equal("yes", @post_appeal.reload.reason)
|
||||
end
|
||||
|
||||
should "return an error if the appeal is too long" do
|
||||
@appealer = create(:user)
|
||||
@post_appeal = create(:post_appeal, creator: @appealer, reason: "xxx")
|
||||
put_auth post_appeal_path(@post_appeal), @appealer, params: { post_appeal: { reason: "x"*1000 }}
|
||||
|
||||
assert_response :success
|
||||
assert_equal("xxx", @post_appeal.reload.reason)
|
||||
end
|
||||
|
||||
should "not allow the appealer to update a rejected appeal" do
|
||||
@appealer = create(:user)
|
||||
@post_appeal = create(:post_appeal, creator: @appealer, reason: "xxx", status: "rejected")
|
||||
put_auth post_appeal_path(@post_appeal), @appealer, params: { post_appeal: { reason: "no" }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal("xxx", @post_appeal.reload.reason)
|
||||
end
|
||||
|
||||
should "not allow other users to update the appeal" do
|
||||
@post_appeal = create(:post_appeal, reason: "xxx")
|
||||
put_auth post_appeal_path(@post_appeal), create(:mod_user), params: { post_appeal: { reason: "no" }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal("xxx", @post_appeal.reload.reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,6 +150,13 @@ class PostFlagsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal("no", @post_flag.reload.reason)
|
||||
end
|
||||
|
||||
should "return an error if the flag is too long" do
|
||||
put_auth post_flag_path(@post_flag), @flagger, params: { post_flag: { reason: "x"*1000 }}
|
||||
|
||||
assert_response :success
|
||||
assert_equal("xxx", @post_flag.reload.reason)
|
||||
end
|
||||
|
||||
should "not allow the flagger to update a resolved flag" do
|
||||
@post_flag.update!(status: "rejected")
|
||||
put_auth post_flag_path(@post_flag), @flagger, params: { post_flag: { reason: "no" }}
|
||||
|
||||
Reference in New Issue
Block a user