moving to not including the post in the reshare xml

This commit is contained in:
danielgrippi 2011-07-13 19:40:08 -07:00 committed by Raphael Sofaer
parent 7b3180e5da
commit 509a435cc9
4 changed files with 91 additions and 2 deletions

View file

@ -66,7 +66,7 @@ class PublicsController < ApplicationController
end
def post
@post = Post.where(:id => params[:id], :public => true).includes(:author, :comments => :author).first
@post = Post.where(:guid => params[:guid], :public => true).includes(:author, :comments => :author).first
#hax to upgrade logged in users who can comment
if @post

View file

@ -3,10 +3,32 @@ class Reshare < Post
validate :root_must_be_public
attr_accessible :root_id, :public
xml_attr :root_diaspora_id
xml_attr :root_guid
attr_accessible :root_diaspora_id, :root_guid
before_validation do
self.public = true
end
def root_guid
self.root.guid
end
def root_guid= rg
#self.root = Post.where(:guid => rg).first
debugger
person = Person.where(:diaspora_handle => self[:root_diaspora_id]).first
Faraday.get(person.url + public_post_path(:guid => rg))
end
def root_diaspora_id
self.root.author.diaspora_handle
end
def root_diaspora_id= id
Webfinger.new(id).fetch
end
def receive(user, person)
local_reshare = Reshare.where(:guid => self.guid).first
if local_reshare.root.author_id == user.person.id

View file

@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do
resources :likes, :only => [:create, :destroy, :index]
resources :comments, :only => [:create, :destroy, :index]
end
get 'p/:id' => 'publics#post', :as => 'public_post'
get 'p/:guid' => 'publics#post', :as => 'public_post'
# roll up likes into a nested resource above
resources :comments, :only => [:create, :destroy] do

View file

@ -1,6 +1,13 @@
require 'spec_helper'
describe Reshare do
include ActionView::Helpers::UrlHelper
include Rails.application.routes.url_helpers
def controller
mock()
end
it 'has a valid Factory' do
Factory(:reshare).should be_valid
end
@ -33,4 +40,64 @@ describe Reshare do
@root.resharers.should include(@reshare.author)
end
end
describe "XML" do
before do
@reshare = Factory(:reshare)
@xml = @reshare.to_xml.to_s
pp @xml
end
context 'serialization' do
it 'serializes root_diaspora_id' do
@xml.should include("root_diaspora_id")
end
it 'serializes root_guid' do
@xml.should include("root_guid")
end
end
context 'marshalling' do
context 'local' do
before do
@original_author = @reshare.root.author.dup
@root_object = @reshare.root.dup
end
it 'fetches the root post from root_guid' do
Reshare.from_xml(@xml).root.should == @root_object
end
it 'fetches the root author from root_diaspora_id' do
Reshare.from_xml(@xml).root.author.should == @original_author
end
end
context 'remote' do
before do
@original_profile = @reshare.root.author.profile
@original_author = @reshare.root.author.delete
@root_object = @reshare.root.delete
end
it 'fetches the root post from root_guid' do
@original_profile.save!
pp @original_profile
@original_author.save!
pp @original_author
Faraday.should_receive(:get).with(@original_author.url + public_post_path(:guid => @reshare.guid)).and_return(@root_object.to_diaspora_xml)
Reshare.from_xml(@xml).root.should == @root_object
end
it 'fetches the root author from root_diaspora_id' do
person = Factory.build(:person)
wf_prof_mock = mock
wf_prof_mock.should_receive(:fetch).and_return(person)
Webfinger.should_receive(:new).and_return(wf_prof_mock)
Reshare.from_xml(@xml)
end
end
end
end
end