moar specs, a little perf upgrade for base_stream#person

This commit is contained in:
Your Name 2011-10-06 16:36:40 -07:00
parent 55ffc44a42
commit 5b9fbd19ed
10 changed files with 43 additions and 25 deletions

View file

@ -148,7 +148,6 @@ class ApplicationController < ActionController::Base
end end
def default_stream_action(stream_klass) def default_stream_action(stream_klass)
puts "yah"
authenticate_user! authenticate_user!
save_sort_order save_sort_order
@stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order) @stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order)

View file

@ -7,6 +7,7 @@ require File.join(Rails.root, 'lib', 'stream', 'public_stream')
class PostsController < ApplicationController class PostsController < ApplicationController
before_filter :authenticate_user!, :except => :show before_filter :authenticate_user!, :except => :show
before_filter :set_format_if_malformed_from_status_net, :only => :show before_filter :set_format_if_malformed_from_status_net, :only => :show
before_filter :redirect_unless_admin, :only => :index
respond_to :html, respond_to :html,
:mobile, :mobile,

View file

@ -4,7 +4,7 @@
module PublisherHelper module PublisherHelper
def public_value def public_value
params[:controller] == "tags" params[:controller] == "tags" || params[:controller] == "posts"
end end
def remote? def remote?

View file

@ -841,6 +841,7 @@ en:
contacts_title: "People who dig these tags" contacts_title: "People who dig these tags"
public: public:
title: "Public Activity" title: "Public Activity"
contacts_title: "Recent Posters"
users: users:
logged_out: logged_out:

View file

@ -9,16 +9,16 @@ class BaseStream
end end
def random_featured_user def random_featured_user
Person.find_by_diaspora_handle(featured_diaspora_id) @random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
end end
def has_featured_users? def has_featured_users?
featured_diaspora_id.present? random_featured_user.present?
end end
#requied to implement said stream #requied to implement said stream
def link(opts={}) def link(opts={})
Rails.application.routes.url_helpers.mentions_path(opts) 'change me in lib/base_stream.rb!'
end end
def can_comment?(post) def can_comment?(post)
@ -26,15 +26,17 @@ class BaseStream
end end
def title def title
'a title' 'change me in lib/base_stream.rb!'
end end
def posts def posts
[] []
end end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people def people
[] people_ids = posts.map{|x| x.author_id}
Person.where(:id => people_ids).includes(:profile)
end end
def contacts_link_title def contacts_link_title
@ -42,11 +44,11 @@ class BaseStream
end end
def contacts_title def contacts_title
"title for a stream" 'change me in lib/base_stream.rb!'
end end
def contacts_link def contacts_link
'#' 'change me in lib/base_stream.rb!'
end end
#helpers #helpers

View file

@ -17,11 +17,6 @@ class MentionStream< BaseStream
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order) @posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
end end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title def contacts_title
I18n.translate('streams.mentions.contacts_title') I18n.translate('streams.mentions.contacts_title')
end end

View file

@ -3,7 +3,6 @@
# the COPYRIGHT file. # the COPYRIGHT file.
class PublicStream < BaseStream class PublicStream < BaseStream
def link(opts={}) def link(opts={})
Rails.application.routes.url_helpers.public_stream_path(opts) Rails.application.routes.url_helpers.public_stream_path(opts)
end end
@ -12,19 +11,14 @@ class PublicStream < BaseStream
I18n.translate("streams.public.title") I18n.translate("streams.public.title")
end end
# @return [ActiveRecord::Association<Post>] AR association of posts # @return [ActiveRecord::Association<Post>] AR association of posts
def posts def posts
@posts ||= Post.all_public.for_a_stream(max_time, order) @posts ||= Post.all_public.for_a_stream(max_time, order)
end end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title def contacts_title
"The last 15 people in this stream" I18n.translate("streams.public.contacts_title")
end end
def can_comment?(post) def can_comment?(post)

View file

@ -20,10 +20,6 @@ class TagStream < BaseStream
for_a_stream(@max_time, @order) for_a_stream(@max_time, @order)
end end
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title def contacts_title
I18n.translate('streams.tags.contacts_title') I18n.translate('streams.tags.contacts_title')
end end

View file

@ -146,4 +146,23 @@ describe PostsController do
StatusMessage.exists?(message.id).should be_true StatusMessage.exists?(message.id).should be_true
end end
end end
describe '#index' do
before do
sign_in alice
end
it 'will succeed if admin' do
AppConfig[:admins] = [alice.username]
get :index
response.should be_success
end
it 'will redirect if not' do
AppConfig[:admins] = []
get :index
response.should be_redirect
end
end
end end

View file

@ -0,0 +1,11 @@
require 'spec_helper'
require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream')
describe PublicStream do
before do
@stream = PublicStream.new(stub)
end
describe 'shared behaviors' do
it_should_behave_like 'it is a stream'
end
end