diff --git a/app/models/status_message.rb b/app/models/status_message.rb index c9aa22515..7b4004911 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -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 diff --git a/lib/stream/followed_tag.rb b/lib/stream/followed_tag.rb index b2c473152..ef71ba424 100644 --- a/lib/stream/followed_tag.rb +++ b/lib/stream/followed_tag.rb @@ -15,7 +15,7 @@ class Stream::FollowedTag < Stream::Base # @return [ActiveRecord::Association] 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 diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index b02570c8c..5087cc3b2 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -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 diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 92c591f32..698257816 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -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