Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #122 from nickjer/get-room-from-response
Browse files Browse the repository at this point in the history
get the room object from the response
  • Loading branch information
jimmycuadra committed Jun 26, 2015
2 parents 2b1ef35 + 88095ce commit 742521f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/lita/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ class Message
attr_reader :source

# @!method user
# The user who sent the message.
# @return [Lita::User] The user.
# @see Lita::Source#user
def_delegators :source, :user
# The user who sent the message.
# @return [Lita::User] The user.
# @see Lita::Source#user
# @!method room_object
# The room where the message came from.
# @return [Lita::Room] The room.
# @see Lita::Source#room_object
def_delegators :source, :user, :room_object

# @param robot [Lita::Robot] The currently running robot.
# @param body [String] The body of the message.
Expand Down
4 changes: 4 additions & 0 deletions lib/lita/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class Response
def_delegators :message, :args, :reply, :reply_privately,
:reply_with_mention, :user, :command?

# @!method room
# @see Lita::Message#room_object
def_delegator :message, :room_object, :room

# @param message [Lita::Message] The incoming message.
# @param pattern [Regexp] The pattern the incoming message matched.
def initialize(message, pattern)
Expand Down
7 changes: 7 additions & 0 deletions spec/lita/message_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
end
end

describe "#room_object" do
it "delegates to #source" do
expect(subject.source).to receive(:room_object)
subject.room_object
end
end

describe "#reply" do
it "sends strings back to the source through the robot" do
expect(robot).to receive(:send_messages).with(source, "foo", "bar")
Expand Down
14 changes: 14 additions & 0 deletions spec/lita/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,18 @@
expect(subject.extensions[:foo]).to eq(:bar)
end
end

describe "#user" do
it "delegates to #message" do
expect(subject.message).to receive(:user)
subject.user
end
end

describe "#room" do
it "delegates to #message" do
expect(subject.message).to receive(:room_object)
subject.room
end
end
end

0 comments on commit 742521f

Please sign in to comment.