Permalink
Browse files

Tolerate empty response bodies better, helps with #28

  • Loading branch information...
1 parent 439c81d commit d149643cca16ccb4c9f1b9c45a2e0460cf16ba2c @rkbodenner rkbodenner committed Jan 10, 2012
Showing with 16 additions and 4 deletions.
  1. +1 −1 lib/tinder/campfire.rb
  2. +3 −3 lib/tinder/connection.rb
  3. +12 −0 spec/tinder/campfire_spec.rb
@@ -31,7 +31,7 @@ def initialize(subdomain, options = {})
# Get an array of all the available rooms
# TODO: detect rooms that are full (no link)
def rooms
- connection.get('/rooms.json')['rooms'].map do |room|
+ (connection.get('/rooms.json')['rooms'] || []).map do |room|
Room.new(connection, room)
end
end
@@ -74,12 +74,12 @@ def token
def get(url, *args)
response = connection.get(url, *args)
- response.body
+ response.body || {}
end
def post(url, body = nil, *args)
response = connection.post(url, body, *args)
- response.body
+ response.body || {}
end
def raw_post(url, body = nil, *args)
@@ -88,7 +88,7 @@ def raw_post(url, body = nil, *args)
def put(url, body = nil, *args)
response = connection.put(url, body, *args)
- response.body
+ response.body || {}
end
# Is the connection to campfire using ssl?
@@ -25,6 +25,18 @@
end
end
+ describe "rooms when unauthorized" do
+ before do
+ stub_connection(@campfire.connection) do |stub|
+ stub.get('/rooms.json') {[403, {}, '']}
+ end
+ end
+
+ it "should return an empty list" do
+ @campfire.rooms.size.should be == 0
+ end
+ end
+
describe "find_by_id" do
before do
stub_connection(@campfire.connection) do |stub|

0 comments on commit d149643

Please sign in to comment.