diff --git a/app/models/comment.rb b/app/models/comment.rb index d3920564c..1a468a581 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,11 +10,11 @@ class Comment < ActiveRecord::Base include Diaspora::Webhooks include Encryptable include Diaspora::Socketable + include Diaspora::Guid xml_attr :text xml_accessor :diaspora_handle xml_accessor :post_guid - xml_attr :guid belongs_to :post belongs_to :person @@ -34,7 +34,7 @@ class Comment < ActiveRecord::Base post.guid end def post_guid= new_post_guid - post = Post.where(:guid => new_post_guid).first + self.post = Post.where(:guid => new_post_guid).first end def notification_type(user, person) diff --git a/app/models/contact.rb b/app/models/contact.rb index 564f9f944..f9ce23885 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -13,7 +13,7 @@ class Contact < ActiveRecord::Base has_many :aspects, :through => :aspect_memberships validate :not_contact_for_self validates_uniqueness_of :person_id, :scope => :user_id - + def dispatch_request request = self.generate_request self.user.push_to_people(request, [self.person]) @@ -21,7 +21,9 @@ class Contact < ActiveRecord::Base end def generate_request - Request.new(:sender => self.user.person, :recipient => self.person) + Request.new(:sender => self.user.person, + :recipient => self.person, + :aspect => aspects.first) end private diff --git a/app/models/person.rb b/app/models/person.rb index af3c6a603..9716a3581 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -9,8 +9,8 @@ class Person < ActiveRecord::Base include Encryptor::Public require File.join(Rails.root, 'lib/diaspora/web_socket') include Diaspora::Socketable + include Diaspora::Guid - xml_attr :guid xml_attr :diaspora_handle xml_attr :url xml_attr :profile, :as => Profile diff --git a/app/models/post.rb b/app/models/post.rb index 34f4b8dc7..659639272 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -8,8 +8,8 @@ class Post < ActiveRecord::Base include ApplicationHelper include ROXML include Diaspora::Webhooks + include Diaspora::Guid - xml_attr :guid xml_attr :diaspora_handle xml_attr :public xml_attr :created_at diff --git a/app/models/request.rb b/app/models/request.rb index 16195ada3..e23a715c1 100644 --- a/app/models/request.rb +++ b/app/models/request.rb @@ -8,8 +8,8 @@ class Request < ActiveRecord::Base include Diaspora::Webhooks include ROXML - xml_attr :sender_handle - xml_attr :recipient_handle + xml_accessor :sender_handle + xml_accessor :recipient_handle belongs_to :sender, :class_name => 'Person' belongs_to :recipient, :class_name => 'Person' diff --git a/db/schema.rb b/db/schema.rb index 7108f3282..ecb16a236 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -124,6 +124,7 @@ ActiveRecord::Schema.define(:version => 0) do t.datetime "updated_at" end + add_index "posts", ["guid"], :name => "index_posts_on_guid" add_index "posts", ["person_id"], :name => "index_posts_on_person_id" add_index "posts", ["type"], :name => "index_posts_on_type" diff --git a/lib/diaspora/exporter.rb b/lib/diaspora/exporter.rb index 9fcc5fb45..f18151413 100644 --- a/lib/diaspora/exporter.rb +++ b/lib/diaspora/exporter.rb @@ -18,8 +18,8 @@ module Diaspora xml.export { xml.user { xml.username user.username - xml.serialized_private_key user.serialized_private_key - + xml.serialized_private_key user.serialized_private_key + xml.parent << user.person.to_xml } @@ -27,9 +27,9 @@ module Diaspora xml.aspects { user.aspects.each do |aspect| - xml.aspect { + xml.aspect { xml.name aspect.name - + # xml.person_ids { #aspect.person_ids.each do |id| #xml.person_id id @@ -47,9 +47,10 @@ module Diaspora xml.contacts { user.contacts.each do |contact| - xml.contact { + xml.contact { xml.user_id contact.user_id xml.person_id contact.person_id + xml.person_guid contact.person.guid xml.aspects { contact.aspects.each do |aspect| @@ -71,7 +72,7 @@ module Diaspora xml.parent << post.to_xml end } - + xml.people { user.contacts.each do |contact| person = contact.person diff --git a/lib/diaspora/guid.rb b/lib/diaspora/guid.rb new file mode 100644 index 000000000..728752434 --- /dev/null +++ b/lib/diaspora/guid.rb @@ -0,0 +1,11 @@ +module Diaspora::Guid + def self.included(model) + model.class_eval do + before_create :set_guid + xml_attr :guid + end + end + def set_guid + self.guid ||= ActiveSupport::SecureRandom.hex(8) + end +end diff --git a/spec/lib/diaspora/exporter_spec.rb b/spec/lib/diaspora/exporter_spec.rb index 8bd3b9c14..a3d3981ff 100644 --- a/spec/lib/diaspora/exporter_spec.rb +++ b/spec/lib/diaspora/exporter_spec.rb @@ -103,7 +103,8 @@ describe Diaspora::Exporter do it 'should include post created at time' do doc = Nokogiri::XML::parse(posts_xml) - Time.parse(doc.xpath('//posts/status_message/created_at').first.text).should == @status_message1.created_at + xml_time = Time.zone.parse(doc.xpath('//posts/status_message/created_at').first.text) + xml_time.to_i.should == @status_message1.created_at.to_i end end end diff --git a/spec/lib/diaspora/parser_spec.rb b/spec/lib/diaspora/parser_spec.rb index 38a8e6351..53b5b56ba 100644 --- a/spec/lib/diaspora/parser_spec.rb +++ b/spec/lib/diaspora/parser_spec.rb @@ -30,12 +30,13 @@ describe Diaspora::Parser do retraction = Retraction.for(message) xml = retraction.to_diaspora_xml - proc { user.receive xml, user2.person }.should change(StatusMessage, :count).by(-1) + lambda { + user.receive xml, user2.person + }.should change(StatusMessage, :count).by(-1) end 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 remote_user = Factory.create(:user) new_person = remote_user.person @@ -53,8 +54,6 @@ describe Diaspora::Parser do 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 diff --git a/spec/models/invitation_spec.rb b/spec/models/invitation_spec.rb index 33e8680de..c16763270 100644 --- a/spec/models/invitation_spec.rb +++ b/spec/models/invitation_spec.rb @@ -9,6 +9,8 @@ describe Invitation do let!(:aspect) {user.aspects.create(:name => "Invitees")} let(:user2) {Factory.create(:user)} before do + user.invites = 20 + user.save @email = 'maggie@example.com' Devise.mailer.deliveries = [] end diff --git a/spec/models/user/invite_spec.rb b/spec/models/user/invite_spec.rb index 26aea5bc4..0e120e6b2 100644 --- a/spec/models/user/invite_spec.rb +++ b/spec/models/user/invite_spec.rb @@ -14,7 +14,9 @@ describe User do context "creating invites" do it 'requires your aspect' do - inviter.invite_user("maggie@example.com", wrong_aspect.id).should raise_error ActiveRecord::RecordNotFound + lambda { + inviter.invite_user("maggie@example.com", wrong_aspect.id) + }.should raise_error ActiveRecord::RecordNotFound end it 'calls Invitation.invite' do