diff --git a/app/models/post.rb b/app/models/post.rb index baeb3f9f0..394b6d45e 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -32,15 +32,21 @@ class Post < ActiveRecord::Base validates :guid, :uniqueness => true + #scopes scope :all_public, where(:public => true, :pending => false) scope :includes_for_a_stream, includes({:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message - def self.for_a_stream(max_time, order='created_at') - where("posts.#{order} < ?", max_time).order("posts.#{order} desc"). - includes_for_a_stream. + def self.for_a_stream(max_time, order) + by_max_time(max_time, order). + includes_for_a_stream. limit(15) end + def by_max_time(max_time, order='created_at') + where("posts.#{order} < ?", max_time).order("posts.#{order} desc") + end + ############# + def diaspora_handle read_attribute(:diaspora_handle) || self.author.diaspora_handle end @@ -147,4 +153,3 @@ class Post < ActiveRecord::Base update_all(:comments_count => self.comments.count) end end - diff --git a/spec/lib/base_stream_spec.rb b/spec/lib/base_stream_spec.rb new file mode 100644 index 000000000..1083821a3 --- /dev/null +++ b/spec/lib/base_stream_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') +describe BaseStream do + before do + @stream = BaseStream.new(stub) + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end diff --git a/spec/lib/mention_stream_spec.rb b/spec/lib/mention_stream_spec.rb new file mode 100644 index 000000000..d92b3f8c3 --- /dev/null +++ b/spec/lib/mention_stream_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe MentionStream do + before do + @stream = MentionStream.new(Factory(:user), :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end diff --git a/spec/lib/tag_stream_spec.rb b/spec/lib/tag_stream_spec.rb new file mode 100644 index 000000000..93050c839 --- /dev/null +++ b/spec/lib/tag_stream_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe TagStream do + before do + @stream = TagStream.new(Factory(:user), :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end diff --git a/spec/shared_behaviors/stream.rb b/spec/shared_behaviors/stream.rb new file mode 100644 index 000000000..01af8b497 --- /dev/null +++ b/spec/shared_behaviors/stream.rb @@ -0,0 +1,45 @@ +require 'spec_helper' + +describe 'Streams' do + shared_examples_for 'it is a stream' do + context 'required methods for display' do + it '#title' do + @stream.title.should_not be_nil + end + + it '#posts' do + @stream.posts.should_not be_nil + end + + it '#people' do + @stream.people.should_not be_nil + end + + it 'has a #contacts title' do + @stream.contacts_title.should_not be_nil + end + + it 'has a contacts link' do + @stream.contacts_link.should_not be_nil + end + + it 'responds to ajax_stream' do + @stream.ajax_stream?.should_not be_nil + end + + it 'responds to ajax_stream' do + @stream.ajax_stream?.should_not be_nil + end + + it 'should make the stream a time object' do + @stream.max_time = 123 + @stream.max_time.should be_a(Time) + end + + it 'should default order to created_at' do + @stream.order=nil + @stream.order.should == 'created_at' + end + end + end +end