/
invitation_spec.rb
74 lines (61 loc) · 2.32 KB
/
invitation_spec.rb
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
# Copyright (c) 2010-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, :language => "de")
end
it 'is valid' do
@invitation.sender.should == user
@invitation.recipient.should == nil
@invitation.aspect.should == user.aspects.first
@invitation.language.should == "de"
@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
describe '#language' do
it 'returns the correct language if the language is set' do
@invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => "de")
@invitation.language.should == "de"
end
it 'returns en if no language is set' do
@invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first)
@invitation.language.should == "en"
end
end
it 'has a message' do
@invitation = Factory.build(:invitation, :sender => user, :recipient => eve, :aspect => user.aspects.first, :language => user.language)
@invitation.message = "!"
@invitation.message.should == "!"
end
describe '.batch_invite' do
before do
@emails = ['max@foo.com', 'bob@mom.com']
@opts = {:aspect => eve.aspects.first, :sender => eve, :service => 'email', :language => eve.language}
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
end