Skip to content
Extraits de code Groupes Projets
publics_controller_spec.rb 3,41 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    require 'spec_helper'
    
    maxwell's avatar
    maxwell a validé
    describe PublicsController do
    
      let(:fixture_path) { File.join(Rails.root, 'spec', 'fixtures')}
    
      before do
        @user = alice
        @person = Factory(:person)
      end
    
    maxwell's avatar
    maxwell a validé
    
    
      describe '#host_meta' do
    
        it 'succeeds', :fixture => :rspec do
    
          get :host_meta
          response.should be_success
          response.body.should =~ /webfinger/
    
          save_fixture(response.body, "host-meta", fixture_path)
    
    maxwell's avatar
    maxwell a validé
      describe '#receive' do
    
        let(:xml) { "<walruses></walruses>" }
    
          post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
    
          response.should be_success
        end
    
        it 'enqueues a receive job' do
    
          Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, xml).once
    
          post :receive, "guid" => @user.person.guid.to_s, "xml" => xml
    
    maxwell's avatar
    maxwell a validé
        end
    
        it 'unescapes the xml before sending it to receive_salmon' do
    
          aspect = @user.aspects.create(:name => 'foo')
    
          post1 = @user.post(:status_message, :text => 'moms', :to => [aspect.id])
    
          xml2 = post1.to_diaspora_xml
    
          user2 = Factory(:user)
    
          salmon_factory = Salmon::SalmonSlap.create(@user, xml2)
    
          enc_xml = salmon_factory.xml_for(user2.person)
    
    
          Resque.should_receive(:enqueue).with(Job::ReceiveSalmon, @user.id, enc_xml).once
    
          post :receive, "guid" => @user.person.guid.to_s, "xml" => CGI::escape(enc_xml)
    
        it 'returns a 422 if no xml is passed' do
    
          post :receive, "guid" => @person.guid.to_s
    
          response.code.should == '422'
    
    maxwell's avatar
    maxwell a validé
    
    
        it 'returns a 404 if no user is found' do
    
          post :receive, "guid" => @person.guid.to_s, "xml" => xml
    
          response.should be_not_found
        end
    
        it 'returns a 404 if no person is found' do
          post :receive, :guid => '2398rq3948yftn', :xml => xml
          response.should be_not_found
        end
    
        it "succeeds", :fixture => :rspec do
    
          post :hcard, "guid" => @user.person.guid.to_s
    
          response.should be_success
    
          save_fixture(response.body, "hcard", fixture_path)
    
        end
    
        it 'sets the person' do
    
          post :hcard, "guid" => @user.person.guid.to_s
    
          assigns[:person].should == @user.person
    
          post :hcard, "guid" => 90348257609247856.to_s
    
          response.should be_not_found
    
    maxwell's avatar
    maxwell a validé
      describe '#webfinger' do
    
        it "succeeds when the person and user exist locally", :fixture => :rspec do
    
          post :webfinger, 'q' => @user.person.diaspora_handle
    
          save_fixture(response.body, "webfinger", fixture_path)
    
        end
    
        it "404s when the person exists remotely because it is local only" do
          stub_success('me@mydiaspora.pod.com')
          post :webfinger, 'q' => 'me@mydiaspora.pod.com'
          response.should be_not_found
        end
    
        it "404s when the person is local but doesn't have an owner" do
    
          post :webfinger, 'q' => @person.diaspora_handle
    
          response.should be_not_found
        end
    
        it "404s when the person does not exist locally or remotely" do
          stub_failure('me@mydiaspora.pod.com')
          post :webfinger, 'q' => 'me@mydiaspora.pod.com'
          response.should be_not_found
    
    maxwell's avatar
    maxwell a validé
    
      describe '#hub' do
        it 'succeeds' do
          get :hub
          response.should be_success
        end
      end