Fix some more specs, aspects controller is green in mysql

This commit is contained in:
Raphael 2010-12-22 14:15:45 -08:00
parent baf0533466
commit 55492535c6
6 changed files with 48 additions and 40 deletions

View file

@ -15,6 +15,8 @@ class Aspect < ActiveRecord::Base
validates_length_of :name, :maximum => 20 validates_length_of :name, :maximum => 20
validates_uniqueness_of :name, :scope => :user_id validates_uniqueness_of :name, :scope => :user_id
attr_accessible :name
before_validation do before_validation do
name.strip! name.strip!
end end

View file

@ -42,7 +42,8 @@ class Person < ActiveRecord::Base
query_tokens = query.to_s.strip.split(" ") query_tokens = query.to_s.strip.split(" ")
p = [] p = []
query_tokens.each do |token| query_tokens.each do |raw_token|
token = "%#{raw_token}%"
p = Person.searchable.where('profiles.first_name LIKE :token', :token => token).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.last_name LIKE :token', :token => token).limit(30) \
| Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \ | Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \

View file

@ -88,7 +88,9 @@ module Diaspora
visibility_ids = visibilities.map{|v| v.id} visibility_ids = visibilities.map{|v| v.id}
PostVisibility.where(:id => visibility_ids).delete_all PostVisibility.where(:id => visibility_ids).delete_all
posts.each do |post| posts.each do |post|
post.decrement_user_refs if post.user_refs == 0
post.destroy
end
end end
raise "Contact not deleted" unless contact.destroy raise "Contact not deleted" unless contact.destroy
end end

View file

@ -23,10 +23,9 @@ module Diaspora
def receive xml, salmon_author def receive xml, salmon_author
object = Diaspora::Parser.from_xml(xml) object = Diaspora::Parser.from_xml(xml)
Rails.logger.info("event=receive status=start recipient=#{self.diaspora_handle} payload_type=#{object.class} sender=#{salmon_author.diaspora_handle}") Rails.logger.info("event=receive status=start recipient=#{self.diaspora_handle} payload_type=#{object.class} sender=#{salmon_author.diaspora_handle}")
if object.is_a?(Request) if object.is_a?(Request)
salmon_author.save salmon_author.save!
object.sender_handle = salmon_author.diaspora_handle object.sender = salmon_author
end end
if object.is_a?(Comment) if object.is_a?(Comment)

View file

@ -27,9 +27,8 @@ describe AspectsController do
describe "#index" do describe "#index" do
it "assigns @contacts to all the user's contacts" do it "assigns @contacts to all the user's contacts" do
Factory.create :person
get :index get :index
assigns[:contacts].should == @user.contacts assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id}
end end
context 'performance' do context 'performance' do
before do before do

View file

@ -5,83 +5,88 @@
require 'spec_helper' require 'spec_helper'
describe Diaspora::Parser do describe Diaspora::Parser do
let(:user) { Factory.create(:user) } before do
let(:aspect) { user.aspects.create(:name => 'spies') } @user = Factory.create(:user)
let(:user2) { Factory.create(:user) } @aspect = @user.aspects.create(:name => 'spies')
let(:aspect2) { user2.aspects.create(:name => "pandas") } @user2 = Factory.create(:user)
let(:person) { Factory.create(:person)} @aspect2 = @user2.aspects.create(:name => "pandas")
@person = Factory.create(:person)
end
describe "parsing compliant XML object" do describe "parsing compliant XML object" do
it 'should be able to correctly parse comment fields' do it 'should be able to correctly parse comment fields' do
post = user.post :status_message, :message => "hello", :to => aspect.id post = @user.post :status_message, :message => "hello", :to => @aspect.id
comment = Factory.create(:comment, :post => post, :person => person, :diaspora_handle => person.diaspora_handle, :text => "Freedom!") comment = Factory.create(:comment, :post => post, :person => @person, :diaspora_handle => @person.diaspora_handle, :text => "Freedom!")
comment.delete comment.delete
xml = comment.to_diaspora_xml xml = comment.to_diaspora_xml
comment_from_xml = Diaspora::Parser.from_xml(xml) comment_from_xml = Diaspora::Parser.from_xml(xml)
comment_from_xml.diaspora_handle.should == person.diaspora_handle comment_from_xml.diaspora_handle.should == @person.diaspora_handle
comment_from_xml.post.should == post comment_from_xml.post.should == post
comment_from_xml.text.should == "Freedom!" comment_from_xml.text.should == "Freedom!"
comment_from_xml.should_not be comment comment_from_xml.should_not be comment
end end
it 'should accept retractions' do it 'should accept retractions' do
connect_users(user, aspect, user2, aspect2) connect_users(@user, @aspect, @user2, @aspect2)
message = user2.post(:status_message, :message => "cats", :to => aspect2.id) message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
retraction = Retraction.for(message) retraction = Retraction.for(message)
xml = retraction.to_diaspora_xml xml = retraction.to_diaspora_xml
lambda { lambda {
user.receive xml, user2.person @user.receive xml, @user2.person
}.should change(StatusMessage, :count).by(-1) }.should change(StatusMessage, :count).by(-1)
end end
context "connecting" do context "connecting" do
let(:good_request) { FakeHttpRequest.new(:success)} let(:good_request) { FakeHttpRequest.new(:success)}
it "should create a new person upon getting a person request" do it "should create a new person upon getting a person request" do
remote_user = Factory.create(:user) new_person = @user2.person
new_person = remote_user.person
request = Request.new(:recipient =>@user.person, :sender => @user2.person)
xml = @user2.salmon(request).xml_for(@user.person)
request = Request.new(:recipient =>user.person, :sender => new_person)
xml = remote_user.salmon(request).xml_for(user.person)
request.delete request.delete
request.sender.delete request.sender.delete
remote_user.delete @user2.delete
new_person.delete new_person.delete
new_person.profile.delete
new_person = new_person.dup
new_person.id = nil
new_person.owner_id = nil
Person.should_receive(:by_account_identifier).twice.and_return(new_person) Person.should_receive(:by_account_identifier).twice.and_return(new_person)
lambda { lambda {
user.receive_salmon xml @user.receive_salmon xml
}.should change(Person, :count).by(1) }.should change(Person, :count).by(1)
end end
end end
it "should activate the Person if I initiated a request to that url" do it "should activate the Person if I initiated a request to that url" do
user.send_contact_request_to(user2.person, aspect) @user.send_contact_request_to(@user2.person, @aspect)
request = Request.where(:recipient_id => user2.person.id, :sender_id => user.id).first request = @user2.request_from(@user.person)
fantasy_resque do fantasy_resque do
user2.accept_and_respond(request.id, aspect2.id) @user2.accept_and_respond(request.id, @aspect2.id)
end end
user.reload @user.reload
aspect.reload @aspect.reload
new_contact = user.contact_for(user2.person) new_contact = @user.contact_for(@user2.person)
aspect.contacts.include?(new_contact).should be true @aspect.contacts.include?(new_contact).should be true
user.contacts.include?(new_contact).should be true @user.contacts.include?(new_contact).should be true
end end
it 'should process retraction for a person' do it 'should process retraction for a person' do
connect_users(user, aspect, user2, aspect2) connect_users(@user, @aspect, @user2, @aspect2)
retraction = Retraction.for(user2) retraction = Retraction.for(@user2)
retraction_xml = retraction.to_diaspora_xml retraction_xml = retraction.to_diaspora_xml
lambda { user.receive retraction_xml, user2.person }.should change { lambda { @user.receive retraction_xml, @user2.person }.should change {
aspect.reload.contacts.size }.by(-1) @aspect.reload.contacts.size }.by(-1)
end end
it 'should marshal a profile for a person' do it 'should marshal a profile for a person' do
connect_users(user, aspect, user2, aspect2) connect_users(@user, @aspect, @user2, @aspect2)
#Create person #Create person
person = user2.person person = @user2.person
id = person.id id = person.id
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com") person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
person.save person.save
@ -101,7 +106,7 @@ describe Diaspora::Parser do
old_profile.first_name.should == 'bob' old_profile.first_name.should == 'bob'
#Marshal profile #Marshal profile
user.receive xml, person @user.receive xml, person
#Check that marshaled profile is the same as old profile #Check that marshaled profile is the same as old profile
person = Person.find(person.id) person = Person.find(person.id)