mode the visible posts api more general and moved to it on the public controller
This commit is contained in:
parent
6e407572c4
commit
7852c346f2
4 changed files with 31 additions and 5 deletions
|
|
@ -52,7 +52,7 @@ class AspectsController < ApplicationController
|
||||||
@fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create",
|
@fb_access_url = MiniFB.oauth_url(FB_APP_ID, APP_CONFIG[:pod_url] + "services/create",
|
||||||
:scope=>MiniFB.scopes.join(","))
|
: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
|
respond_with @aspect
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class PeopleController < ApplicationController
|
||||||
@profile = @person.profile
|
@profile = @person.profile
|
||||||
@aspects_with_person = current_user.aspects_with_person(@person)
|
@aspects_with_person = current_user.aspects_with_person(@person)
|
||||||
@aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]}
|
@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
|
@latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last
|
||||||
@post_count = @posts.count
|
@post_count = @posts.count
|
||||||
respond_with @person
|
respond_with @person
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,13 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def visible_posts( opts = {} )
|
def visible_posts( opts = {} )
|
||||||
|
opts[:order] ||= 'created_at DESC'
|
||||||
if opts[:by_members_of]
|
if opts[:by_members_of]
|
||||||
return raw_visible_posts if opts[:by_members_of] == :all
|
return raw_visible_posts if opts[:by_members_of] == :all
|
||||||
aspect = self.aspects.find_by_id( opts[:by_members_of].id )
|
aspect = self.aspects.find_by_id( opts[:by_members_of].id )
|
||||||
aspect.posts
|
aspect.posts
|
||||||
elsif opts[:from]
|
else
|
||||||
self.raw_visible_posts.find_all_by_person_id(opts[:from].id, :order => 'created_at DESC')
|
self.raw_visible_posts.all(opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,38 @@ describe User do
|
||||||
let!(:user2) { Factory(:user_with_aspect) }
|
let!(:user2) { Factory(:user_with_aspect) }
|
||||||
|
|
||||||
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id }
|
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
|
before do
|
||||||
friend_users(user, first_aspect, user2, user2.aspects.first)
|
friend_users(user, first_aspect, user2, user2.aspects.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#visible_posts" do
|
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)
|
user3 = Factory(:user_with_aspect)
|
||||||
status_message2 = user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id
|
status_message2 = user3.post :status_message, :message => "heyyyy", :to => user3.aspects.first.id
|
||||||
user4 = Factory(:user_with_aspect)
|
user4 = Factory(:user_with_aspect)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue