mode the visible posts api more general and moved to it on the public controller

This commit is contained in:
ilya 2010-09-27 18:31:37 -07:00
parent 6e407572c4
commit 7852c346f2
4 changed files with 31 additions and 5 deletions

View file

@ -52,7 +52,7 @@ class AspectsController < ApplicationController
@fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create",
:scope=>MiniFB.scopes.join(","))
@posts = current_user.raw_visible_posts.all(:public => true, :order => 'created_at DESC').paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
@posts = current_user.visible_posts(:public => true).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
respond_with @aspect
end

View file

@ -21,7 +21,7 @@ class PeopleController < ApplicationController
@profile = @person.profile
@aspects_with_person = current_user.aspects_with_person(@person)
@aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]}
@posts = current_user.visible_posts(:from => @person).paginate :page => params[:page], :order => 'created_at DESC'
@posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC'
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
@post_count = @posts.count
respond_with @person

View file

@ -11,12 +11,13 @@ module Diaspora
end
def visible_posts( opts = {} )
opts[:order] ||= 'created_at DESC'
if opts[:by_members_of]
return raw_visible_posts if opts[:by_members_of] == :all
aspect = self.aspects.find_by_id( opts[:by_members_of].id )
aspect.posts
elsif opts[:from]
self.raw_visible_posts.find_all_by_person_id(opts[:from].id, :order => 'created_at DESC')
else
self.raw_visible_posts.all(opts)
end
end

View file

@ -12,13 +12,38 @@ describe User do
let!(:user2) { Factory(:user_with_aspect) }
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id }
let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id }
let!(:status_message3) { user2.post :status_message, :message => "va", :to => user2.aspects.first.id }
let!(:status_message4) { user2.post :status_message, :message => "da", :public => true , :to => user2.aspects.first.id }
before do
friend_users(user, first_aspect, user2, user2.aspects.first)
end
describe "#visible_posts" do
it "generates a stream for each aspect that includes only that aspect's posts" do
it "queries by person id" do
user2.visible_posts(:person_id => user2.person.id).include?(status_message1).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message2).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message3).should == true
user2.visible_posts(:person_id => user2.person.id).include?(status_message4).should == true
end
it "selects public posts" do
user2.visible_posts(:public => true).include?(status_message2).should == true
user2.visible_posts(:public => true).include?(status_message4).should == true
end
it "selects non public posts" do
user2.visible_posts(:public => false).include?(status_message1).should == true
user2.visible_posts(:public => false).include?(status_message3).should == true
end
it "selects by message contents" do
user2.visible_posts(:message => "hi").include?(status_message1).should == true
end
it "queries by aspect" do
user3 = Factory(:user_with_aspect)
status_message2 = user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id
user4 = Factory(:user_with_aspect)