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

Commit

Permalink
Respect Source#private_message when sending a message. Fixes #16.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmycuadra committed Jan 26, 2015
1 parent 5cd6195 commit 1557430
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/lita/adapters/slack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def shut_down
attr_reader :rtm_connection

def channel_for(target)
if target.room
target.room
else
if target.private_message?
rtm_connection.im_for(target.user.id)
else
target.room
end
end
end
Expand Down
15 changes: 14 additions & 1 deletion spec/lita/adapters/slack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
let(:room_source) { Lita::Source.new(room: 'C024BE91L') }
let(:user) { Lita::User.new('U023BECGF') }
let(:user_source) { Lita::Source.new(user: user) }
let(:private_message_source) do
Lita::Source.new(room: 'C024BE91L', user: user, private_message: true)
end

it "sends messages to rooms" do
expect(rtm_connection).to receive(:send_messages).with(room_source.room, ['foo'])
Expand All @@ -56,7 +59,17 @@

subject.run

subject.send_messages(Lita::Source.new(user: user), ['foo'])
subject.send_messages(user_source, ['foo'])
end

it "sends messages to users when the source is marked as a private message" do
allow(rtm_connection).to receive(:im_for).with(user.id).and_return('D024BFF1M')

expect(rtm_connection).to receive(:send_messages).with('D024BFF1M', ['foo'])

subject.run

subject.send_messages(private_message_source, ['foo'])
end
end

Expand Down

0 comments on commit 1557430

Please sign in to comment.