From 681ace2827ee5eb5d787cd371a7fad6ce1a6daaa Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Wed, 17 Jun 2015 18:26:43 -0400 Subject: [PATCH 1/4] get the room object from the response Currently you can retrieve the user object from a response in your handler with ``` user = response.user ``` This is how you retrieve a room object before/after this commit ``` room = response.message.source.room_object room = response.room_object ``` This better demonstrates the symmetry between a user object and a room object. --- lib/lita/message.rb | 6 ++++++ lib/lita/response.rb | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/lita/message.rb b/lib/lita/message.rb index 035a591e..e0a3669a 100644 --- a/lib/lita/message.rb +++ b/lib/lita/message.rb @@ -17,6 +17,12 @@ class Message # @see Lita::Source#user def_delegators :source, :user + # @!method room_object + # The room where the message was received from. + # @return [Lita::Room] The room. + # @see Lita::Source#room_object + def_delegators :source, :room_object + # @param robot [Lita::Robot] The currently running robot. # @param body [String] The body of the message. # @param source [Lita::Source] The source of the message. diff --git a/lib/lita/response.rb b/lib/lita/response.rb index c571c8d6..183f2588 100644 --- a/lib/lita/response.rb +++ b/lib/lita/response.rb @@ -27,8 +27,10 @@ class Response # @see Lita::Message#reply_with_mention # @!method user # @see Lita::Message#user + # @!method room_object + # @see Lita::Message#room_object def_delegators :message, :args, :reply, :reply_privately, - :reply_with_mention, :user, :command? + :reply_with_mention, :user, :room_object, :command? # @param message [Lita::Message] The incoming message. # @param pattern [Regexp] The pattern the incoming message matched. From c82b54746e09f05e8dc6a631a4bbe4d78d5fe052 Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Fri, 19 Jun 2015 09:52:21 -0400 Subject: [PATCH 2/4] added tests for response.room --- spec/lita/message_spec.rb | 7 +++++++ spec/lita/response_spec.rb | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/spec/lita/message_spec.rb b/spec/lita/message_spec.rb index 344335a0..0935016d 100644 --- a/spec/lita/message_spec.rb +++ b/spec/lita/message_spec.rb @@ -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") diff --git a/spec/lita/response_spec.rb b/spec/lita/response_spec.rb index 7964bcd7..9a5ab297 100644 --- a/spec/lita/response_spec.rb +++ b/spec/lita/response_spec.rb @@ -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 From a60753cf34ba83c7dc52da73cfa98cc94f30e87c Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Fri, 19 Jun 2015 09:53:16 -0400 Subject: [PATCH 3/4] Response object has #room method and not #room_object --- lib/lita/response.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/lita/response.rb b/lib/lita/response.rb index 183f2588..1cee3ca1 100644 --- a/lib/lita/response.rb +++ b/lib/lita/response.rb @@ -27,10 +27,12 @@ class Response # @see Lita::Message#reply_with_mention # @!method user # @see Lita::Message#user - # @!method room_object - # @see Lita::Message#room_object def_delegators :message, :args, :reply, :reply_privately, - :reply_with_mention, :user, :room_object, :command? + :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. From 88095ce4ba83444b12820f3c62cd4d92720d04f2 Mon Sep 17 00:00:00 2001 From: Jeremy Nicklas Date: Fri, 19 Jun 2015 10:09:38 -0400 Subject: [PATCH 4/4] cleaned up the delegators in Message a bit --- lib/lita/message.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/lita/message.rb b/lib/lita/message.rb index e0a3669a..ee0bd443 100644 --- a/lib/lita/message.rb +++ b/lib/lita/message.rb @@ -12,16 +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 was received from. - # @return [Lita::Room] The room. - # @see Lita::Source#room_object - def_delegators :source, :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.