<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require 'spec_helper'


describe PublicsController do
  render_views
  let!(:user) { make_user }
  let!(:user2) { make_user }
  let!(:aspect1) { user.aspect(:name => "foo") }
  let!(:aspect2) { user2.aspect(:name => "far") }
  let!(:aspect2) { user2.aspect(:name => 'disciples') }
  let!(:req) { user2.send_friend_request_to(user.person, aspect2) }
  let!(:xml) { user2.salmon(req).xml_for(user.person) }
  let(:person){Factory(:person)}

  before do
    sign_in :user, user

  end
  
  describe '#receive' do
    before do
      EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success))
    end

    context 'success cases' do
      it 'should 200 on successful receipt of a request' do
        EM::run { 

          person_mock = mock()
          user_mock = mock()
          user_mock.stub!(:receive_salmon).and_return(true)
          user_mock.should_receive(:receive_salmon).and_return(true)
          person_mock.stub!(:owner_id).and_return(true)
          person_mock.stub!(:owner).and_return(user_mock)
          Person.stub!(:first).and_return(person_mock)

          post :receive, :id =>user.person.id, :xml => xml
          response.code.should == '200'
          EM.stop
        }
      end

      it 'should set the user based on their person_id' do

        EM::run {

          person_mock = mock()
          person_mock.stub!(:owner_id).and_return(true)
          person_mock.stub!(:owner).and_return(user)
          Person.stub!(:first).and_return(person_mock)


          post :receive, :id => user.person.id, :xml => xml
          assigns[:user].should == user
          EM.stop
        }
      end

      it 'should have the xml processed as salmon on success' do
        EM::run{

          person_mock = mock()
          user_mock = mock()
          user_mock.stub!(:receive_salmon).and_return(true)
          person_mock.stub!(:owner_id).and_return(true)
          person_mock.stub!(:owner).and_return(user_mock)
          Person.stub!(:first).and_return(person_mock)


          post :receive, :id => user.person.id, :xml => xml
          EM.stop
        }
      end
    end

    it 'should return a 422 if no xml is passed' do
      post :receive, :id => person.id
      response.code.should == '422'
    end

    it 'should return a 404 if no user is found' do
      post :receive, :id => person.id, :xml => xml
      response.code.should == '404'
    end
  end


  describe '#hcard' do
    it 'queries by person id' do
      post :hcard, :id => user.person.id
      assigns[:person].should == user.person<commit_msg>stub out some stuff in publics_controller<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

require 'spec_helper'


describe PublicsController do
  render_views
  let!(:user) { make_user }
  let!(:user2) { make_user }
  let!(:aspect1) { user.aspect(:name => "foo") }
  let!(:aspect2) { user2.aspect(:name => "far") }
  let!(:aspect2) { user2.aspect(:name => 'disciples') }
  let!(:req) { user2.send_friend_request_to(user.person, aspect2) }
  let!(:xml) { user2.salmon(req).xml_for(user.person) }
  let(:person){Factory(:person)}

  before do
    sign_in :user, user

  end
  
  describe '#receive' do
    before do
      EventMachine::HttpRequest.stub!(:new).and_return(FakeHttpRequest.new(:success))
    end

    context 'success cases' do
      before do
        @person_mock = mock()
        @user_mock = mock()
        @user_mock.stub!(:receive_salmon).and_return(true)
        @person_mock.stub!(:owner_id).and_return(true)
        @person_mock.stub!(:owner).and_return(@user_mock)
        Person.stub!(:first).and_return(@person_mock)
      end
      it 'should 200 on successful receipt of a request' do
        post :receive, :id =>user.person.id, :xml => xml
        response.code.should == '200'
      end

      it 'should have the xml processed as salmon on success' do
        @user_mock.should_receive(:receive_salmon).and_return(true)
        post :receive, :id => user.person.id, :xml => xml
      end
    end

    it 'should return a 422 if no xml is passed' do
      post :receive, :id => person.id
      response.code.should == '422'
    end

    it 'should return a 404 if no user is found' do
      post :receive, :id => person.id, :xml => xml
      response.code.should == '404'
    end
  end


  describe '#hcard' do
    it 'queries by person id' do
      post :hcard, :id => user.person.id
      assigns[:person].should == user.person
{'fraction_non_alphanumeric': 0.1283683428813919, 'fraction_numerical': 0.013579461065138977, 'mean_word_length': 2.6856919468334635, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '305', 'n_tokens_mistral': 1605, 'n_tokens_neox': 1529, 'n_words': 379}