logical failures on person spec, 25 failing model specs
This commit is contained in:
parent
cbda6b8c58
commit
baf0533466
13 changed files with 30 additions and 50 deletions
|
|
@ -63,7 +63,7 @@ module SocketsHelper
|
|||
|
||||
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?
|
||||
|
||||
|
|
|
|||
|
|
@ -35,20 +35,17 @@ class Person < ActiveRecord::Base
|
|||
validates_presence_of :url, :profile, :serialized_public_key
|
||||
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)
|
||||
return [] if query.to_s.empty?
|
||||
query_tokens = query.to_s.strip.split(" ")
|
||||
full_query_text = Regexp.escape(query.to_s.strip)
|
||||
|
||||
p = []
|
||||
|
||||
query_tokens.each do |token|
|
||||
q = Regexp.escape(token.to_s.strip)
|
||||
p = Person.searchable.all('profile.first_name' => /^#{q}/i, 'limit' => 30) \
|
||||
| Person.searchable.all('profile.last_name' => /^#{q}/i, 'limit' => 30) \
|
||||
| Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \
|
||||
p = Person.searchable.where('profiles.first_name LIKE :token', :token => token).limit(30) \
|
||||
| Person.searchable.where('profiles.last_name LIKE :token', :token => token).limit(30) \
|
||||
| Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \
|
||||
| p
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ class Post < ActiveRecord::Base
|
|||
before_destroy :propogate_retraction
|
||||
after_destroy :destroy_comments
|
||||
|
||||
attr_accessible :user_refs
|
||||
def user_refs
|
||||
self.post_visibilities.count
|
||||
end
|
||||
|
||||
def self.diaspora_initialize params
|
||||
new_post = self.new params.to_hash
|
||||
|
|
@ -52,15 +54,6 @@ class Post < ActiveRecord::Base
|
|||
false
|
||||
end
|
||||
|
||||
def decrement_user_refs
|
||||
user_refs -= 1
|
||||
if (user_refs > 0) || person.owner.nil? == false
|
||||
save
|
||||
else
|
||||
destroy
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def destroy_comments
|
||||
comments.each { |c| c.destroy }
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class Profile < ActiveRecord::Base
|
|||
validates_length_of :first_name, :maximum => 32
|
||||
validates_length_of :last_name, :maximum => 32
|
||||
|
||||
# attr_accessible :first_name, :last_name, :image_url, :image_url_medium,
|
||||
# :image_url_small, :birthday, :gender, :bio, :searchable, :date
|
||||
attr_accessible :first_name, :last_name, :image_url, :image_url_medium,
|
||||
:image_url_small, :birthday, :gender, :bio, :searchable, :date
|
||||
|
||||
belongs_to :person
|
||||
|
||||
|
|
|
|||
|
|
@ -263,11 +263,11 @@ class User < ActiveRecord::Base
|
|||
|
||||
########### Profile ######################
|
||||
def update_profile(params)
|
||||
if params[:photo]
|
||||
params[:photo].update_attributes(:pending => false) if params[:photo].pending
|
||||
params[:image_url] = params[:photo].url(:thumb_large)
|
||||
params[:image_url_medium] = params[:photo].url(:thumb_medium)
|
||||
params[:image_url_small] = params[:photo].url(:thumb_small)
|
||||
if photo = params.delete(:photo)
|
||||
photo.update_attributes(:pending => false) if photo.pending
|
||||
params[:image_url] = photo.url(:thumb_large)
|
||||
params[:image_url_medium] = photo.url(:thumb_medium)
|
||||
params[:image_url_small] = photo.url(:thumb_small)
|
||||
end
|
||||
if self.person.profile.update_attributes(params)
|
||||
push_to_people profile, contacts.includes(:person).where(:pending => false).map{|c| c.person}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ class CreateSchema < ActiveRecord::Migration
|
|||
t.string :diaspora_handle
|
||||
t.string :guid
|
||||
t.boolean :pending, :default => false
|
||||
t.integer :user_refs, :default => 0
|
||||
t.string :type
|
||||
|
||||
t.text :message
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ module Diaspora
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def posts_from(person)
|
||||
|
|
|
|||
|
|
@ -135,9 +135,8 @@ describe Comment do
|
|||
end
|
||||
|
||||
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
|
||||
user.receive comment.to_diaspora_xml, user2.person
|
||||
comment = user2.comment( "balls", :on => @user_status)
|
||||
end
|
||||
|
||||
context 'posts from a remote person' do
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ describe Person do
|
|||
end
|
||||
|
||||
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("").should_not include invisible_person
|
||||
end
|
||||
|
|
|
|||
|
|
@ -36,15 +36,4 @@ describe Post do
|
|||
post.mutable?.should == false
|
||||
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
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ describe Diaspora::UserModules::Connecting do
|
|||
user.send_contact_request_to(user2.person, aspect1)
|
||||
}.should_not change{Request.where(:recipient_id => user.person.id).count}
|
||||
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
|
||||
|
||||
context 'contact requesting' do
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ describe User do
|
|||
|
||||
it 'should have a pending request after sending a request' do
|
||||
@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
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -99,8 +99,6 @@ describe User do
|
|||
person = user2.person
|
||||
person.owner_id = nil
|
||||
person.save
|
||||
@status_message.user_refs = 1
|
||||
@status_message.save
|
||||
|
||||
lambda {
|
||||
user.disconnected_by(user2.person)
|
||||
|
|
@ -109,23 +107,23 @@ describe User do
|
|||
|
||||
it 'should keep track of user references for one person ' do
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 1
|
||||
@status_message.user_refs.should == 2
|
||||
|
||||
user.disconnect(user2.person)
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 0
|
||||
@status_message.user_refs.should == 1
|
||||
end
|
||||
|
||||
it 'should not override userrefs on receive by another person' do
|
||||
user3.activate_contact(user2.person, aspect3)
|
||||
user3.receive @status_message.to_diaspora_xml, user2.person
|
||||
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 2
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 3
|
||||
|
||||
user.disconnect(user2.person)
|
||||
@status_message.reload
|
||||
@status_message.user_refs.should == 1
|
||||
@status_message.post_visibilities.reset
|
||||
@status_message.user_refs.should == 2
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue