Add tag search on public page

This commit is contained in:
Raphael Sofaer 2011-03-10 18:36:58 -08:00
parent c35f143b29
commit b86098055e
4 changed files with 55 additions and 6 deletions

View file

@ -10,9 +10,21 @@ class PostsController < ApplicationController
skip_before_filter :set_grammatical_gender skip_before_filter :set_grammatical_gender
def index def index
@posts = StatusMessage.joins(:author).where(Person.arel_table[:owner_id].not_eq(nil)).where(:public => true, :pending => false if current_user
).includes(:comments, :photos @posts = StatusMessage.joins(:aspects, :author).where(:pending => false
).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC') ).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true))
).select('DISTINCT `posts`.*')
else
@posts = StatusMessage.joins(:author).where(:public => true, :pending => false)
end
if params[:tag]
@posts = @posts.tagged_with(params[:tag])
else
@posts = @posts.where(Person.arel_table[:owner_id].not_eq(nil))
end
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
@fakes = PostsFake.new(@posts) @fakes = PostsFake.new(@posts)
@commenting_disabled = true @commenting_disabled = true

View file

@ -10,7 +10,10 @@
= include_javascripts :home = include_javascripts :home
%h1 %h1
= t('.whatup', :pod => @pod_url) - if params[:tag]
= t('.posts_tagged_with', :tag => params[:tag])
- else
= t('.whatup', :pod => @pod_url)
.span-15 .span-15
#main_stream.stream #main_stream.stream

View file

@ -426,6 +426,7 @@ en:
posts: posts:
index: index:
whatup: "What's happening on %{pod}" whatup: "What's happening on %{pod}"
posts_tagged_with: "Posts tagged with #%{tag}"
requests: requests:
manage_aspect_contacts: manage_aspect_contacts:
manage_within: "Manage contacts within" manage_within: "Manage contacts within"

View file

@ -19,17 +19,50 @@ describe PostsController do
get :index get :index
response.status.should == 200 response.status.should == 200
end end
it "shows the signed in user's posts" do
posts = []
2.times do
posts << @user.post(:status_message, :message => "#what", :to => 'all')
end
eve.post(:status_message, :message => "#what", :to => 'all')
get :index
assigns[:posts].should =~ posts
end
it "shows any posts that the user can see" do
posts = []
2.times do
posts << bob.post(:status_message, :message => "#what", :to => 'all')
end
eve.post(:status_message, :message => "#what", :to => 'all')
get :index
assigns[:posts].should =~ posts
end
end
it 'restricts the posts by tag' do
posts = []
2.times do
posts << @user.post(:status_message, :message => "#what", :public => true, :to => 'all')
end
2.times do
@user.post(:status_message, :message => "#hello", :public => true, :to => 'all')
end
get :index, :tag => 'what'
assigns[:posts].should =~ posts
end end
it 'shows the most recent public posts' do it 'shows the most recent public posts' do
posts = [] posts = []
10.times do 3.times do
posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all') posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
end end
get :index get :index
assigns[:posts].should =~ posts assigns[:posts].should =~ posts
end end
it' shows only local posts' do it' shows only local posts' do
10.times do 3.times do
@user.post(:status_message, :message => "hello", :public => true, :to => 'all') @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
end end
@user.person.update_attributes(:owner_id => nil) @user.person.update_attributes(:owner_id => nil)