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
def index
@posts = StatusMessage.joins(:author).where(Person.arel_table[:owner_id].not_eq(nil)).where(:public => true, :pending => false
).includes(:comments, :photos
).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC')
if current_user
@posts = StatusMessage.joins(:aspects, :author).where(:pending => false
).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)
@commenting_disabled = true

View file

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

View file

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

View file

@ -19,17 +19,50 @@ describe PostsController do
get :index
response.status.should == 200
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
it 'shows the most recent public posts' do
posts = []
10.times do
3.times do
posts << @user.post(:status_message, :message => "hello", :public => true, :to => 'all')
end
get :index
assigns[:posts].should =~ posts
end
it' shows only local posts' do
10.times do
3.times do
@user.post(:status_message, :message => "hello", :public => true, :to => 'all')
end
@user.person.update_attributes(:owner_id => nil)