Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Broach::Room.find_by_name.

  • Loading branch information...
commit ab479956476d3bc1df5535c45fdd2bbb59fd39fb 1 parent 71fa626
@Manfred authored
Showing with 19 additions and 2 deletions.
  1. +1 −1  lib/broach.rb
  2. +8 −1 lib/broach/room.rb
  3. +10 −0 test/unit/room_test.rb
View
2  lib/broach.rb
@@ -26,7 +26,7 @@
#
# If you want to post multiple lines to one room, it's a good idea to create a Room instance.
#
-# room = Broach.rooms.find { |room| room.name == 'Office' }
+# room = Broach::Room.find_by_name('Office')
# room.speak('Manfred just commited to the `weblog' repository')
# room.speak("commit 4578530113cb87e1e7dbd696c376181e97d429d7\n" +
# "Author: Manfred Stienstra <manfred@fngtps.com>\n" +
View
9 lib/broach/room.rb
@@ -43,9 +43,16 @@ def self.all
end
end
- # Returns a Room instance for a room with a specific ID
+ # Returns a Room instance for a room with a specific ID, raises an exception when it
+ # can't find the room.
def self.find(id)
new(Broach.session.get("room/#{id.to_i}")['room'])
end
+
+ # Returns a Room instance for a room with a specific name, returns nil when it can't find
+ # the room.
+ def self.find_by_name(name)
+ all.find { |room| room.name == name }
+ end
end
end
View
10 test/unit/room_test.rb
@@ -23,6 +23,16 @@ def room(attributes)
room = Broach::Room.find(65667)
room.id.should == 65667
end
+
+ it "should find a room with a certain name" do
+ office_room = mock('Room', :name => 'Office')
+ business_room = mock('Room', :name => 'Business')
+ Broach::Room.stub!(:all).and_return([office_room, business_room])
+
+ Broach::Room.find_by_name('Office').should == office_room
+ Broach::Room.find_by_name('Business').should == business_room
+ Broach::Room.find_by_name('Unknown').should == nil
+ end
end
describe "A Room, concerning messages" do
Please sign in to comment.
Something went wrong with that request. Please try again.