Take out PostsFake, now that we ajax in comments it's not worth the extra complications

This commit is contained in:
Raphael Sofaer 2011-08-03 10:52:41 -07:00
parent 9cbb6c4d5e
commit 5967f01dab
10 changed files with 32 additions and 149 deletions

View file

@ -42,13 +42,12 @@ class AspectsController < ApplicationController
end
@aspect_ids = @aspects.map { |a| a.id }
posts = current_user.visible_posts(:by_members_of => @aspect_ids,
@posts = current_user.visible_posts(:by_members_of => @aspect_ids,
:type => ['StatusMessage','Reshare', 'ActivityStreams::Photo'],
:order => session[:sort_order] + ' DESC',
:max_time => params[:max_time].to_i
).includes(:mentions => {:person => :profile})
).includes(:mentions => {:person => :profile}, :author => :profile)
@posts = PostsFake.new(posts)
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts}
else

View file

@ -101,7 +101,7 @@ class PeopleController < ApplicationController
@commenting_disabled = true
@posts = @person.posts.where(:type => ["StatusMessage", "Reshare", "ActivityStreams::Photo"], :public => true).includes(:comments).limit(15).where(StatusMessage.arel_table[:created_at].lt(max_time)).order('posts.created_at DESC')
end
@posts = PostsFake.new(@posts)
@posts.includes(:author => :profile)
end
if params[:only_posts]

View file

@ -60,9 +60,8 @@ class TagsController < ApplicationController
max_time = params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
@posts = @posts.where(StatusMessage.arel_table[:created_at].lt(max_time))
@posts = @posts.includes(:comments, :photos).order('posts.created_at DESC').limit(15)
@posts = @posts.includes({:author => :profile}, :comments, :photos).order('posts.created_at DESC').limit(15)
@posts = PostsFake.new(@posts)
@commenting_disabled = true
if params[:only_posts]

View file

@ -9,9 +9,6 @@ module LikesHelper
end
def like_action(target, current_user=current_user)
target = target.model if target.instance_of?(PostsFake::Fake)
if target.instance_of?(Comment)
if current_user.liked?(target)
link_to t('shared.stream_element.unlike'), comment_like_path(target, current_user.like_for(target)), :method => :delete, :class => 'unlike', :remote => true

View file

@ -20,8 +20,6 @@ Bundler.require(:default, Rails.env) if defined?(Bundler)
# use newrelic if configured via config/newrelic.yml
require 'newrelic_rpm' if File.exists?(File.expand_path('../newrelic.yml', __FILE__))
require File.expand_path('../../lib/fake', __FILE__)
module Diaspora
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.

View file

@ -1,52 +0,0 @@
class PostsFake
attr_reader :people_hash, :post_fakes
delegate :length, :each, :to_ary, :last, :to => :post_fakes
def initialize(posts)
author_ids = []
posts.each do |p|
author_ids << p.author_id
end
people = Person.where(:id => author_ids).includes(:profile)
@people_hash = {}
people.each{|person| @people_hash[person.id] = person}
@post_fakes = posts.map do |post|
f = Fake.new(post, self)
f
end
end
def models
self.post_fakes.map{|a| a.model }
end
class Fake
attr_reader :model
def initialize(model, fakes_collection)
@fakes_collection = fakes_collection
@model = model
end
def id
@model.id
end
def to_s
@model.id.to_s
end
def author
@fakes_collection.people_hash[@model.author_id]
end
def respond_to?(*args)
super(*args) || model.respond_to?(*args)
end
def method_missing(method, *args)
@model.send(method, *args)
end
end
end

View file

@ -127,19 +127,19 @@ describe AspectsController do
it "pulls back non hidden posts" do
get :index
assigns[:posts].models.include?(@status).should be_true
assigns[:posts].include?(@status).should be_true
end
it "does not pull back hidden posts" do
@vis.update_attributes( :hidden => true )
get :index
assigns[:posts].models.include?(@status).should be_false
assigns[:posts].include?(@status).should be_false
end
end
describe 'infinite scroll' do
it 'renders with the infinite scroll param' do
get :index, :only_posts => true
assigns[:posts].models.include?(@posts.first).should be_true
assigns[:posts].include?(@posts.first).should be_true
response.should be_success
end
@ -148,51 +148,51 @@ describe AspectsController do
describe "ordering" do
it "orders posts by updated_at by default" do
get :index
assigns(:posts).models.should == @posts
assigns(:posts).should == @posts
end
it "orders posts by created_at on request" do
get :index, :sort_order => 'created_at'
assigns(:posts).models.should == @posts.reverse
assigns(:posts).should == @posts.reverse
end
it "remembers your sort order and lets you override the memory" do
get :index, :sort_order => "created_at"
assigns(:posts).models.should == @posts.reverse
assigns(:posts).should == @posts.reverse
get :index
assigns(:posts).models.should == @posts.reverse
assigns(:posts).should == @posts.reverse
get :index, :sort_order => "updated_at"
assigns(:posts).models.should == @posts
assigns(:posts).should == @posts
end
it "doesn't allow SQL injection" do
get :index, :sort_order => "\"; DROP TABLE users;"
assigns(:posts).models.should == @posts
assigns(:posts).should == @posts
get :index, :sort_order => "created_at"
assigns(:posts).models.should == @posts.reverse
assigns(:posts).should == @posts.reverse
end
end
it "returns all posts by default" do
alice.aspects.reload
get :index
assigns(:posts).models.length.should == 2
assigns(:posts).length.should == 2
end
it "posts include reshares" do
reshare = alice.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :index
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
assigns[:posts].map{|x| x.id}.should include(reshare.id)
end
it "can filter to a single aspect" do
get :index, :a_ids => [@alices_aspect_2.id.to_s]
assigns(:posts).models.length.should == 1
assigns(:posts).length.should == 1
end
it "can filter to multiple aspects" do
get :index, :a_ids => [@alices_aspect_1.id.to_s, @alices_aspect_2.id.to_s]
assigns(:posts).models.length.should == 2
assigns(:posts).length.should == 2
end
end

View file

@ -161,7 +161,7 @@ describe PeopleController do
@user.post(:status_message, :text => "public", :to => 'all', :public => true)
@user.reload.posts.length.should == 3
get :show, :id => @user.person.to_param
assigns(:posts).models.should =~ @user.posts
assigns(:posts).map(&:id).should =~ @user.posts.map(&:id)
end
it "renders the comments on the user's posts" do
@ -208,17 +208,17 @@ describe PeopleController do
it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
assigns[:posts].map{|x| x.id}.should include(reshare.id)
end
it "assigns only public posts" do
get :show, :id => @person.id
assigns[:posts].models.should =~ @public_posts
assigns[:posts].map(&:id).should =~ @public_posts.map(&:id)
end
it 'is sorted by created_at desc' do
get :show, :id => @person.id
assigns[:posts].models.should == @public_posts.sort_by{|p| p.created_at}.reverse
assigns[:posts].should == @public_posts.sort_by{|p| p.created_at}.reverse
end
end
@ -255,13 +255,13 @@ describe PeopleController do
bob.reload.posts.length.should == 4
get :show, :id => @person.id
assigns(:posts).models.should =~ posts_user_can_see
assigns(:posts).map(&:id).should =~ posts_user_can_see.map(&:id)
end
it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
assigns[:posts].map{|x| x.id}.should include(reshare.id)
end
it 'sets @commenting_disabled to true' do
@ -293,13 +293,13 @@ describe PeopleController do
eve.reload.posts.length.should == 3
get :show, :id => @person.id
assigns[:posts].models.should =~ [public_post]
assigns[:posts].map(&:id).should =~ [public_post].map(&:id)
end
it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id
assigns[:posts].post_fakes.map{|x| x.id}.should include(reshare.id)
assigns[:posts].map{|x| x.id}.should include(reshare.id)
end
it 'sets @commenting_disabled to true' do

View file

@ -45,21 +45,21 @@ describe TagsController do
it 'displays your own post' do
my_post = alice.post(:status_message, :text => "#what", :to => 'all')
get :show, :name => 'what'
assigns(:posts).models.should == [my_post]
assigns(:posts).should == [my_post]
response.status.should == 200
end
it "displays a friend's post" do
other_post = bob.post(:status_message, :text => "#hello", :to => 'all')
get :show, :name => 'hello'
assigns(:posts).models.should == [other_post]
assigns(:posts).should == [other_post]
response.status.should == 200
end
it 'displays a public post' do
other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all')
get :show, :name => 'hello'
assigns(:posts).models.should == [other_post]
assigns(:posts).should == [other_post]
response.status.should == 200
end
@ -67,7 +67,7 @@ describe TagsController do
stranger = Factory(:user_with_aspect)
stranger_post = stranger.post(:status_message, :text => "#hello", :public => true, :to => 'all')
get :show, :name => 'hello'
assigns(:posts).models.should == [stranger_post]
assigns(:posts).should == [stranger_post]
end
it 'displays a post with a comment containing the tag search' do
@ -76,7 +76,7 @@ describe TagsController do
other_post = bob.post(:status_message, :text => "sup y'all", :to => 'all')
Factory(:comment, :text => "#hello", :post => other_post)
get :show, :name => 'hello'
assigns(:posts).models.should == [other_post]
assigns(:posts).should == [other_post]
response.status.should == 200
end
@ -117,7 +117,7 @@ describe TagsController do
it "assigns the right set of posts" do
get :show, :name => 'what'
assigns[:posts].models.should == [@post]
assigns[:posts].should == [@post]
end
it 'succeeds with comments' do

View file

@ -1,58 +0,0 @@
require 'spec_helper'
describe PostsFake do
before do
@posts = []
@people = []
4.times do
post = Factory(:status_message)
@people << post.author
4.times do
comment = Factory(:comment, :post => post)
comment.author
end
@posts << post
end
end
describe '#initialize' do
before do
@posts_fake = PostsFake.new(@posts)
end
it 'sets @people_hash' do
@people.each do |person|
@posts_fake.people_hash[person.reload.id].should == person
end
@posts_fake.people_hash.length.should == @people.length
end
it 'sets @post_fakes to an array of fakes' do
@posts_fake.post_fakes.each{|x| x.class.should be PostsFake::Fake}
end
end
describe PostsFake::Fake do
include Rails.application.routes.url_helpers
before do
@post = mock()
@fakes = mock()
@fake = PostsFake::Fake.new(@post, @fakes)
end
it 'refers to the parent collection for an author' do
@post.should_receive(:author_id)
@fakes.should_receive(:people_hash).and_return({})
@fake.author
end
it 'refers to its post for any other field' do
@post.should_receive(:text)
@fake.text
end
it 'works with url helpers' do
sm = Factory(:status_message)
fake = PostsFake::Fake.new(sm, @fakes)
post_path(fake).should == post_path(sm)
end
end
end