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

Defer creating all users on connection. #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/lita/adapters/slack/rtm_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions spec/lita/adapters/slack/rtm_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down