Skip to content
Extraits de code Groupes Projets
Valider 9a4c478a rédigé par Maxwell Salzberg's avatar Maxwell Salzberg
Parcourir les fichiers

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

parent ad9dcd85
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -150,4 +150,8 @@ class ApplicationController < ActionController::Base ...@@ -150,4 +150,8 @@ class ApplicationController < ActionController::Base
def sort_order def sort_order
is_mobile_device? ? 'created_at' : session[:sort_order] is_mobile_device? ? 'created_at' : session[:sort_order]
end end
def max_time
params[:max_time] ? Time.at(params[:max_time].to_i) : Time.now
end
end end
...@@ -47,27 +47,17 @@ class TagsController < ApplicationController ...@@ -47,27 +47,17 @@ class TagsController < ApplicationController
def show def show
params[:name].downcase! params[:name].downcase!
@aspect = :tag @aspect = :tag
if current_user if current_user
@posts = StatusMessage. @posts = StatusMessage.owned_or_visible_by_user(current_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(current_user.id).or(
StatusMessage.arel_table[:public].eq(true).or(
StatusMessage.arel_table[:author_id].eq(current_user.person.id)
)
)).select('DISTINCT posts.*')
else else
@posts = StatusMessage.all_public @posts = StatusMessage.all_public
end end
params[:prefill] = "##{params[:name]} " @posts = @posts.tagged_with(params[:name]).for_a_stream(max_time)
@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)
@commenting_disabled = true @commenting_disabled = true
params[:prefill] = "##{params[:name]} "
if params[:only_posts] if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts} render :partial => 'shared/stream', :locals => {:posts => @posts}
...@@ -84,4 +74,5 @@ class TagsController < ApplicationController ...@@ -84,4 +74,5 @@ class TagsController < ApplicationController
end end
@tag_followed @tag_followed
end end
end end
...@@ -11,11 +11,11 @@ module StreamHelper ...@@ -11,11 +11,11 @@ module StreamHelper
elsif controller.instance_of?(PeopleController) elsif controller.instance_of?(PeopleController)
person_path(@person, :max_time => @posts.last.created_at.to_i) person_path(@person, :max_time => @posts.last.created_at.to_i)
elsif controller.instance_of?(TagFollowingsController) 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) 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) 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 else
raise 'in order to use pagination for this new controller, update next_page_path in stream helper' raise 'in order to use pagination for this new controller, update next_page_path in stream helper'
end end
......
...@@ -33,10 +33,11 @@ class Post < ActiveRecord::Base ...@@ -33,10 +33,11 @@ class Post < ActiveRecord::Base
validates :guid, :uniqueness => true validates :guid, :uniqueness => true
scope :all_public, where(:public => true, :pending => false) 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"). where("posts.#{order} < ?", max_time).order("posts.#{order} desc").
includes({:author => :profile}, :mentions => {:person => :profile}). includes_for_a_stream.
limit(15) limit(15)
end end
......
...@@ -26,8 +26,19 @@ class StatusMessage < Post ...@@ -26,8 +26,19 @@ class StatusMessage < Post
after_create :create_mentions after_create :create_mentions
#scopes
scope :where_person_is_mentioned, lambda{|person| joins(:mentions).where(:mentions => {:person_id => person.id})} 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 = {}) def text(opts = {})
self.formatted_message(opts) self.formatted_message(opts)
end end
......
...@@ -181,6 +181,7 @@ And /^I scroll down$/ do ...@@ -181,6 +181,7 @@ And /^I scroll down$/ do
evaluate_script("window.scrollBy(0,3000000)") evaluate_script("window.scrollBy(0,3000000)")
sleep 1 sleep 1
wait_until(30) { evaluate_script('$("#infscr-loading:visible").length') == 0 } wait_until(30) { evaluate_script('$("#infscr-loading:visible").length') == 0 }
And "I wait for the ajax to finish"
end end
Then /^the notification dropdown should be visible$/ do Then /^the notification dropdown should be visible$/ do
......
...@@ -25,6 +25,7 @@ When /^I sign in as "([^"]*)"$/ do |email| ...@@ -25,6 +25,7 @@ When /^I sign in as "([^"]*)"$/ do |email|
@me = User.find_by_email(email) @me = User.find_by_email(email)
@me.password ||= 'password' @me.password ||= 'password'
Given 'I am signed in' Given 'I am signed in'
And 'I wait for the ajax to finish'
end end
When /^I sign in with password "([^"]*)"$/ do |password| When /^I sign in with password "([^"]*)"$/ do |password|
......
# Copyright (c) 2010-2011, Diaspora Inc. This file is # Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'base_stream'
class AspectStream < BaseStream class AspectStream < BaseStream
TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo'] TYPES_OF_POST_IN_STREAM = ['StatusMessage', 'Reshare', 'ActivityStreams::Photo']
...@@ -41,14 +41,14 @@ class AspectStream < BaseStream ...@@ -41,14 +41,14 @@ class AspectStream < BaseStream
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts # 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, @posts ||= @user.visible_posts(:by_members_of => aspect_ids,
:type => TYPES_OF_POST_IN_STREAM, :type => TYPES_OF_POST_IN_STREAM,
:order => "#{@order} DESC", :order => "#{order} DESC",
:max_time => @max_time :max_time => max_time
).for_a_stream(max_time, order) ).for_a_stream(max_time, order)
end end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects # @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people def people
@people ||= Person.all_from_aspects(aspect_ids, @user).includes(:profile) @people ||= Person.all_from_aspects(aspect_ids, user).includes(:profile)
end end
def link(opts={}) def link(opts={})
...@@ -96,7 +96,7 @@ class AspectStream < BaseStream ...@@ -96,7 +96,7 @@ class AspectStream < BaseStream
if for_all_aspects? || aspect_ids.size > 1 if for_all_aspects? || aspect_ids.size > 1
Rails.application.routes.url_helpers.contacts_path Rails.application.routes.url_helpers.contacts_path
else 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 end
end end
class BaseStream class BaseStream
attr_accessor :max_time, :order, :user attr_accessor :max_time, :order, :user
def initialize(user, opts={}) def initialize(user, opts={})
......
...@@ -17,7 +17,7 @@ class TagStream < BaseStream ...@@ -17,7 +17,7 @@ class TagStream < BaseStream
if tag_string.empty? if tag_string.empty?
[] []
else 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
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# licensed under the Affero General Public License version 3 or later. See # licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file. # the COPYRIGHT file.
require 'aspect_stream' require 'spec_helper'
describe AspectStream do describe AspectStream do
describe '#aspects' do describe '#aspects' do
...@@ -70,7 +70,7 @@ describe AspectStream do ...@@ -70,7 +70,7 @@ describe AspectStream do
it 'respects max_time' do it 'respects max_time' do
stream = AspectStream.new(@alice, [1,2], :max_time => 123) 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 stream.posts
end end
end end
......
...@@ -10,6 +10,20 @@ describe Post do ...@@ -10,6 +10,20 @@ describe Post do
@aspect = @user.aspects.create(:name => "winners") @aspect = @user.aspects.create(:name => "winners")
end 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 describe 'validations' do
it 'validates uniqueness of guid and does not throw a db error' do it 'validates uniqueness of guid and does not throw a db error' do
message = Factory(:status_message) message = Factory(:status_message)
......
...@@ -17,6 +17,16 @@ describe StatusMessage do ...@@ -17,6 +17,16 @@ describe StatusMessage do
@aspect = @user.aspects.first @aspect = @user.aspects.first
end 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 describe '.before_create' do
it 'calls build_tags' do it 'calls build_tags' do
status = Factory.build(:status_message) status = Factory.build(:status_message)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter