Allow to load likes and reshares without login

This commit is contained in:
Benjamin Neff 2017-08-27 03:38:52 +02:00 committed by Steffen van Bergerem
parent d130697ce2
commit 350e24863f
No known key found for this signature in database
GPG key ID: 315C9787D548DC6B
4 changed files with 18 additions and 3 deletions

View file

@ -4,7 +4,7 @@
class LikesController < ApplicationController
include ApplicationHelper
before_action :authenticate_user!
before_action :authenticate_user!, except: :index
respond_to :html,
:mobile,

View file

@ -1,5 +1,5 @@
class ResharesController < ApplicationController
before_action :authenticate_user!
before_action :authenticate_user!, except: :index
respond_to :json
def create

View file

@ -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

View file

@ -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