Unverified Commit 350e2486 authored by Benjamin Neff's avatar Benjamin Neff Committed by Steffen van Bergerem
Browse files

Allow to load likes and reshares without login

parent d130697c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@

class LikesController < ApplicationController
  include ApplicationHelper
  before_action :authenticate_user!
  before_action :authenticate_user!, except: :index

  respond_to :html,
             :mobile,
+1 −1
Original line number Diff line number Diff line
class ResharesController < ApplicationController
  before_action :authenticate_user!
  before_action :authenticate_user!, except: :index
  respond_to :json

  def create
+9 −1
Original line number Diff line number Diff line
@@ -91,7 +91,15 @@ describe LikesController, type: :controller do

    it "returns an empty array for a post with no likes" do
      get :index, params: {post_id: @message.id}
      expect(JSON.parse(response.body).map(&:id)).to eq([])
      expect(JSON.parse(response.body)).to eq([])
    end

    it "returns likes for a public post without login" do
      post = alice.post(:status_message, text: "hey", public: true)
      bob.like!(post)
      sign_out :user
      get :index, params: {post_id: post.id}, format: :json
      expect(JSON.parse(response.body).map {|h| h["id"] }).to match_array(post.likes.map(&:id))
    end
  end

+7 −0
Original line number Diff line number Diff line
@@ -101,6 +101,13 @@ describe ResharesController, :type => :controller do
        get :index, params: {post_id: @post.id}, format: :json
        expect(JSON.parse(response.body)).to eq([])
      end

      it "returns reshares without login" do
        bob.reshare!(@post)
        sign_out :user
        get :index, params: {post_id: @post.id}, format: :json
        expect(JSON.parse(response.body).map {|h| h["id"] }).to match_array(@post.reshares.map(&:id))
      end
    end
  end
end