these spes are really green. too bad we need #moar

This commit is contained in:
Maxwell Salzberg 2011-09-30 19:10:01 -07:00
parent ad9dcd8542
commit 9a4c478a7b
13 changed files with 60 additions and 29 deletions

View file

@ -150,4 +150,8 @@ class ApplicationController < ActionController::Base
def sort_order
is_mobile_device? ? 'created_at' : session[:sort_order]
end
def max_time
params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
end
end

View file

@ -47,27 +47,17 @@ class TagsController < ApplicationController
def show
params[:name].downcase!
@aspect = :tag
if current_user
@posts = StatusMessage.
joins("LEFT OUTER JOIN post_visibilities ON post_visibilities.post_id = posts.id").
joins("LEFT OUTER JOIN contacts ON contacts.id = post_visibilities.contact_id").
where(Contact.arel_table[:user_id].eq(current_user.id).or(
StatusMessage.arel_table[:public].eq(true).or(
StatusMessage.arel_table[:author_id].eq(current_user.person.id)
)
)).select('DISTINCT posts.*')
@posts = StatusMessage.owned_or_visible_by_user(current_user)
else
@posts = StatusMessage.all_public
end
params[:prefill] = "##{params[:name]} "
@posts = @posts.tagged_with(params[:name])
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({:author => :profile}, :comments, :photos).order('posts.created_at DESC').limit(15)
@posts = @posts.tagged_with(params[:name]).for_a_stream(max_time)
@commenting_disabled = true
params[:prefill] = "##{params[:name]} "
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts}
@ -84,4 +74,5 @@ class TagsController < ApplicationController
end
@tag_followed
end
end

View file

@ -11,11 +11,11 @@ module StreamHelper
elsif controller.instance_of?(PeopleController)
person_path(@person, :max_time => @posts.last.created_at.to_i)
elsif controller.instance_of?(TagFollowingsController)
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream))
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(MentionsController)
mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream))
mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
elsif controller.instance_of?(AspectsController)
aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids)
aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids, :sort_order => session[:sort_order])
else
raise 'in order to use pagination for this new controller, update next_page_path in stream helper'
end

View file

@ -33,10 +33,11 @@ class Post < ActiveRecord::Base
validates :guid, :uniqueness => true
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)
def self.for_a_stream(max_time, order='created_at')
where("posts.#{order} < ?", max_time).order("posts.#{order} desc").
includes({:author => :profile}, :mentions => {:person => :profile}).
includes_for_a_stream.
limit(15)
end

View file

@ -26,8 +26,19 @@ class StatusMessage < Post
after_create :create_mentions
#scopes
scope :where_person_is_mentioned, lambda{|person| joins(:mentions).where(:mentions => {:person_id => person.id})}
def self.owned_or_visible_by_user(user)
joins("LEFT OUTER JOIN post_visibilities ON post_visibilities.post_id = posts.id").
joins("LEFT OUTER JOIN contacts ON contacts.id = post_visibilities.contact_id").
where(Contact.arel_table[:user_id].eq(user.id).or(
StatusMessage.arel_table[:public].eq(true).or(
StatusMessage.arel_table[:author_id].eq(user.person.id)
)
)).select('DISTINCT posts.*')
end
def text(opts = {})
self.formatted_message(opts)
end

View file

@ -181,6 +181,7 @@ And /^I scroll down$/ do
evaluate_script("window.scrollBy(0,3000000)")
sleep 1
wait_until(30) { evaluate_script('$("#infscr-loading:visible").length') == 0 }
And "I wait for the ajax to finish"
end
Then /^the notification dropdown should be visible$/ do

View file

@ -25,6 +25,7 @@ When /^I sign in as "([^"]*)"$/ do |email|
@me = User.find_by_email(email)
@me.password ||= 'password'
Given 'I am signed in'
And 'I wait for the ajax to finish'
end
When /^I sign in with password "([^"]*)"$/ do |password|

View file

@ -1,7 +1,7 @@
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'base_stream'
class AspectStream < BaseStream
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
@ -41,14 +41,14 @@ class AspectStream < BaseStream
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts
@posts ||= @user.visible_posts(:by_members_of => aspect_ids,
:type => TYPES_OF_POST_IN_STREAM,
:order => "#{@order} DESC",
:max_time => @max_time
:order => "#{order} DESC",
:max_time => max_time
).for_a_stream(max_time, order)
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= Person.all_from_aspects(aspect_ids, @user).includes(:profile)
@people ||= Person.all_from_aspects(aspect_ids, user).includes(:profile)
end
def link(opts={})
@ -96,7 +96,7 @@ class AspectStream < BaseStream
if for_all_aspects? || aspect_ids.size > 1
Rails.application.routes.url_helpers.contacts_path
else
Rails.application.routes.url_helpers.contacts_path(:a_id => @stream.aspect.id)
Rails.application.routes.url_helpers.contacts_path(:a_id => aspect.id)
end
end
end

View file

@ -1,6 +1,4 @@
class BaseStream
attr_accessor :max_time, :order, :user
def initialize(user, opts={})

View file

@ -17,7 +17,7 @@ class TagStream < BaseStream
if tag_string.empty?
[]
else
@posts ||= StatusMessage.tagged_with([@tag_string], :any => true).where(:public => true).for_a_stream(@max_time, @order)
@posts ||= StatusMessage.owned_or_visible_by_user(user).tagged_with([@tag_string], :any => true).where(:public => true).for_a_stream(@max_time, @order)
end
end

View file

@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'aspect_stream'
require 'spec_helper'
describe AspectStream do
describe '#aspects' do
@ -70,7 +70,7 @@ describe AspectStream do
it 'respects max_time' do
stream = AspectStream.new(@alice, [1,2], :max_time => 123)
@alice.should_receive(:visible_posts).with(hash_including(:max_time => 123)).and_return(stub.as_null_object)
@alice.should_receive(:visible_posts).with(hash_including(:max_time => instance_of(Time))).and_return(stub.as_null_object)
stream.posts
end
end

View file

@ -10,6 +10,20 @@ describe Post do
@aspect = @user.aspects.create(:name => "winners")
end
describe 'scopes' do
describe '.for_a_stream' do
it 'returns the posts ordered and limited by unix time'
it 'includes everything in .includes_for_a_stream'
it 'is limited to 15 posts'
end
describe 'includes for a stream' do
it 'inclues author profile and mentions'
it 'should include photos and root of reshares(but does not)'
end
end
describe 'validations' do
it 'validates uniqueness of guid and does not throw a db error' do
message = Factory(:status_message)

View file

@ -17,6 +17,16 @@ describe StatusMessage do
@aspect = @user.aspects.first
end
describe 'scopes' do
describe '.where_person_is_mentioned' do
it 'returns status messages where the given person is mentioned'
end
describe '.owned_or_visible_by_user' do
it 'scopes status_messages based on posts visisble via contacts or public'
end
end
describe '.before_create' do
it 'calls build_tags' do
status = Factory.build(:status_message)