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

Commit

Permalink
Pass a SlackUser to UserCreator.create_user on user/bot updates. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Dec 12, 2014
1 parent 1606410 commit 8d6c33d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/lita/adapters/slack/message_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def from_self?(user)

def handle_bot_change
log.debug("Updating user data for bot.")
UserCreator.create_user(data["bot"], robot, robot_id)
UserCreator.create_user(SlackUser.from_data(data["bot"]), robot, robot_id)
end

def handle_error
Expand Down Expand Up @@ -91,7 +91,7 @@ def handle_unknown

def handle_user_change
log.debug("Updating user data.")
UserCreator.create_user(data["user"], robot, robot_id)
UserCreator.create_user(SlackUser.from_data(data["user"]), robot, robot_id)
end

def log
Expand Down
20 changes: 14 additions & 6 deletions spec/lita/adapters/slack/message_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,23 @@
end

context "with a team join message" do
# let(:bobby) { Lita::Adapters::Slack::SlackUser.new('U023BECGF', 'bobby', real_name) }
let(:data) do
{
"type" => "team_join",
"user" => "some user data"
"user" => {
"id" => "U023BECGF",
"name" => "bobby",
"real_name" => "Bobby Tables"
}
}
end

it "creates the new user" do
expect(
Lita::Adapters::Slack::UserCreator
).to receive(:create_user) do |user_data, robot, robot_id|
expect(user_data).to eq("some user data")
).to receive(:create_user) do |slack_user, robot, robot_id|
expect(slack_user.name).to eq("bobby")
end

subject.handle
Expand All @@ -128,15 +133,18 @@
let(:data) do
{
"type" => "bot_added",
"bot" => "some user data"
"bot" => {
"id" => "U01234567",
"name" => "foobot"
}
}
end

it "creates a new user for the bot" do
expect(
Lita::Adapters::Slack::UserCreator
).to receive(:create_user) do |user_data, robot, robot_id|
expect(user_data).to eq("some user data")
).to receive(:create_user) do |slack_user, robot, robot_id|
expect(slack_user.name).to eq("foobot")
end

subject.handle
Expand Down

0 comments on commit 8d6c33d

Please sign in to comment.