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
|
# Copyright (c) 2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe Invitation do
let(:user) { alice }
before do
@email = 'maggie@example.com'
Devise.mailer.deliveries = []
end
describe 'validations' do
before do
@invitation = Factory.build(:invitation, :sender => user, :recipient => nil, :aspect => user.aspects.first)
end
it 'is valid' do
@invitation.sender.should == user
@invitation.recipient.should == nil
@invitation.aspect.should == user.aspects.first
@invitation.should be_valid
end
it 'ensures the sender is placing the recipient into one of his aspects' do
@invitation.aspect = Factory(:aspect)
@invitation.should_not be_valid
end
end
it 'has a message' do
@invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first)
@invitation.message = "!"
@invitation.message.should == "!"
end
describe 'the invite process' do
before do
end
it 'works for a new user' do
invite = Invitation.new(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'foo@bar.com')
lambda {
invite.save
invite.send!
}.should change(User, :count).by(1)
end
it 'works for a current user(with the right email)' do
invite = Invitation.create(:sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => bob.email)
lambda {
invite.send!
}.should_not change(User, :count)
end
it 'works for a current user(with the same fb id)' do
bob.services << Factory.build(:service, :type => "Services::Facebook")
invite = Invitation.create(:sender => alice, :aspect => alice.aspects.first, :service => 'facebook', :identifier => bob.services.first.uid)
lambda {
invite.send!
}.should_not change(User, :count)
end
it 'handles the case when that user has an invite but not a user' do
pending
end
it 'handles the case where that user has an invite but has not yet accepted' do
pending
end
it 'generate the invitation token and pass it to the user' do
pending
end
end
describe '.batch_invite' do
before do
@emails = ['max@foo.com', 'bob@mom.com']
@opts = {:aspect => eve.aspects.first, :sender => eve, :service => 'email'}
end
it 'returns an array of invites based on the emails passed in' do
invites = Invitation.batch_invite(@emails, @opts)
invites.count.should be 2
invites.all?{|x| x.persisted?}.should be_true
end
it 'shares with people who are already on the pod' do
Factory(:user, :email => @emails.first)
invites = nil
expect{
invites = Invitation.batch_invite(@emails, @opts)
}.to change(eve.contacts, :count).by(1)
invites.count.should be 2
end
end
describe 'send' do
before do
@invitation = Factory(:invitation, :sender => alice, :aspect => alice.aspects.first, :service => 'email', :identifier => 'a@a.com')
end
it 'sends an email' do
lambda {
@invitation.send!
}.should change(Devise.mailer.deliveries, :count).by(1)
end
it 'sends an email with from header' do
@invitation.send!
Devise.mailer.deliveries.first.from.should_not be_blank
end
it 'sends an email with from header' do
@invitation.send!
Devise.mailer.deliveries.first.to.should == ["a@a.com"]
end
context "re-send" do
it 'sends another email' do
lambda {
@invitation.resend
}.should change(Devise.mailer.deliveries, :count).by(1)
end
end
end
describe '#recipient_identifier' do
it 'calls email if the invitation_service is email' do
email = 'abc@abc.com'
invitation = Factory(:invitation, :sender => alice, :service => 'email', :identifier => email, :aspect => alice.aspects.first)
invitation.recipient_identifier.should == email
end
context 'facebook' do
before do
@uid = '23526464'
@service = "facebook"
alice.services << Services::Facebook.new(:uid => "13234895")
alice.reload.services(true).first.service_users.create(:uid => @uid, :photo_url => 'url', :name => "Remote User")
end
it 'gets the name if the invitation_service is facebook' do
invitation = Factory(:invitation, :sender => alice, :identifier => @uid, :service => @service, :aspect => alice.aspects.first)
invitation.recipient_identifier.should == "Remote User"
end
it 'does not error if the facebook user is not recorded' do
invitation = Factory(:invitation, :sender => alice, :identifier => @uid, :service => @service, :aspect => alice.aspects.first)
alice.services.first.service_users.delete_all
invitation.recipient_identifier.should == "A Facebook user"
end
end
end
end
|