diff --git a/.travis.yml b/.travis.yml index 2fa1a3f..0633b96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: ruby rvm: - 2.0.0 + - 2.1.5 + - 2.2.1 script: bundle exec rake before_install: - gem update --system diff --git a/lib/lita/adapters/slack/rtm_connection.rb b/lib/lita/adapters/slack/rtm_connection.rb index 4f6fc68..661dde0 100644 --- a/lib/lita/adapters/slack/rtm_connection.rb +++ b/lib/lita/adapters/slack/rtm_connection.rb @@ -25,8 +25,7 @@ def initialize(robot, config, team_data) @im_mapping = IMMapping.new(API.new(config), team_data.ims) @websocket_url = team_data.websocket_url @robot_id = team_data.self.id - - UserCreator.create_users(team_data.users, robot, robot_id) + @slack_users = team_data.users end def im_for(user_id) @@ -50,6 +49,10 @@ def run(queue = nil, options = {}) end websocket.on(:error) { |event| log.debug("WebSocket error: #{event.message}") } + EventLoop.defer do + UserCreator.create_users(slack_users, robot, robot_id) + end + queue << websocket if queue end end @@ -77,6 +80,7 @@ def shut_down attr_reader :robot_id attr_reader :websocket attr_reader :websocket_url + attr_reader :slack_users def log Lita.logger diff --git a/spec/lita/adapters/slack/rtm_connection_spec.rb b/spec/lita/adapters/slack/rtm_connection_spec.rb index 37b909e..ba6fb44 100644 --- a/spec/lita/adapters/slack/rtm_connection_spec.rb +++ b/spec/lita/adapters/slack/rtm_connection_spec.rb @@ -41,12 +41,6 @@ def with_websocket(subject, queue) it "constructs a new RTMConnection with the results of rtm.start data" do expect(described_class.build(robot, config)).to be_an_instance_of(described_class) end - - it "creates users with the results of rtm.start data" do - expect(Lita::Adapters::Slack::UserCreator).to receive(:create_users) - - described_class.build(robot, config) - end end describe "#im_for" do @@ -89,6 +83,13 @@ def with_websocket(subject, queue) end end + it "creates users with the results of rtm.start data" do + allow(Lita::Adapters::Slack::EventLoop).to receive(:defer).and_yield + expect(Lita::Adapters::Slack::UserCreator).to receive(:create_users) + + subject.run(queue, ping: nil) + end + it "dispatches incoming data to MessageHandler" do allow(Lita::Adapters::Slack::EventLoop).to receive(:defer).and_yield allow(Lita::Adapters::Slack::MessageHandler).to receive(:new).with(