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

posting_spec.rb « user « models « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5bafbb1b0c0793be317b0d489aa66413198972ff (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
#   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 User do
  before do
    @aspect = alice.aspects.first
    @aspect1 = alice.aspects.create(:name => 'other')
  end

  describe '#add_to_streams' do
    before do
      @params = {:text => "hey", :to => [@aspect.id, @aspect1.id]}
      @post = alice.build_post(:status_message, @params)
      @post.save
      @aspect_ids = @params[:to]
      @aspects = alice.aspects_from_ids(@aspect_ids)
    end

    it 'saves post into visible post ids' do
      lambda {
        alice.add_to_streams(@post, @aspects)
      }.should change{alice.raw_visible_posts(:by_members_of => @aspects).length}.by(1)
      alice.raw_visible_posts(:by_members_of => @aspects).should include @post
    end

    it 'saves post into each aspect in aspect_ids' do
      alice.add_to_streams(@post, @aspects)
      @aspect.reload.post_ids.should include @post.id
      @aspect1.reload.post_ids.should include @post.id
    end

    it 'sockets the post to the poster' do
      @post.should_receive(:socket_to_user).with(alice, anything)
      alice.add_to_streams(@post, @aspects)
    end
  end

  describe '#aspects_from_ids' do
    it 'returns a list of all valid aspects a alice can post to' do
      aspect_ids = Aspect.all.map(&:id)
      alice.aspects_from_ids(aspect_ids).to_set.should == alice.aspects.to_set
    end
    it "lets you post to your own aspects" do
      alice.aspects_from_ids([@aspect.id]).should == [@aspect]
      alice.aspects_from_ids([@aspect1.id]).should == [@aspect1]
    end
    it 'removes aspects that are not yours' do
      alice.aspects_from_ids(eve.aspects.first.id).should == []
    end
  end

  describe '#build_post' do
    it 'sets status_message#text' do
      post = alice.build_post(:status_message, :text => "hey", :to => @aspect.id)
      post.text.should == "hey"
    end

    it 'does not save a status_message' do
      post = alice.build_post(:status_message, :text => "hey", :to => @aspect.id)
      post.should_not be_persisted
    end

    it 'does not save a photo' do
      post = alice.build_post(:photo, :user_file => uploaded_photo, :to => @aspect.id)
      post.should_not be_persisted
    end
  end

  describe '#update_post' do
    it 'should update fields' do
      photo = alice.post(:photo, :user_file => uploaded_photo, :text => "Old caption", :to => @aspect.id)
      update_hash = {:text => "New caption"}
      alice.update_post(photo, update_hash)

      photo.text.should match(/New/)
    end
  end
end