moving to not including the post in the reshare xml
This commit is contained in:
parent
7b3180e5da
commit
509a435cc9
4 changed files with 91 additions and 2 deletions
|
|
@ -66,7 +66,7 @@ class PublicsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def post
|
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
|
#hax to upgrade logged in users who can comment
|
||||||
if @post
|
if @post
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,32 @@ class Reshare < Post
|
||||||
validate :root_must_be_public
|
validate :root_must_be_public
|
||||||
attr_accessible :root_id, :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
|
before_validation do
|
||||||
self.public = true
|
self.public = true
|
||||||
end
|
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)
|
def receive(user, person)
|
||||||
local_reshare = Reshare.where(:guid => self.guid).first
|
local_reshare = Reshare.where(:guid => self.guid).first
|
||||||
if local_reshare.root.author_id == user.person.id
|
if local_reshare.root.author_id == user.person.id
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do
|
||||||
resources :likes, :only => [:create, :destroy, :index]
|
resources :likes, :only => [:create, :destroy, :index]
|
||||||
resources :comments, :only => [:create, :destroy, :index]
|
resources :comments, :only => [:create, :destroy, :index]
|
||||||
end
|
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
|
# roll up likes into a nested resource above
|
||||||
resources :comments, :only => [:create, :destroy] do
|
resources :comments, :only => [:create, :destroy] do
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Reshare do
|
describe Reshare do
|
||||||
|
include ActionView::Helpers::UrlHelper
|
||||||
|
include Rails.application.routes.url_helpers
|
||||||
|
def controller
|
||||||
|
mock()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
it 'has a valid Factory' do
|
it 'has a valid Factory' do
|
||||||
Factory(:reshare).should be_valid
|
Factory(:reshare).should be_valid
|
||||||
end
|
end
|
||||||
|
|
@ -33,4 +40,64 @@ describe Reshare do
|
||||||
@root.resharers.should include(@reshare.author)
|
@root.resharers.should include(@reshare.author)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue