Skip to content
This repository has been archived by the owner on Apr 11, 2019. It is now read-only.

Commit

Permalink
Tolerate empty response bodies better, helps with collectiveidea#28
Browse files Browse the repository at this point in the history
  • Loading branch information
rkbodenner committed Jan 10, 2012
1 parent 439c81d commit d149643
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tinder/campfire.rb
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/tinder/connection.rb
Expand Up @@ -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)
Expand All @@ -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?
Expand Down
12 changes: 12 additions & 0 deletions spec/tinder/campfire_spec.rb
Expand Up @@ -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|
Expand Down

0 comments on commit d149643

Please sign in to comment.