Querying spec passes, 63 model spec failures

This commit is contained in:
Raphael 2010-12-20 18:49:07 -08:00
parent f043c9cc7e
commit 659dfd36ed
10 changed files with 27 additions and 41 deletions

View file

@ -62,7 +62,7 @@ class Comment < ActiveRecord::Base
def self.hash_from_post_ids post_ids def self.hash_from_post_ids post_ids
hash = {} hash = {}
comments = where(:post_id.in => post_ids) comments = where(:post_id => post_ids)
post_ids.each do |id| post_ids.each do |id|
hash[id] = [] hash[id] = []
end end

View file

@ -168,6 +168,6 @@ class Person < ActiveRecord::Base
private private
def remove_all_traces def remove_all_traces
Post.all(:person_id => id).each { |p| p.delete } Post.where(:person_id => id).delete_all
end end
end end

View file

@ -10,7 +10,7 @@ class StatusMessage < Post
validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters" validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters"
xml_name :status_message xml_name :status_message
xml_accessor :message #xml_accessor :message
has_many :photos, :dependent => :destroy has_many :photos, :dependent => :destroy
validate :message_or_photos_present? validate :message_or_photos_present?

View file

@ -14,8 +14,6 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable, :recoverable, :rememberable, :trackable, :validatable,
:timeoutable :timeoutable
# key :visible_post_ids, Array, :typecast => 'ObjectId'
#
before_validation :strip_and_downcase_username, :on => :create before_validation :strip_and_downcase_username, :on => :create
before_validation :set_current_language, :on => :create before_validation :set_current_language, :on => :create
@ -38,9 +36,6 @@ class User < ActiveRecord::Base
has_many :contacts has_many :contacts
has_many :contact_people, :through => :contacts has_many :contact_people, :through => :contacts
has_many :services has_many :services
# many :raw_visible_posts, :in => :visible_post_ids, :class => Post
# many :services, :class => Service
before_destroy :disconnect_everyone, :remove_person before_destroy :disconnect_everyone, :remove_person
before_save do before_save do
@ -136,7 +131,7 @@ class User < ActiveRecord::Base
def update_post(post, post_hash = {}) def update_post(post, post_hash = {})
if self.owns? post if self.owns? post
post.update_attributes(post_hash) post.update_attributes(post_hash)
aspects = aspects_with_post(post.id) aspects = self.aspects.joins(:posts).where(:posts => {:id => post.id})
self.push_to_aspects(post, aspects) self.push_to_aspects(post, aspects)
end end
end end

View file

@ -74,7 +74,7 @@ class CreateSchema < ActiveRecord::Migration
t.integer :person_id t.integer :person_id
t.boolean :public, :default => false t.boolean :public, :default => false
t.string :diaspora_handle t.string :diaspora_handle
t.boolean :pending t.boolean :pending, :default => false
t.integer :user_refs, :default => 0 t.integer :user_refs, :default => 0
t.string :type t.string :type
t.text :message t.text :message

View file

@ -110,7 +110,7 @@ ActiveRecord::Schema.define(:version => 0) do
t.integer "person_id" t.integer "person_id"
t.boolean "public", :default => false t.boolean "public", :default => false
t.string "diaspora_handle" t.string "diaspora_handle"
t.boolean "pending" t.boolean "pending", :default => false
t.integer "user_refs", :default => 0 t.integer "user_refs", :default => 0
t.string "type" t.string "type"
t.text "message" t.text "message"

View file

@ -11,7 +11,7 @@ module Diaspora
end end
def raw_visible_posts def raw_visible_posts
Post.joins(:post_visibilities => :aspect).where(:pending => false, :post_visibilities => {:aspects => {:user_id => self.id}}) Post.joins(:aspects).where(:pending => false, :aspects => {:user_id => self.id})
end end
def visible_posts( opts = {} ) def visible_posts( opts = {} )
@ -39,9 +39,9 @@ module Diaspora
people = Person.where(:id => person_ids) people = Person.where(:id => person_ids)
if opts[:type] == 'remote' if opts[:type] == 'remote'
people.delete_if{ |p| !p.owner.blank? } people = people.where(:owner_id => nil)
elsif opts[:type] == 'local' elsif opts[:type] == 'local'
people.delete_if{ |p| p.owner.blank? } people = people.where('`people`.`owner_id` IS NOT NULL')
end end
people people
end end
@ -61,7 +61,7 @@ module Diaspora
end end
def request_from(person) def request_from(person)
Request.where(:sender_id => person.id, :recipient_id => self.person.id) Request.where(:sender_id => person.id, :recipient_id => self.person.id).first
end end
def posts_from(person) def posts_from(person)

View file

@ -94,9 +94,8 @@ module Diaspora
else else
retraction.perform self.id retraction.perform self.id
aspects = self.aspects_with_person(retraction.person) aspects = self.aspects_with_person(retraction.person)
aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id) PostVisibility.where(:post_id => retraction.post_id,
aspect.save :aspect_id => aspects.map{|a| a.id}).delete_all
}
end end
retraction retraction
end end

View file

@ -37,7 +37,6 @@ describe User do
connect_users(@user2, @aspect2, @user, @aspect) connect_users(@user2, @aspect2, @user, @aspect)
aspect3 = @user.aspects.create(:name => "Snoozers") aspect3 = @user.aspects.create(:name => "Snoozers")
@status_message1 = @user2.post :status_message, :message => "hi", :to => @aspect2.id @status_message1 = @user2.post :status_message, :message => "hi", :to => @aspect2.id
pp @status_message1
@status_message2 = @user2.post :status_message, :message => "hey", :public => true , :to => @aspect2.id @status_message2 = @user2.post :status_message, :message => "hey", :public => true , :to => @aspect2.id
@status_message3 = @user.post :status_message, :message => "hey", :public => true , :to => @aspect.id @status_message3 = @user.post :status_message, :message => "hey", :public => true , :to => @aspect.id
@status_message4 = @user2.post :status_message, :message => "blah", :public => true , :to => @aspect2.id @status_message4 = @user2.post :status_message, :message => "blah", :public => true , :to => @aspect2.id
@ -76,34 +75,26 @@ describe User do
it "selects by message contents" do it "selects by message contents" do
query = @user2.visible_posts(:message => "hi") query = @user2.visible_posts(:message => "hi")
pp @status_message1
pp query.to_sql
pp query
query.should == [@status_message1] query.should == [@status_message1]
end end
it "does not return pending posts" do it "does not return pending posts" do
@pending_status_message.pending.should be_true @pending_status_message.pending.should be_true
@user2.visible_posts.should_not include @pending_status_message @user2.visible_posts.should_not include @pending_status_message
@user2.visible_posts(:by_members_of => @aspect2).should_not include @pending_status_message
end end
context 'with two users' do
let!(:first_aspect) {@user.aspects.create(:name => 'bruisers')}
let!(:second_aspect) {@user.aspects.create(:name => 'losers')}
it "queries by aspect" do it "queries by aspect" do
connect_users(@user, first_aspect, @user2, @user2.aspects.first) query = @user.visible_posts(:by_members_of => @aspect)
@user.receive status_message1.to_diaspora_xml, @user2.person query.include?(@status_message1).should == true
query.include?(@status_message2).should == true
@user.visible_posts(:by_members_of => first_aspect).should =~ [status_message1] query.include?(@status_message3).should == true
@user.visible_posts(:by_members_of => second_aspect).should =~ [] query.include?(@status_message4).should == true
query.include?(@status_message5).should == false
@user.visible_posts(:by_members_of => @user.aspects.create(:name => "aaaaah")).should be_empty
end end
it '#find_visible_post_by_id' do it '#find_visible_post_by_id' do
@user2.find_visible_post_by_id(status_message1.id).should == status_message1 @user2.find_visible_post_by_id(@status_message1.id).should == @status_message1
@user.find_visible_post_by_id(status_message1.id).should == nil @user2.find_visible_post_by_id(@status_message5.id).should == nil
end
end end
end end
end end
@ -147,7 +138,8 @@ describe User do
@user.people_in_aspects([first_aspect]).count.should == 4 @user.people_in_aspects([first_aspect]).count.should == 4
@user.people_in_aspects([first_aspect], :type => 'remote').count.should == 1 @user.people_in_aspects([first_aspect], :type => 'remote').count.should == 1
@user.people_in_aspects([first_aspect], :type => 'local').count.should == 3 q = @user.people_in_aspects([first_aspect], :type => 'local')
q.count.should == 3
end end
it 'does not return people not connected to user on same pod' do it 'does not return people not connected to user on same pod' do

View file

@ -183,7 +183,7 @@ describe User do
it 'should receive a salmon for a post' do it 'should receive a salmon for a post' do
user2.receive_salmon( salmon.xml_for user2.person ) user2.receive_salmon( salmon.xml_for user2.person )
user2.visible_post_ids.include?(post.id).should be true user2.raw_visible_posts.include?(post).should be_true
end end
end end
end end