Merge branch 'comment_on_tagged_psts'

This commit is contained in:
Maxwell Salzberg 2011-10-04 18:21:10 -07:00
commit 6f00b047b1
18 changed files with 96 additions and 38 deletions

View file

@ -9,7 +9,6 @@ class TagFollowingsController < ApplicationController
before_filter :save_sort_order, :only => :index
def index
@commenting_disabled = true
@stream = TagStream.new(current_user, :max_time => params[:max_time], :order => sort_order)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @stream.posts}

View file

@ -31,10 +31,12 @@ module CommentsHelper
end
end
def commenting_disabled?
def commenting_disabled?(post)
return true unless user_signed_in?
if defined?(@commenting_disabled)
return @commenting_disabled
@commenting_disabled
elsif defined?(@stream)
!@stream.can_comment?(post)
else
false
end

View file

@ -22,7 +22,7 @@
.likes_container
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment"
- unless commenting_disabled?
- unless commenting_disabled?(post)
%span.like_action
= like_action(comment, current_user)

View file

@ -13,6 +13,6 @@
-else
= render :partial => 'comments/comment', :collection => post.comments, :locals => {:post => post}
- unless commenting_disabled?
- unless commenting_disabled?(post)
.new_comment_form_wrapper{:class => comment_form_wrapper_class(post)}
= new_comment_form(post.id, current_user)

View file

@ -1,3 +1,3 @@
ContentUpdater.addCommentToPost("<%= @comment.post.guid %>",
"<%= @comment.guid%>",
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person}))%>");
"<%= escape_javascript(render(:partial => 'comments/comment', :locals => { :comment => @comment, :person => current_user.person, :post => @comment.post}))%>");

View file

@ -31,7 +31,7 @@
= render 'photos/index', :photos => @posts
- else
#main_stream.stream
= render 'shared/stream', :posts => @posts, :commenting_disabled => commenting_disabled?
= render 'shared/stream', :posts => @posts
#pagination
=link_to(t('more'), next_page_path, :class => 'paginate')

View file

@ -8,7 +8,7 @@
- if @post.is_a?(Photo)
= render 'posts/photo', :post => @post
- else
= render 'shared/stream_element', :post => @post, :commenting_disabled => commenting_disabled?
= render 'shared/stream_element', :post => @post, :commenting_disabled => commenting_disabled?(@post)
%br
%br
%br

View file

@ -4,4 +4,4 @@
.stream
= render :partial => 'shared/stream_element',
:locals => {:post => @post, :commenting_disabled => commenting_disabled?, :expanded_info => true}
:locals => {:post => @post, :commenting_disabled => commenting_disabled?(@post), :expanded_info => true}

View file

@ -4,6 +4,4 @@
= render :partial => 'shared/stream_element',
:collection => posts,
:as => :post,
:locals => { :commenting_disabled => commenting_disabled?}
:as => :post

View file

@ -68,7 +68,7 @@
&ndash;
- unless commenting_disabled?
- unless commenting_disabled?(post)
%span.like_action
= like_action(post, current_user)
@ -84,4 +84,4 @@
.likes_container
= render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post"
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => commenting_disabled?
= render "comments/comments", :post => post, :current_user => current_user, :commenting_disabled => commenting_disabled?(post)

BIN
diaspora_development Normal file

Binary file not shown.

BIN
diaspora_test Normal file

Binary file not shown.

View file

@ -14,6 +14,10 @@ class BaseStream
Rails.application.routes.url_helpers.mentions_path(opts)
end
def can_comment?(post)
true
end
def title
'a title'
end

View file

@ -14,16 +14,12 @@ class TagStream < BaseStream
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
if tag_string.empty?
[]
else
return [] if tag_string.empty?
@posts ||= StatusMessage.owned_or_visible_by_user(user).
joins(:tags).where(:tags => {:name => tag_array}).
for_a_stream(@max_time, @order)
end
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
@ -32,6 +28,17 @@ class TagStream < BaseStream
I18n.translate('streams.tags.contacts_title')
end
def can_comment?(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
def contacts_in_stream
@contacts_in_stream ||= Contact.where(:user_id => user.id, :person_id => people.map{|x| x.id}).all
end
private
def tag_string

View file

@ -26,6 +26,7 @@ $(document).ready(function(){
});
}
jQuery("abbr.timeago").timeago();
return false;
});

View file

@ -1,6 +1,7 @@
require 'spec_helper'
describe CommentsHelper do
describe '.new_comment_form' do
before do
@user = alice
@aspect = @user.aspects.first
@ -18,4 +19,24 @@ describe CommentsHelper do
}
(time*1000).should < 1
end
end
describe 'commenting_disabled?' do
it 'returns true if @commenting_disabled is set' do
@commenting_disabled = true
commenting_disabled?(stub).should_be true
@commenting_disabled = false
commenting_disabled?(stub).should_be false
end
it 'returns @stream.can_comment? if @stream is set' do
post = stub
@stream = stub
@stream.should_receive(:can_comment?).with(post).and_return(true)
commenting_disabled?(post).should_be true
@stream.should_receive(:can_comment?).with(post).and_return(false)
commenting_disabled?(post).should_be false
end
end
end

View file

@ -10,4 +10,26 @@ describe TagStream do
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
end
describe '.can_comment?' do
before do
@stream = TagStream.new(alice)
@stream.stub(:people).and_return([bob.person])
end
it 'returns true if user is a contact of the post author' do
post = Factory(:status_message, :author => bob.person)
@stream.can_comment?(post).should be_true
end
it 'returns true if a user is the author of the post' do
post = Factory(:status_message, :author => alice.person)
@stream.can_comment?(post).should be_true
end
it 'returns false otherwise' do
post = Factory(:status_message, :author => eve.person)
@stream.can_comment?(post).should be_false
end
end
end

View file

@ -40,6 +40,10 @@ describe 'Streams' do
@stream.order=nil
@stream.order.should == 'created_at'
end
it 'should have can_comment?(post)' do
@stream.can_comment?(Factory(:status_message)).should_not be_nil
end
end
end
end