forked from insoshi/insoshi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection_spec.rb
101 lines (82 loc) · 3.01 KB
/
connection_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
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
require File.dirname(__FILE__) + '/../spec_helper'
describe Connection do
before(:each) do
@emails = ActionMailer::Base.deliveries
@emails.clear
@global_prefs = Preference.find(:first)
@person = people(:quentin)
@contact = people(:aaron)
end
describe "class methods" do
it "should create a request" do
Connection.request(@person, @contact)
status(@person, @contact).should == Connection::PENDING
status(@contact, @person).should == Connection::REQUESTED
end
it "should send an email when global/contact notifications are on" do
# Both notifications are on by default.
lambda do
Connection.request(@person, @contact)
end.should change(@emails, :length).by(1)
end
it "should not send an email when contact's notifications are off" do
@contact.toggle!(:connection_notifications)
@contact.connection_notifications.should == false
lambda do
Connection.request(@person, @contact)
end.should_not change(@emails, :length)
end
it "should not send an email when global notifications are off" do
@global_prefs.update_attributes(:email_notifications => false)
lambda do
Connection.request(@person, @contact)
end.should_not change(@emails, :length)
end
describe "connect method" do
it "should not send an email when contact's notifications are off" do
@contact.toggle!(:connection_notifications)
@contact.connection_notifications.should == false
lambda do
Connection.connect(@person, @contact)
end.should_not change(@emails, :length)
end
end
it "should accept a request" do
Connection.request(@person, @contact)
Connection.accept(@person, @contact)
status(@person, @contact).should == Connection::ACCEPTED
status(@contact, @person).should == Connection::ACCEPTED
end
it "should break up a connection" do
Connection.request(@person, @contact)
Connection.breakup(@person, @contact)
Connection.exists?(@person, @contact).should be_false
end
end
describe "instance methods" do
before(:each) do
Connection.request(@person, @contact)
@connection = Connection.conn(@person, @contact)
end
it "should accept a request" do
@connection.accept
end
it "should break up a connection" do
@connection.breakup
Connection.exists?(@person, @contact).should be_false
end
end
it "should create a feed activity for a new connection" do
connection = Connection.connect(@person, @contact)
activity = Activity.find_by_item_id(connection)
activity.should_not be_nil
activity.person.should_not be_nil
end
it "should not create an activity for a connection with the first admin" do
connection = Connection.connect(@person, Person.find_first_admin)
Activity.find_by_item_id(connection).should be_nil
end
def status(person, conn)
Connection.conn(person, conn).status
end
end