Fix some more specs, aspects controller is green in mysql
This commit is contained in:
parent
baf0533466
commit
55492535c6
6 changed files with 48 additions and 40 deletions
|
|
@ -15,6 +15,8 @@ class Aspect < ActiveRecord::Base
|
|||
validates_length_of :name, :maximum => 20
|
||||
validates_uniqueness_of :name, :scope => :user_id
|
||||
|
||||
attr_accessible :name
|
||||
|
||||
before_validation do
|
||||
name.strip!
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ class Person < ActiveRecord::Base
|
|||
query_tokens = query.to_s.strip.split(" ")
|
||||
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) \
|
||||
| Person.searchable.where('profiles.last_name LIKE :token', :token => token).limit(30) \
|
||||
| Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \
|
||||
|
|
|
|||
|
|
@ -88,7 +88,9 @@ module Diaspora
|
|||
visibility_ids = visibilities.map{|v| v.id}
|
||||
PostVisibility.where(:id => visibility_ids).delete_all
|
||||
posts.each do |post|
|
||||
post.decrement_user_refs
|
||||
if post.user_refs == 0
|
||||
post.destroy
|
||||
end
|
||||
end
|
||||
raise "Contact not deleted" unless contact.destroy
|
||||
end
|
||||
|
|
|
|||
|
|
@ -23,10 +23,9 @@ module Diaspora
|
|||
def receive xml, salmon_author
|
||||
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}")
|
||||
|
||||
if object.is_a?(Request)
|
||||
salmon_author.save
|
||||
object.sender_handle = salmon_author.diaspora_handle
|
||||
salmon_author.save!
|
||||
object.sender = salmon_author
|
||||
end
|
||||
|
||||
if object.is_a?(Comment)
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@ describe AspectsController do
|
|||
|
||||
describe "#index" do
|
||||
it "assigns @contacts to all the user's contacts" do
|
||||
Factory.create :person
|
||||
get :index
|
||||
assigns[:contacts].should == @user.contacts
|
||||
assigns[:contacts].map{|c| c.id}.should == @user.contacts.map{|c| c.id}
|
||||
end
|
||||
context 'performance' do
|
||||
before do
|
||||
|
|
|
|||
|
|
@ -5,83 +5,88 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Diaspora::Parser do
|
||||
let(:user) { Factory.create(:user) }
|
||||
let(:aspect) { user.aspects.create(:name => 'spies') }
|
||||
let(:user2) { Factory.create(:user) }
|
||||
let(:aspect2) { user2.aspects.create(:name => "pandas") }
|
||||
let(:person) { Factory.create(:person)}
|
||||
|
||||
before do
|
||||
@user = Factory.create(:user)
|
||||
@aspect = @user.aspects.create(:name => 'spies')
|
||||
@user2 = Factory.create(:user)
|
||||
@aspect2 = @user2.aspects.create(:name => "pandas")
|
||||
@person = Factory.create(:person)
|
||||
end
|
||||
describe "parsing compliant XML object" do
|
||||
it 'should be able to correctly parse comment fields' do
|
||||
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!")
|
||||
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.delete
|
||||
xml = comment.to_diaspora_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.text.should == "Freedom!"
|
||||
comment_from_xml.should_not be comment
|
||||
end
|
||||
|
||||
it 'should accept retractions' do
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
message = user2.post(:status_message, :message => "cats", :to => aspect2.id)
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
message = @user2.post(:status_message, :message => "cats", :to => @aspect2.id)
|
||||
retraction = Retraction.for(message)
|
||||
xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda {
|
||||
user.receive xml, user2.person
|
||||
@user.receive xml, @user2.person
|
||||
}.should change(StatusMessage, :count).by(-1)
|
||||
end
|
||||
|
||||
context "connecting" do
|
||||
let(:good_request) { FakeHttpRequest.new(:success)}
|
||||
it "should create a new person upon getting a person request" do
|
||||
remote_user = Factory.create(:user)
|
||||
new_person = remote_user.person
|
||||
new_person = @user2.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.sender.delete
|
||||
remote_user.delete
|
||||
@user2.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)
|
||||
|
||||
lambda {
|
||||
user.receive_salmon xml
|
||||
@user.receive_salmon xml
|
||||
}.should change(Person, :count).by(1)
|
||||
end
|
||||
end
|
||||
|
||||
it "should activate the Person if I initiated a request to that url" do
|
||||
user.send_contact_request_to(user2.person, aspect)
|
||||
request = Request.where(:recipient_id => user2.person.id, :sender_id => user.id).first
|
||||
@user.send_contact_request_to(@user2.person, @aspect)
|
||||
request = @user2.request_from(@user.person)
|
||||
fantasy_resque do
|
||||
user2.accept_and_respond(request.id, aspect2.id)
|
||||
@user2.accept_and_respond(request.id, @aspect2.id)
|
||||
end
|
||||
user.reload
|
||||
aspect.reload
|
||||
new_contact = user.contact_for(user2.person)
|
||||
aspect.contacts.include?(new_contact).should be true
|
||||
user.contacts.include?(new_contact).should be true
|
||||
@user.reload
|
||||
@aspect.reload
|
||||
new_contact = @user.contact_for(@user2.person)
|
||||
@aspect.contacts.include?(new_contact).should be true
|
||||
@user.contacts.include?(new_contact).should be true
|
||||
end
|
||||
|
||||
it 'should process retraction for a person' do
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
retraction = Retraction.for(user2)
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
retraction = Retraction.for(@user2)
|
||||
retraction_xml = retraction.to_diaspora_xml
|
||||
|
||||
lambda { user.receive retraction_xml, user2.person }.should change {
|
||||
aspect.reload.contacts.size }.by(-1)
|
||||
lambda { @user.receive retraction_xml, @user2.person }.should change {
|
||||
@aspect.reload.contacts.size }.by(-1)
|
||||
end
|
||||
|
||||
it 'should marshal a profile for a person' do
|
||||
connect_users(user, aspect, user2, aspect2)
|
||||
connect_users(@user, @aspect, @user2, @aspect2)
|
||||
#Create person
|
||||
person = user2.person
|
||||
person = @user2.person
|
||||
id = person.id
|
||||
person.profile = Profile.new(:first_name => 'bob', :last_name => 'billytown', :image_url => "http://clown.com")
|
||||
person.save
|
||||
|
|
@ -101,7 +106,7 @@ describe Diaspora::Parser do
|
|||
old_profile.first_name.should == 'bob'
|
||||
|
||||
#Marshal profile
|
||||
user.receive xml, person
|
||||
@user.receive xml, person
|
||||
|
||||
#Check that marshaled profile is the same as old profile
|
||||
person = Person.find(person.id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue