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: 04a443520afad94fe91131295d3552969544f983 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#   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) { Factory.create :user }
  let!(:user2) { Factory.create :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
      response.code.should == '200'
    end

    it 'does not query by user id' do
      post :hcard, :id => user.id
      assigns[:person].should be_nil
      response.code.should == '404'
    end
  end

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

  context 'intergration tests that should not be in this file' do
    describe 'friend requests' do
      before do
        deliverable = Object.new
        deliverable.stub!(:deliver)
        Notifier.stub!(:new_request).and_return(deliverable)
        req.delete
        user2.reload
        user2.pending_requests.count.should be 1
      end


      it 'should accept a post from another node and save the information' do
        pending
        message = user2.build_post(:status_message, :message => "hi")

        friend_users(user, aspect1, user2, aspect2)

        user.reload
        user.visible_post_ids.include?(message.id).should be false

        xml1 = user2.salmon(message).xml_for(user.person)

        EM::run{
          post :receive, :id => user.person.id, :xml => xml1
          EM.stop
        }
        user.reload
        user.visible_post_ids.include?(message.id).should be true
      end
    end
  end
end