Welcome to mirror list, hosted at ThFree Co, Russian Federation.

publics_controller_spec.rb « controllers « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0e4b6d4651729251677299f472492c1feac04f8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#   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
  let(:fixture_path) { File.join(Rails.root, 'spec', 'fixtures')}
  before do
    @user = alice
    @person = Factory(:person)
  end

  describe '#host_meta' do
    it 'succeeds', :fixture => true do
      get :host_meta
      response.should be_success
      response.body.should =~ /webfinger/
      save_fixture(response.body, "host-meta", fixture_path)
    end
  end

  describe '#receive' do
    let(:xml) { "<walruses></walruses>" }

    it 'succeeds' do
      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
    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)
    end

    it 'returns a 422 if no xml is passed' do
      post :receive, "guid" => @person.guid.to_s
      response.code.should == '422'
    end

    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
  end

  describe '#post' do
    it 'shows a public post' do
      status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')

      get :post, :id => status.id
      response.status= 200
    end

    it 'does not show a private post' do
      status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all')
      get :post, :id => status.id
      response.status = 302
    end

    it 'redirects to the proper show page if the user has visibility of the post' do
      status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
      sign_in bob
      get :post, :id => status.id
      response.should be_redirect
    end
  end

  describe '#hcard' do
    it "succeeds", :fixture => true 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
    end

    it 'does not query by user id' do
      post :hcard, "guid" => 90348257609247856.to_s
      assigns[:person].should be_nil
      response.should be_not_found
    end
  end

  describe '#webfinger' do
    it "succeeds when the person and user exist locally", :fixture => true do
      post :webfinger, 'q' => @user.person.diaspora_handle
      response.should be_success
      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
    end
  end

  describe '#hub' do
    it 'succeeds' do
      get :hub
      response.should be_success
    end
  end
end