From 350e24863fba411f4ead316aaf7f5ae9bdb3879b Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 27 Aug 2017 03:38:52 +0200 Subject: [PATCH] Allow to load likes and reshares without login --- app/controllers/likes_controller.rb | 2 +- app/controllers/reshares_controller.rb | 2 +- spec/controllers/likes_controller_spec.rb | 10 +++++++++- spec/controllers/reshares_controller_spec.rb | 7 +++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index 182760951..6cbdb57ab 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -4,7 +4,7 @@ class LikesController < ApplicationController include ApplicationHelper - before_action :authenticate_user! + before_action :authenticate_user!, except: :index respond_to :html, :mobile, diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index d38f49f6a..dfd921d4a 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -1,5 +1,5 @@ class ResharesController < ApplicationController - before_action :authenticate_user! + before_action :authenticate_user!, except: :index respond_to :json def create diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb index b29fdeae9..aa490b831 100644 --- a/spec/controllers/likes_controller_spec.rb +++ b/spec/controllers/likes_controller_spec.rb @@ -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 diff --git a/spec/controllers/reshares_controller_spec.rb b/spec/controllers/reshares_controller_spec.rb index 4682baa23..e5d053f0d 100644 --- a/spec/controllers/reshares_controller_spec.rb +++ b/spec/controllers/reshares_controller_spec.rb @@ -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 -- GitLab