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

invite_spec.rb « user « models « spec - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8756a485ebeb16ed9a1d15663e1e791214db0d0a (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
#   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
  let(:inviter)  {new_user = eve; new_user.invites = 5; new_user.save; new_user;}
  let(:aspect)   {inviter.aspects.create(:name => "awesome")}
  let(:another_user) {alice}
  let(:wrong_aspect) {another_user.aspects.create(:name => "super")}
  let(:inviter_with_3_invites) { new_user = Factory.create(:user); new_user.invites = 3; new_user.save; new_user;}
  let(:aspect2) {inviter_with_3_invites.aspects.create(:name => "Jersey Girls")}

  before do
    @email = "bob@bob.com"
  end

  context "creating invites" do
    it 'requires your aspect' do
      lambda {
        inviter.invite_user(wrong_aspect.id, "email", "maggie@example.com")
      }.should raise_error ActiveRecord::RecordNotFound
    end
    
    it 'takes a service parameter' do
      @invite_params = {:service => 'email'}
      Invitation.should_receive(:invite).with(hash_including(@invite_params))
      inviter.invite_user(aspect.id, 'email', @email) 
    end

    it 'takes an indentifier parameter' do
      @invite_params = {:identifier => @email}
      Invitation.should_receive(:invite).with(hash_including(@invite_params))
      inviter.invite_user(aspect.id, 'email', @email)
    end

    it 'calls Invitation.invite' do
      Invitation.should_receive(:invite)
      inviter.invite_user(aspect.id, 'email', @email)
    end

    it 'has an invitation' do
      inviter.invite_user(aspect.id, 'email', @email).invitations_to_me.count.should == 1
    end

    it 'creates it with an email' do
      inviter.invite_user(aspect.id, 'email', @email).email.should == @email
    end

    it "throws if you try to add someone you're connected to" do
      connect_users(inviter, aspect, another_user, wrong_aspect)
      proc{
        inviter.invite_user(aspect.id, 'email', another_user.email)
      }.should raise_error ActiveRecord::RecordNotUnique
    end

  end

  context "limit on invites" do

    it 'does not invite people I already invited' do
      inviter_with_3_invites.invite_user(aspect2.id, 'email', "email1@example.com")
      proc{
        inviter_with_3_invites.invite_user(aspect2.id, 'email', "email1@example.com")
      }.should raise_error /You already invited this person/
    end
  end


  describe "#accept_invitation!" do
    let(:invited_user) {@invited_user_pre.accept_invitation!(:invitation_token => "abc",
                              :email    => "a@a.com",
                              :username => "user",
                              :password => "secret",
                              :password_confirmation => "secret",
                              :person => {:profile => {:first_name => "Bob",
                                :last_name  => "Smith"}} )}

    before do
      @invited_user_pre = Invitation.invite(:from => inviter, :service => 'email', :identifier => 'invitee@example.org', :into => aspect).reload
      @person_count = Person.count
    end

    context 'after invitation acceptance' do
      before do
        invited_user.reload
      end
      it 'destroys the invitations' do
        invited_user.invitations_to_me.count.should == 0
      end
      it "should create the person with the passed in params" do
        Person.count.should == @person_count + 1
        invited_user.person.profile.first_name.should == "Bob"
      end

      it 'resolves incoming invitations into contact requests' do
        inviter.contacts.where(:person_id => invited_user.person.id).count.should == 1
      end
    end
  end
end