displaying public tags in the multi stream
This commit is contained in:
parent
016032cf95
commit
41db42a7a4
4 changed files with 47 additions and 5 deletions
|
|
@ -35,9 +35,14 @@ class StatusMessage < Post
|
|||
#scopes
|
||||
scope :where_person_is_mentioned, lambda{|person| joins(:mentions).where(:mentions => {:person_id => person.id})}
|
||||
|
||||
def self.tag_stream(user, tag_ids, max_time, order)
|
||||
def self.user_tag_stream(user, tag_ids)
|
||||
owned_or_visible_by_user(user).
|
||||
joins(:tags).where(:tags => {:id => tag_ids})
|
||||
tag_stream(tag_ids)
|
||||
end
|
||||
|
||||
def self.public_tag_stream(tag_ids)
|
||||
all_public.
|
||||
tag_stream(tag_ids)
|
||||
end
|
||||
|
||||
def text(opts = {})
|
||||
|
|
@ -165,11 +170,16 @@ class StatusMessage < Post
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
def presence_of_content
|
||||
if text_and_photos_blank?
|
||||
errors[:base] << 'Status message requires a message or at least one photo'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def self.tag_stream(tag_ids)
|
||||
joins(:tags).where(:tags => {:id => tag_ids})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class Stream::FollowedTag < Stream::Base
|
|||
# @return [ActiveRecord::Association<Post>] AR association of posts
|
||||
def posts
|
||||
return [] if tag_string.empty?
|
||||
@posts ||= StatusMessage.tag_stream(user, tag_ids, max_time, order)
|
||||
@posts ||= StatusMessage.user_tag_stream(user, tag_ids)
|
||||
end
|
||||
|
||||
def contacts_title
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class Stream::Multi < Stream::Base
|
|||
end
|
||||
|
||||
def followed_tags_post_ids
|
||||
@followed_tags_ids ||= ids(StatusMessage.tag_stream(user, tag_ids, max_time, order).for_a_stream(max_time, order))
|
||||
@followed_tags_ids ||= ids(StatusMessage.public_tag_stream(tag_ids).for_a_stream(max_time, order))
|
||||
end
|
||||
|
||||
def mentioned_post_ids
|
||||
|
|
|
|||
|
|
@ -30,6 +30,38 @@ describe StatusMessage do
|
|||
StatusMessage.where_person_is_mentioned(@bo).count.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
context "tag_streams" do
|
||||
before do
|
||||
@sm1 = Factory.create(:status_message, :text => "#hashtag" , :public => true)
|
||||
@sm2 = Factory.create(:status_message, :text => "#hashtag" )
|
||||
@sm3 = Factory.create(:status_message, :text => "hashtags are #awesome", :public => true )
|
||||
@sm4 = Factory.create(:status_message, :text => "hashtags are #awesome" )
|
||||
|
||||
@tag_id = ActsAsTaggableOn::Tag.where(:name => "hashtag").first.id
|
||||
end
|
||||
|
||||
describe '.tag_steam' do
|
||||
it 'returns status messages tagged with the tag' do
|
||||
StatusMessage.send(:tag_stream, [@tag_id]).should == [@sm1, @sm2]
|
||||
end
|
||||
end
|
||||
|
||||
describe '.public_tag_stream' do
|
||||
it 'returns public status messages tagged with the tag' do
|
||||
StatusMessage.public_tag_stream([@tag_id]).should == [@sm1]
|
||||
end
|
||||
end
|
||||
|
||||
describe '.user_tag_stream' do
|
||||
it 'returns tag stream thats owned or visibile by' do
|
||||
StatusMessage.should_receive(:owned_or_visible_by_user).with(bob).and_return(StatusMessage)
|
||||
StatusMessage.should_receive(:tag_stream).with([@tag_id])
|
||||
|
||||
StatusMessage.user_tag_stream(bob, [@tag_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.before_create' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue