diff --git a/app/controllers/post_appeals_controller.rb b/app/controllers/post_appeals_controller.rb index c3924c032..99f46c2e2 100644 --- a/app/controllers/post_appeals_controller.rb +++ b/app/controllers/post_appeals_controller.rb @@ -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 diff --git a/app/controllers/post_flags_controller.rb b/app/controllers/post_flags_controller.rb index 7ec3f729f..486ccdbb9 100644 --- a/app/controllers/post_flags_controller.rb +++ b/app/controllers/post_flags_controller.rb @@ -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 diff --git a/app/views/post_appeals/edit.html.erb b/app/views/post_appeals/edit.html.erb index a5554fd50..ef07a583c 100644 --- a/app/views/post_appeals/edit.html.erb +++ b/app/views/post_appeals/edit.html.erb @@ -7,7 +7,7 @@

<%= 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 %> diff --git a/app/views/post_flags/edit.html.erb b/app/views/post_flags/edit.html.erb index ad878b25a..a6f919846 100644 --- a/app/views/post_flags/edit.html.erb +++ b/app/views/post_flags/edit.html.erb @@ -7,7 +7,7 @@

<%= 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 %> diff --git a/test/functional/post_appeals_controller_test.rb b/test/functional/post_appeals_controller_test.rb index 1f1b5fd58..f87875d3c 100644 --- a/test/functional/post_appeals_controller_test.rb +++ b/test/functional/post_appeals_controller_test.rb @@ -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 diff --git a/test/functional/post_flags_controller_test.rb b/test/functional/post_flags_controller_test.rb index 64c50bd55..df5fe3715 100644 --- a/test/functional/post_flags_controller_test.rb +++ b/test/functional/post_flags_controller_test.rb @@ -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" }}