display photos correctly

This commit is contained in:
Raphael 2011-01-17 19:21:37 -08:00
parent 0c24510682
commit 6474ca9540
5 changed files with 36 additions and 21 deletions

View file

@ -26,8 +26,7 @@ class PhotosController < ApplicationController
@similar_people = similar_people @contact
end
@posts = current_user.raw_visible_posts.where(
:type => 'Photo',
@posts = current_user.visible_photos.where(
:person_id => @person.id
).paginate(:page => params[:page])
@ -136,7 +135,7 @@ class PhotosController < ApplicationController
end
def show
@photo = current_user.find_visible_post_by_id params[:id]
@photo = current_user.visible_photos.where(:id => params[:id]).first
if @photo
@parent = @photo.status_message

View file

@ -27,6 +27,7 @@ class StatusMessagesController < ApplicationController
@status_message.photos += photos
for photo in photos
photo.public = public_flag
photo.pending = false
photo.save
current_user.add_to_streams(photo, aspects)
current_user.dispatch_post(photo)

View file

@ -11,10 +11,16 @@ module Diaspora
end
def raw_visible_posts
Post.joins(:post_visibilities => :aspect).where(:pending => false,
Post.joins(:aspects).where(:pending => false,
:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*')
end
def visible_photos
p = Post.arel_table
Post.joins(:aspects).where(p[:status_message_id].not_eq(nil).or(p[:pending].eq(false))
).where(:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*').order("posts.updated_at DESC")
end
def visible_posts( opts = {} )
order = opts.delete(:order)
order ||= 'created_at DESC'

View file

@ -15,11 +15,12 @@ describe PhotosController do
let(:filename) { 'button.png' }
let(:fixture_name) { File.join(File.dirname(__FILE__), '..', 'fixtures', filename) }
let!(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) }
let!(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) }
let(:photo1) { user1.post(:photo, :user_file => File.open(fixture_name), :to => aspect1.id) }
let(:photo2) { user2.post(:photo, :user_file => File.open(fixture_name), :to => aspect2.id) }
before do
connect_users(user1, aspect1, user2, aspect2)
photo1; photo2
@controller.stub!(:current_user).and_return(user1)
sign_in :user, user1
end
@ -57,11 +58,11 @@ describe PhotosController do
assigns[:posts].should == [photo1]
end
it 'sets the person to a contact if person_id is set' do
it "displays another person's pictures" do
get :index, :person_id => user2.person.id.to_s
assigns[:person].should == user2.person
assigns[:posts].should be_empty
assigns[:posts].should == [photo2]
end
end

View file

@ -60,21 +60,29 @@ describe StatusMessagesController do
old_status_message.reload.message.should == 'hello'
end
it "dispatches all referenced photos" do
context 'with photos' do
before do
fixture_filename = 'button.png'
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
@photo1 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
@photo2 = user1.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect1.id)
photo1.save!
photo2.save!
hash = status_message_hash
hash[:photos] = [photo1.id.to_s, photo2.id.to_s]
@photo1.save!
@photo2.save!
@hash = status_message_hash
@hash[:photos] = [@photo1.id.to_s, @photo2.id.to_s]
end
it "dispatches all referenced photos" do
user1.should_receive(:dispatch_post).exactly(3).times
post :create, hash
post :create, @hash
end
it "sets the pending bit of referenced photos" do
post :create, @hash
@photo1.reload.pending.should be_false
@photo2.reload.pending.should be_false
end
end
end