Fix all specs, add foreign key constraints on post_visibility
This commit is contained in:
parent
8816bd7f91
commit
97d8b34599
9 changed files with 29 additions and 20 deletions
|
|
@ -26,9 +26,8 @@ class AspectsController < ApplicationController
|
|||
|
||||
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq
|
||||
@aspect_ids = @aspects.map { |a| a.id }
|
||||
@posts = StatusMessage.joins(:aspects).where(:pending => false,
|
||||
:aspects => {:id => @aspect_ids}).includes(:comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate(
|
||||
:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC')
|
||||
@posts = current_user.raw_visible_posts(:by_members_of => @aspect_ids, :type => 'StatusMessage').includes(
|
||||
:comments, :likes, :dislikes).paginate(:page => params[:page], :per_page => 15, :order => session[:sort_order] + ' DESC')
|
||||
@fakes = PostsFake.new(@posts)
|
||||
|
||||
@contact_count = current_user.contacts.count
|
||||
|
|
|
|||
|
|
@ -141,10 +141,10 @@ class PhotosController < ApplicationController
|
|||
end
|
||||
|
||||
def show
|
||||
@photo = current_user.visible_photos.where(:id => params[:id]).includes(:author, :status_message => :photos).first
|
||||
@photo ||= Photo.where(:public => true, :id => params[:id]).includes(:author, :status_message => :photos).first
|
||||
@photo = current_user.visible_photos.where(:id => params[:id]).first
|
||||
@photo ||= Photo.where(:public => true, :id => params[:id]).first
|
||||
if @photo
|
||||
@parent = @photo.status_message
|
||||
@parent = StatusMessage.where(:id => @photo.status_message_id).includes(:photos).first if @photo.status_message_id
|
||||
|
||||
#if photo is not an attachment, fetch comments for self
|
||||
if @parent
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class Post < ActiveRecord::Base
|
|||
has_many :post_visibilities
|
||||
has_many :contacts, :through => :post_visibilities
|
||||
has_many :mentions, :dependent => :destroy
|
||||
|
||||
belongs_to :author, :class_name => 'Person'
|
||||
|
||||
cattr_reader :per_page
|
||||
|
|
|
|||
|
|
@ -3,11 +3,6 @@
|
|||
# the COPYRIGHT file.
|
||||
|
||||
class PostVisibility < ActiveRecord::Base
|
||||
|
||||
belongs_to :contact
|
||||
validates_presence_of :contact
|
||||
|
||||
belongs_to :post
|
||||
validates_presence_of :post
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -50,6 +50,8 @@ SQL
|
|||
|
||||
remove_index :post_visibilities, [:aspect_id, :post_id]
|
||||
remove_column :post_visibilities, :aspect_id
|
||||
add_foreign_key :post_visibilities, :contacts, :dependent => :delete
|
||||
add_foreign_key :post_visibilities, :posts, :dependent => :delete
|
||||
end
|
||||
|
||||
def self.down
|
||||
|
|
|
|||
|
|
@ -389,6 +389,9 @@ ActiveRecord::Schema.define(:version => 20110328202414) do
|
|||
|
||||
add_foreign_key "notification_actors", "notifications", :name => "notification_actors_notification_id_fk", :dependent => :delete
|
||||
|
||||
add_foreign_key "post_visibilities", "contacts", :name => "post_visibilities_contact_id_fk", :dependent => :delete
|
||||
add_foreign_key "post_visibilities", "posts", :name => "post_visibilities_post_id_fk", :dependent => :delete
|
||||
|
||||
add_foreign_key "posts", "people", :name => "posts_author_id_fk", :column => "author_id", :dependent => :delete
|
||||
|
||||
add_foreign_key "profiles", "people", :name => "profiles_person_id_fk", :dependent => :delete
|
||||
|
|
|
|||
|
|
@ -85,13 +85,12 @@ module Diaspora
|
|||
def remove_contact(contact)
|
||||
bad_person_id = contact.person_id
|
||||
posts = contact.posts.all
|
||||
contact.post_visibilities.delete_all
|
||||
contact.destroy
|
||||
posts.each do |post|
|
||||
if post.user_refs < 1
|
||||
post.destroy
|
||||
end
|
||||
end
|
||||
contact.destroy
|
||||
end
|
||||
|
||||
def disconnected_by(person)
|
||||
|
|
|
|||
|
|
@ -10,17 +10,26 @@ module Diaspora
|
|||
self.raw_visible_posts.where(:id => id).includes({:author => :profile}, {:comments => {:author => :profile}}, :photos).first
|
||||
end
|
||||
|
||||
def raw_visible_posts
|
||||
post_ids = []
|
||||
post_ids = Post.joins(:contacts).where(:contacts => {:user_id => self.id}).map{|p| p.id}
|
||||
def raw_visible_posts(opts = {})
|
||||
opts[:type] ||= ['StatusMessage', 'Photo']
|
||||
|
||||
post_ids += Post.joins(:aspect_visibilities => :aspect).where(:aspects => {:user_id => self.id}).select('posts.id').map{|p| p.id}
|
||||
posts_from_others = Post.joins(:contacts).where(:contacts => {:user_id => self.id})
|
||||
posts_from_self = self.person.posts.joins(:aspect_visibilities => :aspect).where(:aspects => {:user_id => self.id})
|
||||
|
||||
Post.where(:id => post_ids, :pending => false).select('DISTINCT `posts`.*')
|
||||
if opts[:by_members_of]
|
||||
posts_from_others = posts_from_others.joins(:contacts => :aspect_memberships).where(
|
||||
:aspect_memberships => {:aspect_id => opts[:by_members_of]})
|
||||
posts_from_self = posts_from_self.where(:aspects => {:id => opts[:by_members_of]})
|
||||
end
|
||||
|
||||
post_ids = posts_from_others.select('posts.id').map{|p| p.id}
|
||||
post_ids += posts_from_self.select('posts.id').map{|p| p.id}
|
||||
|
||||
Post.where(:id => post_ids, :pending => false, :type => opts[:type]).select('DISTINCT `posts`.*')
|
||||
end
|
||||
|
||||
def visible_photos
|
||||
raw_visible_posts.where(:type => 'Photo')
|
||||
raw_visible_posts(:type => 'Photo')
|
||||
end
|
||||
|
||||
def contact_for(person)
|
||||
|
|
|
|||
|
|
@ -179,7 +179,6 @@ describe 'a user receives a post' do
|
|||
@contact.post_visibilities.reset
|
||||
@contact.posts(true).should include(@post)
|
||||
@post.post_visibilities.reset
|
||||
|
||||
end
|
||||
|
||||
it 'deletes a post if the noone links to it' do
|
||||
|
|
@ -197,9 +196,11 @@ describe 'a user receives a post' do
|
|||
it 'should keep track of user references for one person ' do
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 3
|
||||
@status_message.contacts(true).should include(@contact)
|
||||
|
||||
@user1.disconnect(@contact)
|
||||
@status_message.reload
|
||||
@status_message.contacts(true).should_not include(@contact)
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 2
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue