lita 4.4.2 → 4.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a7e995f4c250faf7cb4ccb24fe606d338c26073
4
- data.tar.gz: df5d314c0cc71b6c99810df59453f47c12c82227
3
+ metadata.gz: 60f8a5c4baff97cb21c6bda0e37416b919747443
4
+ data.tar.gz: 2ecdd16eb4c246c566178a31f4cfc277e0794282
5
5
  SHA512:
6
- metadata.gz: df5cd5d29b7f262896e4c295eea4b9207020b389d8942f62992c950076dfd96b03e1bd0ae8a86522a7e5d4d0615eaf32a4d0cd98b4c4e63a8f8dda85f0576b8d
7
- data.tar.gz: 68618e0d9c07a25439a15da5f2a8cf4ec00bc58698bf58cd708da1efc3e5023e1dd559b2f9c69b7cd2ae89736422601fa42572b4e6b68afc7772dd60255b4a12
6
+ metadata.gz: 1f9d6e452648e187da436d3b9fbb248ff90243abc47ac671340df664f42b4c12c7d7fb832f169583cb485dd4adb44b554a79f4751f6ba011b6be6ed22fdc35d0
7
+ data.tar.gz: 55d2096400b2dca088b16b40f07ae0888ed30ec98ad9dc6e873c5a2b7a23132b7b16c8649a3b61c49a1a0a6c9009c830bc0e7b5ce6f7c589aeef37c0b105eb57
@@ -82,7 +82,7 @@ module Lita
82
82
  # @!method roster(room)
83
83
  # Get a list of users that are online in the given room.
84
84
  # @param room [Lita::Room] The room to return a roster for.
85
- # @return [Array<Lita::Roster>] An array of users.
85
+ # @return [Array<Lita::User>] An array of users.
86
86
  # @abstract This should be implemented by the adapter.
87
87
  # @since 4.4.0
88
88
 
@@ -80,21 +80,40 @@ module Lita
80
80
  end
81
81
 
82
82
  # Makes the robot join a room with the specified ID.
83
- # @param room_id [String] The ID of the room.
83
+ # @param room [Room, String] The room to join, as a {Lita::Room} object or a string identifier.
84
84
  # @return [void]
85
85
  # @since 3.0.0
86
- def join(room_id)
87
- Lita.redis.sadd("persisted_rooms", room_id)
88
- adapter.join(room_id)
86
+ def join(room)
87
+ room_object = find_room(room)
88
+
89
+ if room_object
90
+ Lita.redis.sadd("persisted_rooms", room_object.id)
91
+ adapter.join(room_object.id)
92
+ else
93
+ adapter.join(room)
94
+ end
89
95
  end
90
96
 
91
97
  # Makes the robot part from the room with the specified ID.
92
- # @param room_id [String] The ID of the room.
98
+ # @param room [Room, String] The room to leave, as a {Lita::Room} object or a string identifier.
93
99
  # @return [void]
94
100
  # @since 3.0.0
95
- def part(room_id)
96
- Lita.redis.srem("persisted_rooms", room_id)
97
- adapter.part(room_id)
101
+ def part(room)
102
+ room_object = find_room(room)
103
+
104
+ if room_object
105
+ Lita.redis.srem("persisted_rooms", room_object.id)
106
+ adapter.part(room_object.id)
107
+ else
108
+ adapter.part(room)
109
+ end
110
+ end
111
+
112
+ # A list of room IDs the robot should join on boot.
113
+ # @return [Array<String>] An array of room IDs.
114
+ # @since 4.4.2
115
+ def persisted_rooms
116
+ Lita.redis.smembers("persisted_rooms").sort
98
117
  end
99
118
 
100
119
  # Sends one or more messages to a user or room.
@@ -162,11 +181,6 @@ module Lita
162
181
  end
163
182
  end
164
183
 
165
- # A list of room IDs the robot should join.
166
- def persisted_rooms
167
- Lita.redis.smembers("persisted_rooms").sort
168
- end
169
-
170
184
  private
171
185
 
172
186
  # Loads and caches the adapter on first access.
@@ -174,6 +188,16 @@ module Lita
174
188
  @adapter ||= load_adapter
175
189
  end
176
190
 
191
+ # Ensure the argument is a Lita::Room.
192
+ def find_room(room_or_identifier)
193
+ case room_or_identifier
194
+ when Room
195
+ room_or_identifier
196
+ else
197
+ Room.fuzzy_find(room_or_identifier)
198
+ end
199
+ end
200
+
177
201
  # Loads the selected adapter.
178
202
  def load_adapter
179
203
  adapter_name = config.robot.adapter
@@ -1,4 +1,4 @@
1
1
  module Lita
2
2
  # The current version of Lita.
3
- VERSION = "4.4.2"
3
+ VERSION = "4.4.3"
4
4
  end
@@ -128,15 +128,34 @@ describe Lita::Robot, lita: true do
128
128
  allow_any_instance_of(Lita::Adapters::Shell).to receive(:join)
129
129
  end
130
130
 
131
- it "delegates to the adapter" do
132
- expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("#lita.io")
133
- subject.join("#lita.io")
131
+ context "when a Room object exists" do
132
+ let!(:room) { Lita::Room.create_or_update(1, name: "#lita.io") }
133
+
134
+ it "passes the room ID to the adapter when a string argument is provided" do
135
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("1")
136
+
137
+ subject.join("#lita.io")
138
+ end
139
+
140
+ it "passes the room ID to the adapter when a Room argument is provided" do
141
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("1")
142
+
143
+ subject.join(room)
144
+ end
145
+
146
+ it "adds the room ID to the persisted list" do
147
+ subject.join("#lita.io")
148
+
149
+ expect(subject.persisted_rooms).to include("1")
150
+ end
134
151
  end
135
152
 
136
- it "adds the room ID to the persisted list" do
137
- subject.join("#lita.io")
153
+ context "when no Room object exists" do
154
+ it "delegates to the adapter with the raw argument" do
155
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:join).with("#lita.io")
138
156
 
139
- expect(Lita.redis.smembers("persisted_rooms")).to include("#lita.io")
157
+ subject.join("#lita.io")
158
+ end
140
159
  end
141
160
  end
142
161
 
@@ -146,17 +165,36 @@ describe Lita::Robot, lita: true do
146
165
  allow_any_instance_of(Lita::Adapters::Shell).to receive(:part)
147
166
  end
148
167
 
149
- it "delegates to the adapter" do
150
- expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("#lita.io")
151
- subject.part("#lita.io")
152
- end
168
+ context "when a Room object exists" do
169
+ let!(:room) { Lita::Room.create_or_update(1, name: "#lita.io") }
170
+
171
+ it "passes the room ID to the adapter when a string argument is provided" do
172
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("1")
173
+
174
+ subject.part("#lita.io")
175
+ end
176
+
177
+ it "passes the room ID to the adapter when a Room argument is provided" do
178
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("1")
179
+
180
+ subject.part(room)
181
+ end
182
+
183
+ it "removes the room ID from the persisted list" do
184
+ subject.join("#lita.io")
185
+
186
+ subject.part("#lita.io")
153
187
 
154
- it "removes the room ID from the persisted list" do
155
- subject.join("#lita.io")
188
+ expect(subject.persisted_rooms).not_to include("1")
189
+ end
190
+ end
156
191
 
157
- subject.part("#lita.io")
192
+ context "when no Room object exists" do
193
+ it "delegates to the adapter with the raw argument" do
194
+ expect_any_instance_of(Lita::Adapters::Shell).to receive(:part).with("#lita.io")
158
195
 
159
- expect(Lita.redis.smembers("persisted_rooms")).not_to include("#lita.io")
196
+ subject.part("#lita.io")
197
+ end
160
198
  end
161
199
  end
162
200
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.2
4
+ version: 4.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Cuadra