Fix stream on pages other than 1, rename raw_visible_posts to visible_posts
This commit is contained in:
parent
9383388bb6
commit
efe79eb351
19 changed files with 88 additions and 69 deletions
|
|
@ -30,9 +30,9 @@ class ApisController < ApplicationController #We should start with this versione
|
||||||
|
|
||||||
def home_timeline
|
def home_timeline
|
||||||
set_defaults
|
set_defaults
|
||||||
timeline = current_user.raw_visible_posts.includes(:comments, :photos, :likes, :dislikes).paginate(
|
timeline = current_user.visible_posts(:max_time => params[:max_time],
|
||||||
:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
|
:per_page => params[:per_page],
|
||||||
|
:order => "#{params[:order]} DESC").includes(:comments, :photos, :likes, :dislikes)
|
||||||
respond_with timeline do |format|
|
respond_with timeline do |format|
|
||||||
format.json{ render :json => timeline.to_json(:format => :twitter) }
|
format.json{ render :json => timeline.to_json(:format => :twitter) }
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ class AspectsController < ApplicationController
|
||||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq unless params[:only_posts]
|
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq unless params[:only_posts]
|
||||||
|
|
||||||
@aspect_ids = @aspects.map { |a| a.id }
|
@aspect_ids = @aspects.map { |a| a.id }
|
||||||
posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids,
|
posts = current_user.visible_posts(:by_members_of => @aspect_ids,
|
||||||
:type => 'StatusMessage',
|
:type => 'StatusMessage',
|
||||||
:order => session[:sort_order] + ' DESC',
|
:order => session[:sort_order] + ' DESC',
|
||||||
:page => params[:page]
|
:max_time => params[:max_time].to_i
|
||||||
).includes(:comments, :mentions, :likes, :dislikes)
|
).includes(:comments, :mentions, :likes, :dislikes)
|
||||||
|
|
||||||
@posts = PostsFake.new(posts)
|
@posts = PostsFake.new(posts)
|
||||||
|
|
@ -160,6 +160,10 @@ class AspectsController < ApplicationController
|
||||||
@aspect.save
|
@aspect.save
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ensure_page
|
||||||
|
params[:max_time] ||= Time.now + 1
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def save_sort_order
|
def save_sort_order
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module AspectsHelper
|
module AspectsHelper
|
||||||
|
def next_page_path
|
||||||
|
aspects_path(:max_time => @posts.last.send(session[:sort_order].to_sym).to_i, :a_ids => params[:a_ids])
|
||||||
|
end
|
||||||
def link_for_aspect(aspect, opts={})
|
def link_for_aspect(aspect, opts={})
|
||||||
opts[:params] ||= {}
|
opts[:params] ||= {}
|
||||||
params ||= {}
|
params ||= {}
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
local_post = Post.where(:guid => self.guid).first
|
local_post = Post.where(:guid => self.guid).first
|
||||||
if local_post && local_post.author_id == self.author_id
|
if local_post && local_post.author_id == self.author_id
|
||||||
known_post = user.raw_visible_posts.where(:guid => self.guid).first
|
known_post = user.visible_posts.where(:guid => self.guid).first
|
||||||
if known_post
|
if known_post
|
||||||
if known_post.mutable?
|
if known_post.mutable?
|
||||||
known_post.update_attributes(self.attributes)
|
known_post.update_attributes(self.attributes)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,6 @@
|
||||||
- if posts.length > 0
|
- if posts.length > 0
|
||||||
= render 'shared/stream', :posts => posts
|
= render 'shared/stream', :posts => posts
|
||||||
#pagination
|
#pagination
|
||||||
=link_to(t('more'), aspects_path(:page => next_page, :a_ids => params[:a_ids]), :class => 'paginate')
|
=link_to(t('more'), next_page_path, :class => 'paginate')
|
||||||
- else
|
- else
|
||||||
= render 'aspects/no_posts_message', :post_count => posts.length
|
= render 'aspects/no_posts_message', :post_count => posts.length
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,9 @@
|
||||||
= link_to t('.post_a_message'), '#publisher_page', :id => 'publisher_button'
|
= link_to t('.post_a_message'), '#publisher_page', :id => 'publisher_button'
|
||||||
#main_stream.stream
|
#main_stream.stream
|
||||||
= render 'shared/stream', :posts => @posts
|
= render 'shared/stream', :posts => @posts
|
||||||
|
-if @posts.length > 0
|
||||||
#pagination
|
#pagination
|
||||||
%a.more-link.paginate{:href => aspects_path(:a_ids => params[:a_ids], :page => params[:page] + 1)}
|
%a.more-link.paginate{:href => next_page_path}
|
||||||
%h2= t("more")
|
%h2= t("more")
|
||||||
- content_for :subpages do
|
- content_for :subpages do
|
||||||
= render 'shared/publisher', :aspect_ids => @aspect_ids
|
= render 'shared/publisher', :aspect_ids => @aspect_ids
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
.content
|
.content
|
||||||
.from
|
.from
|
||||||
= person_link(post.author, :class => 'author')
|
= person_link(post.author, :class => 'author')
|
||||||
%time.timeago{:datetime => post.created_at}
|
%time.timeago{:datetime => post.created_at, :integer => post.created_at.to_i}
|
||||||
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
= render 'status_messages/status_message', :post => post, :photos => post.photos
|
||||||
|
|
||||||
.info
|
.info
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module PhotoMover
|
||||||
FileUtils::mkdir_p temp_dir
|
FileUtils::mkdir_p temp_dir
|
||||||
Dir.chdir 'tmp/exports'
|
Dir.chdir 'tmp/exports'
|
||||||
|
|
||||||
photos = user.raw_visible_posts.where(:author_id => user.person.id, :type => 'Photo')
|
photos = user.visible_posts.where(:author_id => user.person.id, :type => 'Photo')
|
||||||
|
|
||||||
photos_dir = "#{user.id}/photos"
|
photos_dir = "#{user.id}/photos"
|
||||||
FileUtils::mkdir_p photos_dir
|
FileUtils::mkdir_p photos_dir
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ module Diaspora
|
||||||
}
|
}
|
||||||
|
|
||||||
xml.posts {
|
xml.posts {
|
||||||
user.raw_visible_posts.find_all_by_author_id(user_person_id).each do |post|
|
user.visible_posts.find_all_by_author_id(user_person_id).each do |post|
|
||||||
#post.comments.each do |comment|
|
#post.comments.each do |comment|
|
||||||
# post_doc << comment.to_xml
|
# post_doc << comment.to_xml
|
||||||
#end
|
#end
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,16 @@ module Diaspora
|
||||||
post ||= Post.where(:id => id, :public => true).where(opts).first
|
post ||= Post.where(:id => id, :public => true).where(opts).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def raw_visible_posts(opts = {})
|
def visible_posts(opts = {})
|
||||||
opts = opts.dup
|
opts = opts.dup
|
||||||
opts[:type] ||= ['StatusMessage', 'Photo']
|
opts[:type] ||= ['StatusMessage', 'Photo']
|
||||||
opts[:limit] ||= 15
|
opts[:limit] ||= 15
|
||||||
opts[:order] ||= 'updated_at DESC'
|
opts[:order] ||= 'updated_at DESC'
|
||||||
|
order_field = opts[:order].split.first.to_sym
|
||||||
opts[:hidden] ||= false
|
opts[:hidden] ||= false
|
||||||
order_with_table = 'posts.' + opts[:order]
|
order_with_table = 'posts.' + opts[:order]
|
||||||
opts[:page] ||= 1
|
opts[:max_time] = Time.at(opts[:max_time]) if opts[:max_time].instance_of?(Fixnum)
|
||||||
opts[:offset] = opts[:page] == 1 ? 0 : opts[:limit] * (opts[:page] - 1)
|
opts[:max_time] ||= Time.now + 1
|
||||||
select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
|
select_clause ='DISTINCT posts.id, posts.updated_at AS updated_at, posts.created_at AS created_at'
|
||||||
|
|
||||||
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
|
posts_from_others = Post.joins(:contacts).where( :post_visibilities => {:hidden => opts[:hidden]}, :contacts => {:user_id => self.id})
|
||||||
|
|
@ -32,17 +33,17 @@ module Diaspora
|
||||||
posts_from_self = posts_from_self.joins(:aspect_visibilities).where(:aspect_visibilities => {:aspect_id => opts[:by_members_of]})
|
posts_from_self = posts_from_self.joins(:aspect_visibilities).where(:aspect_visibilities => {:aspect_id => opts[:by_members_of]})
|
||||||
end
|
end
|
||||||
|
|
||||||
posts_from_others = posts_from_others.select(select_clause).limit(opts[:limit]*opts[:page]).order(order_with_table)
|
posts_from_others = posts_from_others.select(select_clause).limit(opts[:limit]).order(order_with_table).where(Post.arel_table[order_field].lt(opts[:max_time]))
|
||||||
posts_from_self = posts_from_self.select(select_clause).limit(opts[:limit]*opts[:page]).order(order_with_table)
|
posts_from_self = posts_from_self.select(select_clause).limit(opts[:limit]).order(order_with_table).where(Post.arel_table[order_field].lt(opts[:max_time]))
|
||||||
|
|
||||||
all_posts = "(#{posts_from_others.to_sql}) UNION ALL (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]} OFFSET #{opts[:offset]}"
|
all_posts = "(#{posts_from_others.to_sql}) UNION ALL (#{posts_from_self.to_sql}) ORDER BY #{opts[:order]} LIMIT #{opts[:limit]}"
|
||||||
post_ids = Post.connection.execute(all_posts).map{|r| r.first}
|
post_ids = Post.connection.execute(all_posts).map{|r| r.first}
|
||||||
|
|
||||||
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT posts.*').limit(opts[:limit]).order(order_with_table)
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_photos
|
def visible_photos(opts = {})
|
||||||
raw_visible_posts(:type => 'Photo')
|
visible_posts(opts.merge(:type => 'Photo'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def contact_for(person)
|
def contact_for(person)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class PostsFake
|
class PostsFake
|
||||||
attr_reader :people_hash, :post_fakes
|
attr_reader :people_hash, :post_fakes
|
||||||
delegate :length, :each, :to_ary, :to => :post_fakes
|
delegate :length, :each, :to_ary, :last, :to => :post_fakes
|
||||||
|
|
||||||
def initialize(posts)
|
def initialize(posts)
|
||||||
author_ids = []
|
author_ids = []
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,11 @@ var InfiniteScroll = {
|
||||||
itemSelector : ".stream_element",
|
itemSelector : ".stream_element",
|
||||||
// selector for all items you'll retrieve
|
// selector for all items you'll retrieve
|
||||||
pathParse : function( pathStr, nextPage ){
|
pathParse : function( pathStr, nextPage ){
|
||||||
|
console.log(pathStr);
|
||||||
|
console.log(nextPage);
|
||||||
var newPath = pathStr.replace("?", "?only_posts=true&");
|
var newPath = pathStr.replace("?", "?only_posts=true&");
|
||||||
return newPath.replace( "page=2", "page=" + nextPage);
|
var last_time = $('#main_stream .stream_element').last().find('time.timeago').attr('integer');
|
||||||
|
return newPath.replace( /max_time=\d+/, 'max_time=' + last_time);
|
||||||
},
|
},
|
||||||
bufferPx: 500,
|
bufferPx: 500,
|
||||||
debug: false,
|
debug: false,
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ Diaspora.widgets.add("directionDetector", function() {
|
||||||
|
|
||||||
this.start = function() {
|
this.start = function() {
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
InfiniteScroll.postScrollCallback = function() {
|
InfiniteScroll.postScroll(function() {
|
||||||
Diaspora.widgets.directionDetector.updateBinds();
|
Diaspora.widgets.directionDetector.updateBinds();
|
||||||
}
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
this.isRTL = function(str) {
|
this.isRTL = function(str) {
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ describe 'a user receives a post' do
|
||||||
bob.dispatch_post(sm, :to => bob.aspects.first)
|
bob.dispatch_post(sm, :to => bob.aspects.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
alice.raw_visible_posts.count.should == 1
|
alice.visible_posts.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'mentions' do
|
context 'mentions' do
|
||||||
|
|
@ -158,14 +158,14 @@ describe 'a user receives a post' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "adds a received post to the the contact" do
|
it "adds a received post to the the contact" do
|
||||||
@user1.raw_visible_posts.include?(@status_message).should be_true
|
@user1.visible_posts.include?(@status_message).should be_true
|
||||||
@contact.posts.include?(@status_message).should be_true
|
@contact.posts.include?(@status_message).should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'removes posts upon disconnecting' do
|
it 'removes posts upon disconnecting' do
|
||||||
@user1.disconnect(@contact)
|
@user1.disconnect(@contact)
|
||||||
@user1.reload
|
@user1.reload
|
||||||
@user1.raw_visible_posts.should_not include @status_message
|
@user1.visible_posts.should_not include @status_message
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'dependant delete' do
|
context 'dependant delete' do
|
||||||
|
|
@ -243,7 +243,7 @@ describe 'a user receives a post' do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should correctly attach the user already on the pod' do
|
it 'should correctly attach the user already on the pod' do
|
||||||
@user2.reload.raw_visible_posts.size.should == 1
|
@user2.reload.visible_posts.size.should == 1
|
||||||
post_in_db = StatusMessage.find(@post.id)
|
post_in_db = StatusMessage.find(@post.id)
|
||||||
post_in_db.comments.should == []
|
post_in_db.comments.should == []
|
||||||
receive_with_zord(@user2, @user1.person, @xml)
|
receive_with_zord(@user2, @user1.person, @xml)
|
||||||
|
|
@ -270,7 +270,7 @@ describe 'a user receives a post' do
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@user2.reload.raw_visible_posts.size.should == 1
|
@user2.reload.visible_posts.size.should == 1
|
||||||
post_in_db = StatusMessage.find(@post.id)
|
post_in_db = StatusMessage.find(@post.id)
|
||||||
post_in_db.comments.should == []
|
post_in_db.comments.should == []
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ describe 'a user receives a post' do
|
||||||
zord = Postzord::Receiver.new(@user2, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(@user2, :salmon_xml => salmon_xml)
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
@user2.raw_visible_posts.include?(post).should be_true
|
@user2.visible_posts.include?(post).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ describe 'making sure the spec runner works' do
|
||||||
|
|
||||||
it 'allows posting after running' do
|
it 'allows posting after running' do
|
||||||
message = @user1.post(:status_message, :text => "Connection!", :to => @aspect1.id)
|
message = @user1.post(:status_message, :text => "Connection!", :to => @aspect1.id)
|
||||||
@user2.reload.raw_visible_posts.should include message
|
@user2.reload.visible_posts.should include message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ describe "attack vectors" do
|
||||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
user.raw_visible_posts.include?(post_from_non_contact).should be_false
|
user.visible_posts.include?(post_from_non_contact).should be_false
|
||||||
Post.count.should == post_count
|
Post.count.should == post_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -49,7 +49,7 @@ describe "attack vectors" do
|
||||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
user3.reload.raw_visible_posts.should_not include(StatusMessage.find(original_message.id))
|
user3.reload.visible_posts.should_not include(StatusMessage.find(original_message.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'malicious contact attack vector' do
|
context 'malicious contact attack vector' do
|
||||||
|
|
@ -89,10 +89,10 @@ describe "attack vectors" do
|
||||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
}.should_not change{user.reload.raw_visible_posts.count}
|
}.should_not change{user.reload.visible_posts.count}
|
||||||
|
|
||||||
original_message.reload.text.should == "store this!"
|
original_message.reload.text.should == "store this!"
|
||||||
user.raw_visible_posts.first.text.should == "store this!"
|
user.visible_posts.first.text.should == "store this!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'should not overwrite another persons profile profile' do
|
it 'should not overwrite another persons profile profile' do
|
||||||
|
|
@ -119,7 +119,7 @@ describe "attack vectors" do
|
||||||
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
zord = Postzord::Receiver.new(user, :salmon_xml => salmon_xml)
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
user.raw_visible_posts.count.should == 1
|
user.visible_posts.count.should == 1
|
||||||
StatusMessage.count.should == 1
|
StatusMessage.count.should == 1
|
||||||
|
|
||||||
ret = Retraction.new
|
ret = Retraction.new
|
||||||
|
|
@ -132,7 +132,7 @@ describe "attack vectors" do
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
StatusMessage.count.should == 1
|
StatusMessage.count.should == 1
|
||||||
user.raw_visible_posts.count.should == 1
|
user.visible_posts.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it "disregards retractions for non-existent posts that are from someone other than the post's author" do
|
it "disregards retractions for non-existent posts that are from someone other than the post's author" do
|
||||||
|
|
@ -163,7 +163,7 @@ describe "attack vectors" do
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
|
|
||||||
user.raw_visible_posts.count.should == 1
|
user.visible_posts.count.should == 1
|
||||||
|
|
||||||
ret = Retraction.new
|
ret = Retraction.new
|
||||||
ret.post_guid = original_message.guid
|
ret.post_guid = original_message.guid
|
||||||
|
|
@ -177,7 +177,7 @@ describe "attack vectors" do
|
||||||
zord.perform
|
zord.perform
|
||||||
|
|
||||||
}.should_not change(StatusMessage, :count)
|
}.should_not change(StatusMessage, :count)
|
||||||
user.reload.raw_visible_posts.count.should == 1
|
user.reload.visible_posts.count.should == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'it should not allow you to send retractions for other people' do
|
it 'it should not allow you to send retractions for other people' do
|
||||||
|
|
|
||||||
|
|
@ -275,9 +275,9 @@ describe Diaspora::UserModules::Connecting do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "deletes the disconnected user's posts from visible_posts" do
|
it "deletes the disconnected user's posts from visible_posts" do
|
||||||
bob.reload.raw_visible_posts.include?(@message).should be_true
|
bob.reload.visible_posts.include?(@message).should be_true
|
||||||
bob.disconnect bob.contact_for(alice.person)
|
bob.disconnect bob.contact_for(alice.person)
|
||||||
bob.reload.raw_visible_posts.include?(@message).should be_false
|
bob.reload.visible_posts.include?(@message).should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ describe User do
|
||||||
it 'saves post into visible post ids' do
|
it 'saves post into visible post ids' do
|
||||||
proc {
|
proc {
|
||||||
user.add_to_streams(@post, @aspects)
|
user.add_to_streams(@post, @aspects)
|
||||||
}.should change{user.raw_visible_posts(:by_members_of => @aspects).length}.by(1)
|
}.should change{user.visible_posts(:by_members_of => @aspects).length}.by(1)
|
||||||
user.raw_visible_posts(:by_members_of => @aspects).should include @post
|
user.visible_posts(:by_members_of => @aspects).should include @post
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'saves post into each aspect in aspect_ids' do
|
it 'saves post into each aspect in aspect_ids' do
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ describe User do
|
||||||
@eves_aspect = eve.aspects.first
|
@eves_aspect = eve.aspects.first
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#raw_visible_posts" do
|
describe "#visible_posts" do
|
||||||
it "returns all the posts the user can see" do
|
it "returns all the posts the user can see" do
|
||||||
connect_users(eve, @eves_aspect, alice, @alices_aspect)
|
connect_users(eve, @eves_aspect, alice, @alices_aspect)
|
||||||
self_post = alice.post(:status_message, :text => "hi", :to => @alices_aspect.id)
|
self_post = alice.post(:status_message, :text => "hi", :to => @alices_aspect.id)
|
||||||
|
|
@ -19,7 +19,7 @@ describe User do
|
||||||
dogs = eve.aspects.create(:name => "dogs")
|
dogs = eve.aspects.create(:name => "dogs")
|
||||||
invisible_post = eve.post(:status_message, :text => "foobar", :to => dogs.id)
|
invisible_post = eve.post(:status_message, :text => "foobar", :to => dogs.id)
|
||||||
|
|
||||||
stream = alice.raw_visible_posts
|
stream = alice.visible_posts
|
||||||
stream.should include(self_post)
|
stream.should include(self_post)
|
||||||
stream.should include(visible_post)
|
stream.should include(visible_post)
|
||||||
stream.should_not include(invisible_post)
|
stream.should_not include(invisible_post)
|
||||||
|
|
@ -31,28 +31,35 @@ describe User do
|
||||||
(1..25).each do |n|
|
(1..25).each do |n|
|
||||||
[alice, bob, eve].each do |u|
|
[alice, bob, eve].each do |u|
|
||||||
post = u.post :status_message, :text => "#{u.username} - #{n}", :to => u.aspects.first.id
|
post = u.post :status_message, :text => "#{u.username} - #{n}", :to => u.aspects.first.id
|
||||||
post.created_at = post.created_at + time_interval
|
post.created_at = post.created_at - time_interval
|
||||||
post.updated_at = post.updated_at + time_interval
|
post.updated_at = post.updated_at - time_interval
|
||||||
post.save
|
post.save
|
||||||
time_interval += 1000
|
time_interval += 1000
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
it 'works' do #This is in one spec to save time
|
it 'works' do #This is in one spec to save time
|
||||||
bob.raw_visible_posts.length.should == 15 #it returns 15 by default
|
bob.visible_posts.length.should == 15 #it returns 15 by default
|
||||||
bob.raw_visible_posts.should == bob.raw_visible_posts(:by_members_of => bob.aspects.map{|a| a.id}) # it is the same when joining through aspects
|
bob.visible_posts.should == bob.visible_posts(:by_members_of => bob.aspects.map{|a| a.id}) # it is the same when joining through aspects
|
||||||
bob.raw_visible_posts.sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts.map{|p| p.id}.reverse #it is sorted updated_at desc by default
|
bob.visible_posts.sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.visible_posts.map{|p| p.id}.reverse #it is sorted updated_at desc by default
|
||||||
|
|
||||||
opts = {:limit => 40}
|
opts = {:limit => 40}
|
||||||
bob.raw_visible_posts(opts).length.should == 40 #it takes a limit
|
bob.visible_posts(opts).length.should == 40 #it takes a limit
|
||||||
bob.raw_visible_posts(opts).should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id}))
|
bob.visible_posts(opts).should == bob.visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id}))
|
||||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
bob.visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.visible_posts(opts).map{|p| p.id}.reverse
|
||||||
|
|
||||||
opts = {:page => 2}
|
last_time_of_last_page = bob.visible_posts.last.updated_at
|
||||||
bob.raw_visible_posts(opts).length.should == 15
|
opts = {:max_time => last_time_of_last_page}
|
||||||
bob.raw_visible_posts(opts).map{|p| p.id}.should == bob.raw_visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id})).map{|p| p.id}
|
bob.visible_posts(opts).length.should == 15
|
||||||
bob.raw_visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.raw_visible_posts(opts).map{|p| p.id}.reverse
|
bob.visible_posts(opts).map{|p| p.id}.should == bob.visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id})).map{|p| p.id}
|
||||||
bob.raw_visible_posts(opts).map{|p|p.id}.should == bob.raw_visible_posts(:limit => 40)[15...30].map{|p|p.id} #pagination should return the right posts
|
bob.visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.visible_posts(opts).map{|p| p.id}.reverse
|
||||||
|
bob.visible_posts(opts).map{|p|p.id}.should == bob.visible_posts(:limit => 40)[15...30].map{|p|p.id} #pagination should return the right posts
|
||||||
|
|
||||||
|
opts = {:max_time => last_time_of_last_page.to_i}
|
||||||
|
bob.visible_posts(opts).length.should == 15
|
||||||
|
bob.visible_posts(opts).map{|p| p.id}.should == bob.visible_posts(opts.merge(:by_members_of => bob.aspects.map{|a| a.id})).map{|p| p.id}
|
||||||
|
bob.visible_posts(opts).sort_by{|p| p.updated_at}.map{|p| p.id}.should == bob.visible_posts(opts).map{|p| p.id}.reverse
|
||||||
|
bob.visible_posts(opts).map{|p|p.id}.should == bob.visible_posts(:limit => 40)[15...30].map{|p|p.id} #pagination should return the right posts
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -72,7 +79,7 @@ describe User do
|
||||||
|
|
||||||
describe "#visible_posts" do
|
describe "#visible_posts" do
|
||||||
it "queries by person id" do
|
it "queries by person id" do
|
||||||
query = eve.raw_visible_posts.where(:author_id => eve.person.id)
|
query = eve.visible_posts.where(:author_id => eve.person.id)
|
||||||
query.include?(@status_message1).should == true
|
query.include?(@status_message1).should == true
|
||||||
query.include?(@status_message2).should == true
|
query.include?(@status_message2).should == true
|
||||||
query.include?(@status_message3).should == false
|
query.include?(@status_message3).should == false
|
||||||
|
|
@ -81,7 +88,7 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects public posts" do
|
it "selects public posts" do
|
||||||
query = eve.raw_visible_posts.where(:public => true)
|
query = eve.visible_posts.where(:public => true)
|
||||||
query.include?(@status_message1).should == false
|
query.include?(@status_message1).should == false
|
||||||
query.include?(@status_message2).should == true
|
query.include?(@status_message2).should == true
|
||||||
query.include?(@status_message3).should == true
|
query.include?(@status_message3).should == true
|
||||||
|
|
@ -90,7 +97,7 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects non public posts" do
|
it "selects non public posts" do
|
||||||
query = eve.raw_visible_posts.where(:public => false)
|
query = eve.visible_posts.where(:public => false)
|
||||||
query.include?(@status_message1).should == true
|
query.include?(@status_message1).should == true
|
||||||
query.include?(@status_message2).should == false
|
query.include?(@status_message2).should == false
|
||||||
query.include?(@status_message3).should == false
|
query.include?(@status_message3).should == false
|
||||||
|
|
@ -99,13 +106,13 @@ describe User do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "selects by message contents" do
|
it "selects by message contents" do
|
||||||
query = eve.raw_visible_posts.where(:text=> "hi")
|
query = eve.visible_posts.where(:text=> "hi")
|
||||||
query.should == [@status_message1]
|
query.should == [@status_message1]
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not return pending posts" do
|
it "does not return pending posts" do
|
||||||
@pending_status_message.pending.should be_true
|
@pending_status_message.pending.should be_true
|
||||||
eve.raw_visible_posts.should_not include @pending_status_message
|
eve.visible_posts.should_not include @pending_status_message
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#find_visible_post_by_id' do
|
it '#find_visible_post_by_id' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue