From a32ef3c1d803f09b82f91a46bc9ca69091df718b Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Thu, 14 Jul 2011 15:56:55 -0700 Subject: [PATCH] added xml response to the post --- app/controllers/publics_controller.rb | 26 +++++++++++++-------- app/models/reshare.rb | 2 +- spec/controllers/publics_controller_spec.rb | 6 +++++ spec/models/reshare_spec.rb | 4 ++-- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index c58b7f917..e0e3941e2 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -12,6 +12,9 @@ class PublicsController < ApplicationController skip_before_filter :set_grammatical_gender before_filter :allow_cross_origin, :only => [:hcard, :host_meta, :webfinger] + respond_to :html + respond_to :xml, :only => :post + def allow_cross_origin headers["Access-Control-Allow-Origin"] = "*" end @@ -77,17 +80,20 @@ class PublicsController < ApplicationController if @post if user_signed_in? && current_user.find_visible_post_by_id(@post.id) redirect_to post_path(@post) - return - end - - @landing_page = true - @person = @post.author - if @person.owner_id - I18n.locale = @person.owner.language - render "#{@post.class.to_s.underscore}", :layout => 'application' else - flash[:error] = I18n.t('posts.show.not_found') - redirect_to root_url + @landing_page = true + @person = @post.author + if @person.owner_id + I18n.locale = @person.owner.language + + respond_to do |format| + format.all{ render "#{@post.class.to_s.underscore}", :layout => 'application'} + format.xml{ render :xml => @post.to_diaspora_xml } + end + else + flash[:error] = I18n.t('posts.show.not_found') + redirect_to root_url + end end else flash[:error] = I18n.t('posts.show.not_found') diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 8eb0303d7..9b80ba533 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -40,7 +40,7 @@ class Reshare < Post root_author.save! unless self.root = Post.where(:guid => @root_guid).first - self.root = Diaspora::Parser.from_xml(Faraday.get(root_author.url + "/p/#{@root_guid}").body) + self.root = Diaspora::Parser.from_xml(Faraday.get(root_author.url + "/p/#{@root_guid}.xml").body) self.root.save! end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 8f55400fc..b99c0be69 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -82,6 +82,12 @@ describe PublicsController do response.should be_redirect end + it 'responds with diaspora xml if format is xml' do + status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all') + get :post, :guid => status.guid, :format => :xml + response.body.should == status.to_diaspora_xml + end + # We want to be using guids from now on for this post route, but do not want to break # preexisiting permalinks. We can assume a guid is 8 characters long as we have # guids set to hex(8) since we started using them. diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index c84890052..f029d5b2d 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -81,7 +81,7 @@ describe Reshare do it 'fetches the root post from root_guid' do response = mock response.stub(:body).and_return(@root_object.to_diaspora_xml) - Faraday.default_connection.should_receive(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid)).and_return(response) + Faraday.default_connection.should_receive(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response) root = Reshare.from_xml(@xml).root @@ -101,7 +101,7 @@ describe Reshare do response = mock response.stub(:body).and_return(@root_object.to_diaspora_xml) - Faraday.default_connection.should_receive(:get).with(@original_author.url + public_post_path(:guid => @root_object.guid)).and_return(response) + Faraday.default_connection.should_receive(:get).with(@original_author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response) Reshare.from_xml(@xml) end