Skip to content

Commit

Permalink
Run the markdown link formatter on attachments too
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Lavender committed Sep 28, 2015
1 parent dc20b91 commit 7b93579
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/slack-notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ def initialize webhook_url, options={}

def ping message, options={}
message = LinkFormatter.format(message)
if attachments = options[:attachments] || options["attachments"]
attachments.each do |attachment|
["text", :text].each do |key|
attachment[key] = LinkFormatter.format(attachment[key]) if attachment.has_key?(key)
end
end
end
payload = default_payload.merge(options).merge(text: message)
client = payload.delete(:http_client) || http_client
http_options = payload.delete(:http_options)
Expand Down
16 changes: 16 additions & 0 deletions spec/lib/slack-notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
described_class.new('http://example.com').ping "the message", channel: 'foo'
end

it "passes attachment messages through LinkFormatter" do
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
.with("the message")
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
.with("attachment message")
expect( Slack::Notifier::LinkFormatter ).to receive(:format)
.with("fallback message")

described_class.new('http://example.com').ping "the message", channel: 'foo',
attachments: [{
color: "#000",
text: "attachment message",
fallback: "fallback message"
}]
end

context "with a default channel set" do

before :each do
Expand Down

0 comments on commit 7b93579

Please sign in to comment.