Fixed a few more specs, having trouble getting AR to return the count of distinct (once for all aspects a post is visible in) posts a user can see

This commit is contained in:
Michael Sofaer and Raphael Sofaer 2010-12-24 00:23:37 -08:00
parent 22a5832c01
commit 426651d827
6 changed files with 14 additions and 11 deletions

View file

@ -207,7 +207,7 @@ class User < ActiveRecord::Base
comment = Comment.new(:person_id => self.person.id,
:text => text,
:post => options[:on])
comment.set_guid
#sign comment as commenter
comment.creator_signature = comment.sign_with_key(self.encryption_key)

View file

@ -11,8 +11,8 @@ module Diaspora
end
def raw_visible_posts
Post.joins(:aspects).where(:pending => false,
:aspects => {:user_id => self.id})
Post.joins(:post_visibilities => :aspect).where(:pending => false,
:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*')
end
def visible_posts( opts = {} )

View file

@ -213,9 +213,7 @@ describe Comment do
it 'should attach the creator signature if the user is commenting' do
comment = user.comment "Yeah, it was great", :on => @remote_message
pp comment.signable_string
@remote_message.comments.reset
pp @remote_message.comments.first
@remote_message.comments.first.signature_valid?.should be_true
end

View file

@ -16,13 +16,12 @@ describe Retraction do
it 'should have a post id after serialization' do
retraction = Retraction.for(post)
xml = retraction.to_xml.to_s
xml.include?(post.id.to_s).should == true
xml.include?(post.guid.to_s).should == true
end
end
describe 'dispatching' do
it 'should dispatch a message on delete' do
Factory.create(:person)
it 'should dispatch a message on destroy' do
MessageHandler.should_receive :add_post_request
post.destroy
end

View file

@ -26,8 +26,10 @@ describe User do
it 'saves post into visible post ids' do
proc {
pp user.raw_visible_posts
user.add_to_streams(@post, @aspect_ids)
}.should change(user.raw_visible_posts, :count).by(1)
pp user.raw_visible_posts
}.should change{user.raw_visible_posts.count}.by(1)
user.reload.raw_visible_posts.should include @post
end
@ -46,7 +48,7 @@ describe User do
describe '#aspects_from_ids' do
it 'returns a list of all valid aspects a user can post to' do
aspect_ids = Aspect.all.map(&:id)
user.aspects_from_ids(aspect_ids).should =~ [aspect, aspect1]
user.aspects_from_ids(aspect_ids).should =~ user.aspects
end
it "lets you post to your own aspects" do
user.aspects_from_ids([aspect.id]).should == [aspect]

View file

@ -347,6 +347,8 @@ describe User do
it 'should send retractions to remote poeple' do
user2.delete
user2.person.owner_id = nil
user2.person.save
user.activate_contact(user2.person, aspect)
user.should_receive(:disconnect).once
@ -355,7 +357,9 @@ describe User do
it 'should disconnect local people' do
connect_users(user, aspect, user2, aspect2)
lambda {user.destroy}.should change{user2.reload.contacts.count}.by(-1)
lambda {
user.destroy
}.should change{user2.reload.contacts.count}.by(-1)
end
end
end