logical failures on person spec, 25 failing model specs

This commit is contained in:
Raphael 2010-12-21 18:59:28 -08:00
parent cbda6b8c58
commit baf0533466
13 changed files with 30 additions and 50 deletions

View file

@ -63,7 +63,7 @@ module SocketsHelper
end end
action_hash[:mine?] = object.person && (object.person.owner.id == uid) if object.respond_to?(:person) action_hash[:mine?] = object.person && (object.person.owner_id == uid) if object.respond_to?(:person)
I18n.locale = old_locale unless user.nil? I18n.locale = old_locale unless user.nil?

View file

@ -35,20 +35,17 @@ class Person < ActiveRecord::Base
validates_presence_of :url, :profile, :serialized_public_key validates_presence_of :url, :profile, :serialized_public_key
validates_uniqueness_of :diaspora_handle, :case_sensitive => false validates_uniqueness_of :diaspora_handle, :case_sensitive => false
scope :searchable, includes(:profile).where(:profile => {:searchable => true}) scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
def self.search(query) def self.search(query)
return [] if query.to_s.empty? return [] if query.to_s.empty?
query_tokens = query.to_s.strip.split(" ") query_tokens = query.to_s.strip.split(" ")
full_query_text = Regexp.escape(query.to_s.strip)
p = [] p = []
query_tokens.each do |token| query_tokens.each do |token|
q = Regexp.escape(token.to_s.strip) p = Person.searchable.where('profiles.first_name LIKE :token', :token => token).limit(30) \
p = Person.searchable.all('profile.first_name' => /^#{q}/i, 'limit' => 30) \ | Person.searchable.where('profiles.last_name LIKE :token', :token => token).limit(30) \
| Person.searchable.all('profile.last_name' => /^#{q}/i, 'limit' => 30) \ | Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \
| Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \
| p | p
end end

View file

@ -25,7 +25,9 @@ class Post < ActiveRecord::Base
before_destroy :propogate_retraction before_destroy :propogate_retraction
after_destroy :destroy_comments after_destroy :destroy_comments
attr_accessible :user_refs def user_refs
self.post_visibilities.count
end
def self.diaspora_initialize params def self.diaspora_initialize params
new_post = self.new params.to_hash new_post = self.new params.to_hash
@ -52,15 +54,6 @@ class Post < ActiveRecord::Base
false false
end end
def decrement_user_refs
user_refs -= 1
if (user_refs > 0) || person.owner.nil? == false
save
else
destroy
end
end
protected protected
def destroy_comments def destroy_comments
comments.each { |c| c.destroy } comments.each { |c| c.destroy }

View file

@ -24,8 +24,8 @@ class Profile < ActiveRecord::Base
validates_length_of :first_name, :maximum => 32 validates_length_of :first_name, :maximum => 32
validates_length_of :last_name, :maximum => 32 validates_length_of :last_name, :maximum => 32
# attr_accessible :first_name, :last_name, :image_url, :image_url_medium, attr_accessible :first_name, :last_name, :image_url, :image_url_medium,
# :image_url_small, :birthday, :gender, :bio, :searchable, :date :image_url_small, :birthday, :gender, :bio, :searchable, :date
belongs_to :person belongs_to :person

View file

@ -263,11 +263,11 @@ class User < ActiveRecord::Base
########### Profile ###################### ########### Profile ######################
def update_profile(params) def update_profile(params)
if params[:photo] if photo = params.delete(:photo)
params[:photo].update_attributes(:pending => false) if params[:photo].pending photo.update_attributes(:pending => false) if photo.pending
params[:image_url] = params[:photo].url(:thumb_large) params[:image_url] = photo.url(:thumb_large)
params[:image_url_medium] = params[:photo].url(:thumb_medium) params[:image_url_medium] = photo.url(:thumb_medium)
params[:image_url_small] = params[:photo].url(:thumb_small) params[:image_url_small] = photo.url(:thumb_small)
end end
if self.person.profile.update_attributes(params) if self.person.profile.update_attributes(params)
push_to_people profile, contacts.includes(:person).where(:pending => false).map{|c| c.person} push_to_people profile, contacts.includes(:person).where(:pending => false).map{|c| c.person}

View file

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

View file

@ -62,7 +62,8 @@ module Diaspora
end end
def request_from(person) def request_from(person)
Request.where(:sender_id => person.id, :recipient_id => self.person.id).first Request.where(:sender_id => person.id,
:recipient_id => self.person.id).first
end end
def posts_from(person) def posts_from(person)

View file

@ -135,9 +135,8 @@ describe Comment do
end end
it 'should send a comment a user made on your post to all people' do it 'should send a comment a user made on your post to all people' do
comment = user2.comment( "balls", :on => @user_status)
MessageHandler.should_receive(:add_post_request).once MessageHandler.should_receive(:add_post_request).once
user.receive comment.to_diaspora_xml, user2.person comment = user2.comment( "balls", :on => @user_status)
end end
context 'posts from a remote person' do context 'posts from a remote person' do

View file

@ -193,7 +193,7 @@ describe Person do
end end
it 'should only display searchable people' do it 'should only display searchable people' do
invisible_person = Factory(:person, :profile => {:searchable => false, :first_name => "johnson"}) invisible_person = Factory(:person, :profile => Factory(:profile,:searchable => false, :first_name => "johnson"))
Person.search("johnson").should_not include invisible_person Person.search("johnson").should_not include invisible_person
Person.search("").should_not include invisible_person Person.search("").should_not include invisible_person
end end

View file

@ -36,15 +36,4 @@ describe Post do
post.mutable?.should == false post.mutable?.should == false
end end
end end
describe '#decrement_user_refs' do
before do
@post = @user.post :status_message, :message => "hello", :to => @aspect.id
end
it 'decrements user_refs' do
lambda {
@post.decrement_user_refs
}.should change(@post, :user_refs).by(-1)
end
end
end end

View file

@ -43,6 +43,10 @@ describe Diaspora::UserModules::Connecting do
user.send_contact_request_to(user2.person, aspect1) user.send_contact_request_to(user2.person, aspect1)
}.should_not change{Request.where(:recipient_id => user.person.id).count} }.should_not change{Request.where(:recipient_id => user.person.id).count}
end end
it 'persists a request for the recipient' do
user.send_contact_request_to(user2.person, aspect1)
user2.request_from(user.person).should_not be_nil
end
end end
context 'contact requesting' do context 'contact requesting' do

View file

@ -206,7 +206,7 @@ describe User do
it 'should have a pending request after sending a request' do it 'should have a pending request after sending a request' do
@user.send_contact_request_to(user5.person, @user.aspects.first) @user.send_contact_request_to(user5.person, @user.aspects.first)
request = @user.reload.request_from(user5.person) request = user5.request_from(@user.person)
request.should_not be_nil request.should_not be_nil
end end
end end

View file

@ -99,8 +99,6 @@ describe User do
person = user2.person person = user2.person
person.owner_id = nil person.owner_id = nil
person.save person.save
@status_message.user_refs = 1
@status_message.save
lambda { lambda {
user.disconnected_by(user2.person) user.disconnected_by(user2.person)
@ -109,23 +107,23 @@ describe User do
it 'should keep track of user references for one person ' do it 'should keep track of user references for one person ' do
@status_message.reload @status_message.reload
@status_message.user_refs.should == 1 @status_message.user_refs.should == 2
user.disconnect(user2.person) user.disconnect(user2.person)
@status_message.reload @status_message.reload
@status_message.user_refs.should == 0 @status_message.user_refs.should == 1
end end
it 'should not override userrefs on receive by another person' do it 'should not override userrefs on receive by another person' do
user3.activate_contact(user2.person, aspect3) user3.activate_contact(user2.person, aspect3)
user3.receive @status_message.to_diaspora_xml, user2.person user3.receive @status_message.to_diaspora_xml, user2.person
@status_message.reload @status_message.post_visibilities.reset
@status_message.user_refs.should == 2 @status_message.user_refs.should == 3
user.disconnect(user2.person) user.disconnect(user2.person)
@status_message.reload @status_message.post_visibilities.reset
@status_message.user_refs.should == 1 @status_message.user_refs.should == 2
end end
end end