Fix query in TagsController#show

This commit is contained in:
Raphael Sofaer 2011-04-06 10:51:56 -07:00
parent 4c696603c6
commit fd0fa61d53
2 changed files with 31 additions and 18 deletions

View file

@ -40,9 +40,12 @@ class TagsController < ApplicationController
def show def show
if current_user if current_user
@posts = StatusMessage.joins(:aspects).where(:pending => false @posts = StatusMessage.joins(:contacts).where(:pending => false).where(
).where(Aspect.arel_table[:user_id].eq(current_user.id).or(StatusMessage.arel_table[:public].eq(true)) Contact.arel_table[:user_id].eq(current_user.id).or(
).select('DISTINCT posts.*') StatusMessage.arel_table[:public].eq(true).or(
StatusMessage.arel_table[:author_id].eq(current_user.person.id)
)
)).select('DISTINCT posts.*')
else else
@posts = StatusMessage.where(:public => true, :pending => false) @posts = StatusMessage.where(:public => true, :pending => false)
end end

View file

@ -7,13 +7,9 @@ require 'spec_helper'
describe TagsController do describe TagsController do
render_views render_views
before do
@user = alice
end
describe '#index (search)' do describe '#index (search)' do
before do before do
sign_in :user, @user sign_in :user, alice
bob.profile.tag_string = "#cats #diaspora #rad" bob.profile.tag_string = "#cats #diaspora #rad"
bob.profile.build_tags bob.profile.build_tags
bob.profile.save! bob.profile.save!
@ -45,10 +41,24 @@ describe TagsController do
context 'signed in' do context 'signed in' do
before do before do
sign_in :user, @user sign_in :user, alice
end end
it 'works' do it 'displays your own post' do
get :show, :name => 'testing' my_post = alice.post(:status_message, :text => "#what", :to => 'all')
get :show, :name => 'what'
assigns(:posts).should == [my_post]
response.status.should == 200
end
it "displays a friend's post" do
other_post = bob.post(:status_message, :text => "#hello", :to => 'all')
get :show, :name => 'hello'
assigns(:posts).should == [other_post]
response.status.should == 200
end
it 'displays a public post' do
other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all')
get :show, :name => 'hello'
assigns(:posts).should == [other_post]
response.status.should == 200 response.status.should == 200
end end
end end
@ -56,22 +66,22 @@ describe TagsController do
context "not signed in" do context "not signed in" do
context "when there are people to display" do context "when there are people to display" do
before do before do
@user.profile.tag_string = "#whatevs" alice.profile.tag_string = "#whatevs"
@user.profile.build_tags alice.profile.build_tags
@user.profile.save! alice.profile.save!
get :show, :name => "whatevs" get :show, :name => "whatevs"
end end
it "succeeds" do it "succeeds" do
response.should be_success response.should be_success
end end
it "assigns the right set of people" do it "assigns the right set of people" do
assigns(:people).should == [@user.person] assigns(:people).should == [alice.person]
end end
end end
context "when there are posts to display" do context "when there are posts to display" do
before do before do
@post = @user.post(:status_message, :text => "#what", :public => true, :to => 'all') @post = alice.post(:status_message, :text => "#what", :public => true, :to => 'all')
@user.post(:status_message, :text => "#hello", :public => true, :to => 'all') alice.post(:status_message, :text => "#hello", :public => true, :to => 'all')
end end
it "succeeds" do it "succeeds" do
get :show, :name => 'what' get :show, :name => 'what'
@ -82,7 +92,7 @@ describe TagsController do
assigns[:posts].should == [@post] assigns[:posts].should == [@post]
end end
it 'succeeds with comments' do it 'succeeds with comments' do
@user.comment('what WHAT!', :on => @post) alice.comment('what WHAT!', :on => @post)
get :show, :name => 'what' get :show, :name => 'what'
response.should be_success response.should be_success
end end