diff --git a/Changelog.md b/Changelog.md index 3d5dfa0ac4e6049d3dfd4b6d3a172e6716c5fff3..1affbef9af02c53b9a10445e8578535f6d6f25ad 100644 --- a/Changelog.md +++ b/Changelog.md @@ -23,6 +23,7 @@ * More buttons in mobile streams are fixed [#7036](https://github.com/diaspora/diaspora/pull/7036) * Fixed missing sidebar background in the contacts tab [#7064](https://github.com/diaspora/diaspora/pull/7064) * Fix tags URLs in hovercards [#7075](https://github.com/diaspora/diaspora/pull/7075) +* Fix 500 in html requests for post interactions [#7085](https://github.com/diaspora/diaspora/pull/7085) ## Features * Deleted comments will be removed when loading more comments [#7045](https://github.com/diaspora/diaspora/pull/7045) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index be2c2dcc90a9a15af2021a22bf1d112f1b104a61..e88af7a778496aea22ef8949eff25b1f05ca6387 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -41,8 +41,13 @@ class PostsController < ApplicationController end def interactions - post = post_service.find!(params[:id]) - respond_with PostInteractionPresenter.new(post, current_user) + respond_to do |format| + format.json { + post = post_service.find!(params[:id]) + render json: PostInteractionPresenter.new(post, current_user) + } + format.any { render nothing: true, status: 406 } + end end def destroy diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 7c3bb4384852412aa0ee8a44f650197c99f28b09..82464ad3a4011983719739e5b5424cb8fca78983 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -136,6 +136,38 @@ describe PostsController, type: :controller do end end + describe "#interactions" do + context "user not signed in" do + it "returns a 401 for private posts and format json" do + get :interactions, id: post.id, format: :json + expect(response.status).to eq(401) + expect(JSON.parse(response.body)["error"]).to eq(I18n.t("devise.failure.unauthenticated")) + end + + it "returns a 406 for private posts and format html" do + get :interactions, id: post.id + expect(response.status).to eq(406) + end + end + + context "user signed in" do + before do + sign_in alice + end + + it "shows interactions of a post as json" do + get :interactions, id: post.id, format: :json + expect(response.body).to eq(PostInteractionPresenter.new(post, alice).to_json) + end + + it "returns a 406 for format html" do + sign_in alice + get :interactions, id: post.id + expect(response.status).to eq(406) + end + end + end + describe "#destroy" do context "own post" do before do diff --git a/spec/factories.rb b/spec/factories.rb index 3d4fd827f8387a5e424d2a64b0c45933b9d7e305..72ad1d109c589a1cc7e3b933d8818dcaad7dbbec 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -321,13 +321,6 @@ FactoryGirl.define do additional_data { {"new_property" => "some text"} } end - #templates - factory(:status_with_photo_backdrop, :parent => :status_message_with_photo) - - factory(:photo_backdrop, :parent => :status_message_with_photo) do - text "" - end - factory(:note, :parent => :status_message) do text SecureRandom.hex(1000) end