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

Allow to load likes and reshares without login

parent d130697c
......@@ -4,7 +4,7 @@
class LikesController < ApplicationController
include ApplicationHelper
before_action :authenticate_user!
before_action :authenticate_user!, except: :index
respond_to :html,
:mobile,
......
class ResharesController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_user!, except: :index
respond_to :json
def create
......
......@@ -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
......
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment