added shared behaviors for real
This commit is contained in:
parent
6734aab378
commit
52bb5900a3
5 changed files with 89 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
11
spec/lib/base_stream_spec.rb
Normal file
11
spec/lib/base_stream_spec.rb
Normal file
|
|
@ -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
|
||||
12
spec/lib/mention_stream_spec.rb
Normal file
12
spec/lib/mention_stream_spec.rb
Normal file
|
|
@ -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
|
||||
12
spec/lib/tag_stream_spec.rb
Normal file
12
spec/lib/tag_stream_spec.rb
Normal file
|
|
@ -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
|
||||
45
spec/shared_behaviors/stream.rb
Normal file
45
spec/shared_behaviors/stream.rb
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue