forked from insoshi/insoshi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnections_controller_spec.rb
60 lines (49 loc) · 1.59 KB
/
connections_controller_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
require File.dirname(__FILE__) + '/../spec_helper'
describe ConnectionsController do
integrate_views
before(:each) do
@person = login_as(:quentin)
@contact = people(:aaron)
end
it "should protect the create page" do
logout
post :create
response.should redirect_to(login_url)
end
it "should create a new connection request" do
Connection.should_receive(:request).with(@person, @contact).
and_return(true)
post :create, :person_id => @contact
response.should redirect_to(home_url)
end
describe "with existing connection" do
integrate_views
before(:each) do
Connection.request(@person, @contact)
@connection = Connection.conn(@person, @contact)
end
it "should get the edit page" do
get :edit, :id => @connection
response.should be_success
end
it "should require the right current person" do
login_as :aaron
get :edit, :id => @connection
response.should redirect_to(home_url)
end
it "should accept the connection" do
put :update, :id => @connection, :commit => "Accept"
Connection.find(@connection).status.should == Connection::ACCEPTED
response.should redirect_to(home_url)
end
it "should decline the connection" do
put :update, :id => @connection, :commit => "Decline"
@connection.should_not exist_in_database
response.should redirect_to(home_url)
end
it "should end a connection" do
delete :destroy, :id => @connection
response.should redirect_to(person_connections_url(@person))
end
end
end