Skip to content
This repository
Newer
Older
100644 109 lines (89 sloc) 2.514 kb
97515034 » bartzon
2011-05-04 More site fluff
1 require 'spec_helper'
2
3 describe Host do
8a2f1aca » bartzon
2011-05-09 Disabling all outgoing http connections
4 before(:each) do
5 Transcoder.stub!(:host_status).and_return {}
6 end
7
d3a62cb5 » bartzon
2011-05-09 Added hosts
8 describe "creating via the api" do
9 def create_host
10 Host.from_api('name' => 'name', 'url' => 'url')
11 end
12
13 it "should map the parameters" do
14 create_host
15 host = Host.last
16 host.name.should == 'name'
17 host.url.should == 'url'
18 end
19
20 it "should update the status" do
21 host = mock("Host", :save => true)
22 Host.stub!(:new).and_return host
23 host.should_receive(:update_status)
24 create_host
25 end
26
27 it "should return the host" do
28 create_host.should == Host.last
29 end
30 end
31
653a64db » bartzon
2011-05-04 Added more specs
32 describe "returning hosts with available slots" do
33 before(:each) do
34 @up = double(Host, :update_status => true, :available_slots => 1)
35 @down = double(Host, :update_status => true, :available_slots => 0)
36 Host.stub!(:all).and_return [@up, @down]
37 end
38
39 def do_get
40 Host.with_available_slots
41 end
42
43 it "should update the statuses" do
44 @up.should_receive(:update_status)
45 @down.should_receive(:update_status)
46 do_get
47 end
48
49 it "should return the hosts with available slots" do
50 do_get.should == [@up]
51 end
52 end
53
54 describe "updating a host's status" do
55 before(:each) do
ad11d6b9 » bartzon
2011-05-05 Rewrote object generating using FactoryGirl
56 @host = Factory(:host)
653a64db » bartzon
2011-05-04 Added more specs
57 end
58
59 def update
60 @host.update_status
61 end
62
63 describe "up" do
64 before(:each) do
32b26a62 » bartzon
2011-05-05 Added more specs
65 Transcoder.stub!(:host_status).and_return({'max_slots' => 2, 'free_slots' => 1})
653a64db » bartzon
2011-05-04 Added more specs
66 end
67
68 it "should be available" do
69 update
70 @host.should be_available
71 end
72
73 it "should have 2 max slots" do
74 update
75 @host.total_slots.should == 2
76 end
77
78 it "should have 1 free slots" do
79 update
80 @host.available_slots.should == 1
81 end
a94b1ef5 » bartzon
2011-05-05 Better returning from update_status
82
83 it "should return self" do
84 update.should == @host
85 end
653a64db » bartzon
2011-05-04 Added more specs
86 end
87
88 describe "down" do
89 before(:each) do
32b26a62 » bartzon
2011-05-05 Added more specs
90 Transcoder.stub!(:host_status).and_return false
653a64db » bartzon
2011-05-04 Added more specs
91 end
92
93 it "should not be available" do
94 update
95 @host.should_not be_available
96 end
a94b1ef5 » bartzon
2011-05-05 Better returning from update_status
97
98 it "should return self" do
99 update.should == @host
100 end
653a64db » bartzon
2011-05-04 Added more specs
101 end
b73b5893 » bartzon
2011-06-07 A host should update its status once every 10 seconds
102
103 it "should not update its status if the last update was < 10 seconds ago" do
104 host = Factory(:host, :updated_at => 5.seconds.ago)
105 host.should_not_receive(:save)
106 host.update_status
107 end
653a64db » bartzon
2011-05-04 Added more specs
108 end
97515034 » bartzon
2011-05-04 More site fluff
109 end
Something went wrong with that request. Please try again.