Commit 5b9fbd19 authored by Your Name's avatar Your Name

moar specs, a little perf upgrade for base_stream#person

parent 55ffc44a
......@@ -148,7 +148,6 @@ class ApplicationController < ActionController::Base
end
def default_stream_action(stream_klass)
puts "yah"
authenticate_user!
save_sort_order
@stream = stream_klass.new(current_user, :max_time => params[:max_time], :order => sort_order)
......
......@@ -7,6 +7,7 @@ require File.join(Rails.root, 'lib', 'stream', 'public_stream')
class PostsController < ApplicationController
before_filter :authenticate_user!, :except => :show
before_filter :set_format_if_malformed_from_status_net, :only => :show
before_filter :redirect_unless_admin, :only => :index
respond_to :html,
:mobile,
......
......@@ -4,7 +4,7 @@
module PublisherHelper
def public_value
params[:controller] == "tags"
params[:controller] == "tags" || params[:controller] == "posts"
end
def remote?
......
......@@ -841,6 +841,7 @@ en:
contacts_title: "People who dig these tags"
public:
title: "Public Activity"
contacts_title: "Recent Posters"
users:
logged_out:
......
......@@ -9,16 +9,16 @@ class BaseStream
end
def random_featured_user
Person.find_by_diaspora_handle(featured_diaspora_id)
@random_featured_user ||= Person.find_by_diaspora_handle(featured_diaspora_id)
end
def has_featured_users?
featured_diaspora_id.present?
random_featured_user.present?
end
#requied to implement said stream
def link(opts={})
Rails.application.routes.url_helpers.mentions_path(opts)
'change me in lib/base_stream.rb!'
end
def can_comment?(post)
......@@ -26,15 +26,17 @@ class BaseStream
end
def title
'a title'
'change me in lib/base_stream.rb!'
end
def posts
[]
end
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
def people
[]
people_ids = posts.map{|x| x.author_id}
Person.where(:id => people_ids).includes(:profile)
end
def contacts_link_title
......@@ -42,11 +44,11 @@ class BaseStream
end
def contacts_title
"title for a stream"
'change me in lib/base_stream.rb!'
end
def contacts_link
'#'
'change me in lib/base_stream.rb!'
end
#helpers
......
......@@ -17,11 +17,6 @@ class MentionStream< BaseStream
@posts ||= StatusMessage.where_person_is_mentioned(self.user.person).for_a_stream(max_time, order)
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
I18n.translate('streams.mentions.contacts_title')
end
......
......@@ -3,7 +3,6 @@
# the COPYRIGHT file.
class PublicStream < BaseStream
def link(opts={})
Rails.application.routes.url_helpers.public_stream_path(opts)
end
......@@ -12,19 +11,14 @@ class PublicStream < BaseStream
I18n.translate("streams.public.title")
end
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
@posts ||= Post.all_public.for_a_stream(max_time, order)
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
"The last 15 people in this stream"
I18n.translate("streams.public.contacts_title")
end
def can_comment?(post)
......
......@@ -20,10 +20,6 @@ class TagStream < BaseStream
for_a_stream(@max_time, @order)
end
def people
@people ||= posts.map{|p| p.author}.uniq
end
def contacts_title
I18n.translate('streams.tags.contacts_title')
end
......
......@@ -146,4 +146,23 @@ describe PostsController do
StatusMessage.exists?(message.id).should be_true
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment