parent
b375bfa630
commit
c203c1eb94
7 changed files with 1 additions and 108 deletions
|
|
@ -1,17 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module InterimStreamHackinessHelper
|
module InterimStreamHackinessHelper
|
||||||
def commenting_disabled?(post)
|
|
||||||
return true unless user_signed_in?
|
|
||||||
if defined?(@commenting_disabled)
|
|
||||||
@commenting_disabled
|
|
||||||
elsif defined?(@stream)
|
|
||||||
!@stream.can_comment?(post)
|
|
||||||
else
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
##### These methods need to go away once we pass publisher object into the partial ######
|
##### These methods need to go away once we pass publisher object into the partial ######
|
||||||
def publisher_formatted_text
|
def publisher_formatted_text
|
||||||
if params[:prefill].present?
|
if params[:prefill].present?
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@
|
||||||
|
|
||||||
.stream
|
.stream
|
||||||
= render partial: "shared/stream_element",
|
= render partial: "shared/stream_element",
|
||||||
locals: {post: post, commenting_disabled: commenting_disabled?(post), expanded_info: true}
|
locals: {post: post, expanded_info: true}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -80,15 +80,6 @@ class Stream::Aspect < Stream::Base
|
||||||
@all_aspects ||= aspects.size == user.aspects.size
|
@all_aspects ||= aspects.size == user.aspects.size
|
||||||
end
|
end
|
||||||
|
|
||||||
# This is perfomance optimization, as everyone in your aspect stream you have
|
|
||||||
# a contact.
|
|
||||||
#
|
|
||||||
# @param post [Post]
|
|
||||||
# @return [Boolean]
|
|
||||||
def can_comment?(post)
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def aspect_ids
|
def aspect_ids
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,6 @@ class Stream::Base
|
||||||
'change me in lib/base_stream.rb!'
|
'change me in lib/base_stream.rb!'
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Boolean]
|
|
||||||
def can_comment?(post)
|
|
||||||
return true if post.author.local?
|
|
||||||
post_is_from_contact?(post)
|
|
||||||
end
|
|
||||||
|
|
||||||
def post_from_group(post)
|
def post_from_group(post)
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
@ -105,13 +99,4 @@ class Stream::Base
|
||||||
def contacts_in_stream
|
def contacts_in_stream
|
||||||
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map(&:id)).load
|
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map(&:id)).load
|
||||||
end
|
end
|
||||||
|
|
||||||
# @param post [Post]
|
|
||||||
# @return [Boolean]
|
|
||||||
def post_is_from_contact?(post)
|
|
||||||
@can_comment_cache ||= {}
|
|
||||||
@can_comment_cache[post.id] ||= contacts_in_stream.find{|contact| contact.person_id == post.author.id}.present?
|
|
||||||
@can_comment_cache[post.id] ||= (user.person_id == post.author_id)
|
|
||||||
@can_comment_cache[post.id]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@ class Stream::Public < Stream::Base
|
||||||
@posts ||= Post.all_public
|
@posts ||= Post.all_public
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_comment?(post)
|
|
||||||
post.author.local?
|
|
||||||
end
|
|
||||||
|
|
||||||
# Override base class method
|
# Override base class method
|
||||||
def aspects
|
def aspects
|
||||||
["public"]
|
["public"]
|
||||||
|
|
|
||||||
|
|
@ -1,41 +1,6 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
describe InterimStreamHackinessHelper, type: :helper do
|
describe InterimStreamHackinessHelper, type: :helper do
|
||||||
describe "commenting_disabled?" do
|
|
||||||
include Devise::Test::ControllerHelpers
|
|
||||||
|
|
||||||
before do
|
|
||||||
sign_in alice
|
|
||||||
def user_signed_in?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if no user is signed in' do
|
|
||||||
def user_signed_in?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
expect(commenting_disabled?(double)).to eq(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if @commenting_disabled is set' do
|
|
||||||
@commenting_disabled = true
|
|
||||||
expect(commenting_disabled?(double)).to eq(true)
|
|
||||||
@commenting_disabled = false
|
|
||||||
expect(commenting_disabled?(double)).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns @stream.can_comment? if @stream is set' do
|
|
||||||
post = double
|
|
||||||
@stream = double
|
|
||||||
expect(@stream).to receive(:can_comment?).with(post).and_return(true)
|
|
||||||
expect(commenting_disabled?(post)).to eq(false)
|
|
||||||
|
|
||||||
expect(@stream).to receive(:can_comment?).with(post).and_return(false)
|
|
||||||
expect(commenting_disabled?(post)).to eq(true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#publisher_formatted_text" do
|
describe "#publisher_formatted_text" do
|
||||||
it "returns the prefill text from the stream" do
|
it "returns the prefill text from the stream" do
|
||||||
@stream = double(publisher: Publisher.new(alice, prefill: "hello world"))
|
@stream = double(publisher: Publisher.new(alice, prefill: "hello world"))
|
||||||
|
|
|
||||||
|
|
@ -30,39 +30,6 @@ describe Stream::Base do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.can_comment?' do
|
|
||||||
before do
|
|
||||||
@person = FactoryGirl.create(:person)
|
|
||||||
allow(@stream).to receive(:people).and_return([bob.person, eve.person, @person])
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'allows me to comment on my local contacts post' do
|
|
||||||
post = FactoryGirl.create(:status_message, :author => bob.person)
|
|
||||||
expect(@stream.can_comment?(post)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'allows me to comment on my own post' do
|
|
||||||
post = FactoryGirl.create(:status_message, :author => alice.person)
|
|
||||||
expect(@stream.can_comment?(post)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'allows me to comment on any local public post' do
|
|
||||||
post = FactoryGirl.create(:status_message, :author => eve.person)
|
|
||||||
expect(@stream.can_comment?(post)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'allows me to comment on a remote contacts post' do
|
|
||||||
Contact.create!(:user => @stream.user, :person => @person)
|
|
||||||
post = FactoryGirl.create(:status_message, :author => @person)
|
|
||||||
expect(@stream.can_comment?(post)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns false if person is remote and not a contact' do
|
|
||||||
post = FactoryGirl.create(:status_message, :author => @person)
|
|
||||||
expect(@stream.can_comment?(post)).to be false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#people' do
|
describe '#people' do
|
||||||
it 'excludes blocked people' do
|
it 'excludes blocked people' do
|
||||||
expect(@stream).to receive(:stream_posts).and_return(double.as_null_object)
|
expect(@stream).to receive(:stream_posts).and_return(double.as_null_object)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue